Java Code Examples for org.telegram.messenger.AndroidUtilities#cancelRunOnUIThread()

The following examples show how to use org.telegram.messenger.AndroidUtilities#cancelRunOnUIThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ActionBarLayout.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b)
{
    super.onLayout(changed, l, t, r, b);

    View rootView = getRootView();
    getWindowVisibleDisplayFrame(rect);
    int usableViewHeight = rootView.getHeight() - (rect.top != 0 ? AndroidUtilities.statusBarHeight : 0) - AndroidUtilities.getViewInset(rootView);
    isKeyboardVisible = usableViewHeight - (rect.bottom - rect.top) > 0;
    if (waitingForKeyboardCloseRunnable != null && !containerView.isKeyboardVisible && !containerViewBack.isKeyboardVisible)
    {
        AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
        waitingForKeyboardCloseRunnable.run();
        waitingForKeyboardCloseRunnable = null;
    }
}
 
Example 2
Source File: RecyclerListView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void cancelClickRunnables(boolean uncheck)
{
    if (selectChildRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(selectChildRunnable);
        selectChildRunnable = null;
    }
    if (currentChildView != null)
    {
        View child = currentChildView;
        if (uncheck)
        {
            onChildPressed(currentChildView, false);
        }
        currentChildView = null;
        removeSelection(child, null);
    }
    if (clickRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(clickRunnable);
        clickRunnable = null;
    }
    interceptedByChild = false;
}
 
Example 3
Source File: PeopleNearbyActivity.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onFragmentDestroy() {
    super.onFragmentDestroy();
    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.newLocationAvailable);
    getNotificationCenter().removeObserver(this, NotificationCenter.newPeopleNearbyAvailable);
    getNotificationCenter().removeObserver(this, NotificationCenter.needDeleteDialog);
    if (shortPollRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(shortPollRunnable);
        shortPollRunnable = null;
    }
    if (checkExpiredRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(checkExpiredRunnable);
        checkExpiredRunnable = null;
    }
    if (showProgressRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(showProgressRunnable);
        showProgressRunnable = null;
    }
    if (undoView != null) {
        undoView.hide(true, 0);
    }
}
 
Example 4
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void search(String text) {
    if (reqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
        reqId = 0;
    }
    if (reqId2 != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId2, true);
        reqId2 = 0;
    }
    if (TextUtils.isEmpty(text)) {
        searchQuery = null;
        localPacks.clear();
        emojiStickers.clear();
        serverPacks.clear();
        if (stickersGridView.getAdapter() != stickersGridAdapter) {
            stickersGridView.setAdapter(stickersGridAdapter);
        }
        notifyDataSetChanged();
    } else {
        searchQuery = text.toLowerCase();
    }
    AndroidUtilities.cancelRunOnUIThread(searchRunnable);
    AndroidUtilities.runOnUIThread(searchRunnable, 300);
}
 
Example 5
Source File: StickerMasksAlert.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public void search(String text) {
    if (reqId2 != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId2, true);
        reqId2 = 0;
    }
    if (TextUtils.isEmpty(text)) {
        searchQuery = null;
        localPacks.clear();
        emojiStickers.clear();
        if (gridView.getAdapter() != stickersGridAdapter) {
            gridView.setAdapter(stickersGridAdapter);
        }
        notifyDataSetChanged();
    } else {
        searchQuery = text.toLowerCase();
    }
    AndroidUtilities.cancelRunOnUIThread(searchRunnable);
    AndroidUtilities.runOnUIThread(searchRunnable, 300);
}
 
Example 6
Source File: PasscodeView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
private void checkRetryTextView() {
    long currentTime = SystemClock.elapsedRealtime();
    if (currentTime > SharedConfig.lastUptimeMillis) {
        SharedConfig.passcodeRetryInMs -= (currentTime - SharedConfig.lastUptimeMillis);
        if (SharedConfig.passcodeRetryInMs < 0) {
            SharedConfig.passcodeRetryInMs = 0;
        }
    }
    SharedConfig.lastUptimeMillis = currentTime;
    SharedConfig.saveConfig();
    if (SharedConfig.passcodeRetryInMs > 0) {
        int value = Math.max(1, (int) Math.ceil(SharedConfig.passcodeRetryInMs / 1000.0));
        if (value != lastValue) {
            retryTextView.setText(LocaleController.formatString("TooManyTries", R.string.TooManyTries, LocaleController.formatPluralString("Seconds", value)));
            lastValue = value;
        }
        if (retryTextView.getVisibility() != VISIBLE) {
            retryTextView.setVisibility(VISIBLE);
            passwordFrameLayout.setVisibility(INVISIBLE);
            if (numbersFrameLayout.getVisibility() == VISIBLE) {
                numbersFrameLayout.setVisibility(INVISIBLE);
            }
            AndroidUtilities.hideKeyboard(passwordEditText);
            AndroidUtilities.cancelRunOnUIThread(checkRunnable);
            AndroidUtilities.runOnUIThread(checkRunnable, 100);
        }
    } else {
        AndroidUtilities.cancelRunOnUIThread(checkRunnable);
        if (passwordFrameLayout.getVisibility() != VISIBLE) {
            retryTextView.setVisibility(INVISIBLE);
            passwordFrameLayout.setVisibility(VISIBLE);
            if (SharedConfig.passcodeType == 0) {
                numbersFrameLayout.setVisibility(VISIBLE);
            } else if (SharedConfig.passcodeType == 1) {
                AndroidUtilities.showKeyboard(passwordEditText);
            }
        }
    }
}
 
Example 7
Source File: PeopleNearbyActivity.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (shortPollRunnable != null) {
        sendRequest(true, 0);
        AndroidUtilities.cancelRunOnUIThread(shortPollRunnable);
        AndroidUtilities.runOnUIThread(shortPollRunnable, SHORT_POLL_TIMEOUT);
    }
}
 
Example 8
Source File: WebPlayerView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updatePlayButton() {
    controlsView.checkNeedHide();
    AndroidUtilities.cancelRunOnUIThread(progressRunnable);
    if (!videoPlayer.isPlaying()) {
        if (isCompleted) {
            playButton.setImageResource(isInline ? R.drawable.ic_againinline : R.drawable.ic_again);
        } else {
            playButton.setImageResource(isInline ? R.drawable.ic_playinline : R.drawable.ic_play);
        }
    } else {
        playButton.setImageResource(isInline ? R.drawable.ic_pauseinline : R.drawable.ic_pause);
        AndroidUtilities.runOnUIThread(progressRunnable, 500);
        checkAudioFocus();
    }
}
 
Example 9
Source File: MentionsAdapter.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void showUsersResult(ArrayList<TLRPC.User> newResult, SparseArray<TLRPC.User> newMap, boolean notify) {
    searchResultUsernames = newResult;
    searchResultUsernamesMap = newMap;
    if (cancelDelayRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(cancelDelayRunnable);
        cancelDelayRunnable = null;
    }
    if (notify) {
        notifyDataSetChanged();
        delegate.needChangePanelVisibility(!searchResultUsernames.isEmpty());
    }
}
 
Example 10
Source File: MentionsAdapter.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public void onDestroy()
{
    if (locationProvider != null)
    {
        locationProvider.stop();
    }
    if (contextQueryRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(contextQueryRunnable);
        contextQueryRunnable = null;
    }
    if (contextUsernameReqid != 0)
    {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(contextUsernameReqid, true);
        contextUsernameReqid = 0;
    }
    if (contextQueryReqid != 0)
    {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(contextQueryReqid, true);
        contextQueryReqid = 0;
    }
    foundContextBot = null;
    inlineMediaEnabled = true;
    searchingContextUsername = null;
    searchingContextQuery = null;
    noUserName = false;
}
 
Example 11
Source File: ActionBarLayout.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void onAnimationEndCheck(boolean byCheck)
{
    onCloseAnimationEnd();
    onOpenAnimationEnd();
    if (waitingForKeyboardCloseRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(waitingForKeyboardCloseRunnable);
        waitingForKeyboardCloseRunnable = null;
    }
    if (currentAnimation != null)
    {
        if (byCheck)
        {
            currentAnimation.cancel();
        }
        currentAnimation = null;
    }
    if (animationRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(animationRunnable);
        animationRunnable = null;
    }
    setAlpha(1.0f);
    containerView.setAlpha(1.0f);
    containerView.setScaleX(1.0f);
    containerView.setScaleY(1.0f);
    containerViewBack.setAlpha(1.0f);
    containerViewBack.setScaleX(1.0f);
    containerViewBack.setScaleY(1.0f);
}
 
Example 12
Source File: EditTextEmoji.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void onResume() {
    isPaused = false;
    if (showKeyboardOnResume) {
        showKeyboardOnResume = false;
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
        if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet()) {
            waitingForKeyboardOpen = true;
            AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
            AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
        }
    }
}
 
Example 13
Source File: EditTextEmoji.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public void onResume() {
    isPaused = false;
    if (showKeyboardOnResume) {
        showKeyboardOnResume = false;
        editText.requestFocus();
        AndroidUtilities.showKeyboard(editText);
        if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet()) {
            waitingForKeyboardOpen = true;
            AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
            AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
        }
    }
}
 
Example 14
Source File: PasscodeView.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    if (dotRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(dotRunnable);
        dotRunnable = null;
    }
    if (currentAnimation != null) {
        currentAnimation.cancel();
        currentAnimation = null;
    }

    for (int a = 0; a < 4; a++) {
        if (a < stringBuilder.length()) {
            TextView textView = characterTextViews.get(a);
            textView.setAlpha(0);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));

            textView = dotTextViews.get(a);
            textView.setAlpha(1);
            textView.setScaleX(1);
            textView.setScaleY(1);
            textView.setTranslationY(0);
            textView.setTranslationX(getXForTextView(a));
        } else {
            characterTextViews.get(a).setAlpha(0);
            dotTextViews.get(a).setAlpha(0);
        }
    }
    super.onLayout(changed, left, top, right, bottom);
}
 
Example 15
Source File: AlertDialog.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void dismiss() {
    if (cancelDialog != null) {
        cancelDialog.dismiss();
    }
    try {
        super.dismiss();
    } catch (Throwable ignore) {

    }
    AndroidUtilities.cancelRunOnUIThread(showRunnable);
}
 
Example 16
Source File: PasscodeView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void checkRetryTextView() {
    long currentTime = SystemClock.elapsedRealtime();
    if (currentTime > SharedConfig.lastUptimeMillis) {
        SharedConfig.passcodeRetryInMs -= (currentTime - SharedConfig.lastUptimeMillis);
        if (SharedConfig.passcodeRetryInMs < 0) {
            SharedConfig.passcodeRetryInMs = 0;
        }
    }
    SharedConfig.lastUptimeMillis = currentTime;
    SharedConfig.saveConfig();
    if (SharedConfig.passcodeRetryInMs > 0) {
        int value = Math.max(1, (int) Math.ceil(SharedConfig.passcodeRetryInMs / 1000.0));
        if (value != lastValue) {
            retryTextView.setText(LocaleController.formatString("TooManyTries", R.string.TooManyTries, LocaleController.formatPluralString("Seconds", value)));
            lastValue = value;
        }
        if (retryTextView.getVisibility() != VISIBLE) {
            retryTextView.setVisibility(VISIBLE);
            passwordFrameLayout.setVisibility(INVISIBLE);
            if (numbersFrameLayout.getVisibility() == VISIBLE) {
                numbersFrameLayout.setVisibility(INVISIBLE);
            }
            AndroidUtilities.hideKeyboard(passwordEditText);
            AndroidUtilities.cancelRunOnUIThread(checkRunnable);
            AndroidUtilities.runOnUIThread(checkRunnable, 100);
        }
    } else {
        AndroidUtilities.cancelRunOnUIThread(checkRunnable);
        if (passwordFrameLayout.getVisibility() != VISIBLE) {
            retryTextView.setVisibility(INVISIBLE);
            passwordFrameLayout.setVisibility(VISIBLE);
            if (SharedConfig.passcodeType == 0) {
                numbersFrameLayout.setVisibility(VISIBLE);
            } else if (SharedConfig.passcodeType == 1) {
                AndroidUtilities.showKeyboard(passwordEditText);
            }
        }
    }
}
 
Example 17
Source File: Tooltip.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public void hide() {
    if (showing) {
        if (animator != null) {
            animator.setListener(null);
            animator.cancel();
            animator = null;
        }

        AndroidUtilities.cancelRunOnUIThread(dismissRunnable);
        dismissRunnable.run();
    }
    showing = false;
}
 
Example 18
Source File: AlertDialog.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public void showDelayed(long delay) {
    AndroidUtilities.cancelRunOnUIThread(showRunnable);
    AndroidUtilities.runOnUIThread(showRunnable, delay);
}
 
Example 19
Source File: GroupStickersActivity.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void resolveStickerSet() {
    if (listAdapter == null) {
        return;
    }
    if (reqId != 0) {
        ConnectionsManager.getInstance(currentAccount).cancelRequest(reqId, true);
        reqId = 0;
    }
    if (queryRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(queryRunnable);
        queryRunnable = null;
    }
    selectedStickerSet = null;
    if (usernameTextView.length() <= 0) {
        searching = false;
        searchWas = false;
        if (selectedStickerRow != -1) {
            updateRows();
        }
        return;
    }
    searching = true;
    searchWas = true;
    final String query = usernameTextView.getText().toString();
    TLRPC.TL_messages_stickerSet existingSet = MediaDataController.getInstance(currentAccount).getStickerSetByName(query);
    if (existingSet != null) {
        selectedStickerSet = existingSet;
    }
    if (selectedStickerRow == -1) {
        updateRows();
    } else {
        listAdapter.notifyItemChanged(selectedStickerRow);
    }
    if (existingSet != null) {
        searching = false;
        return;
    }
    AndroidUtilities.runOnUIThread(queryRunnable = () -> {
        if (queryRunnable == null) {
            return;
        }
        TLRPC.TL_messages_getStickerSet req = new TLRPC.TL_messages_getStickerSet();
        req.stickerset = new TLRPC.TL_inputStickerSetShortName();
        req.stickerset.short_name = query;
        reqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
            searching = false;
            if (response instanceof TLRPC.TL_messages_stickerSet) {
                selectedStickerSet = (TLRPC.TL_messages_stickerSet) response;
                if (donePressed) {
                    saveStickerSet();
                } else {
                    if (selectedStickerRow != -1) {
                        listAdapter.notifyItemChanged(selectedStickerRow);
                    } else {
                        updateRows();
                    }
                }
            } else {
                if (selectedStickerRow != -1) {
                    listAdapter.notifyItemChanged(selectedStickerRow);
                }
                if (donePressed) {
                    donePressed = false;
                    showEditDoneProgress(false);
                    if (getParentActivity() != null) {
                        Toast.makeText(getParentActivity(), LocaleController.getString("AddStickersNotFound", R.string.AddStickersNotFound), Toast.LENGTH_SHORT).show();
                    }
                }
            }
            reqId = 0;
        }));
    }, 500);
}
 
Example 20
Source File: ActionBarMenuItem.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public void toggleSubMenu()
{
    if (popupLayout == null)
    {
        return;
    }
    if (showMenuRunnable != null)
    {
        AndroidUtilities.cancelRunOnUIThread(showMenuRunnable);
        showMenuRunnable = null;
    }
    if (popupWindow != null && popupWindow.isShowing())
    {
        popupWindow.dismiss();
        return;
    }
    if (popupWindow == null)
    {
        popupWindow = new ActionBarPopupWindow(popupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
        if (animationEnabled && Build.VERSION.SDK_INT >= 19)
        {
            popupWindow.setAnimationStyle(0);
        }
        else
        {
            popupWindow.setAnimationStyle(R.style.PopupAnimation);
        }
        if (!animationEnabled)
        {
            popupWindow.setAnimationEnabled(animationEnabled);
        }
        popupWindow.setOutsideTouchable(true);
        popupWindow.setClippingEnabled(true);
        if (layoutInScreen)
        {
            try
            {
                if (layoutInScreenMethod == null)
                {
                    layoutInScreenMethod = PopupWindow.class.getDeclaredMethod("setLayoutInScreenEnabled", boolean.class);
                    layoutInScreenMethod.setAccessible(true);
                }
                layoutInScreenMethod.invoke(popupWindow, true);
            }
            catch (Exception e)
            {
                FileLog.e(e);
            }
        }
        popupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
        popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
        popupLayout.measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), MeasureSpec.AT_MOST));
        popupWindow.getContentView().setFocusableInTouchMode(true);
        popupWindow.getContentView().setOnKeyListener((v, keyCode, event) ->
        {
            if (keyCode == KeyEvent.KEYCODE_MENU && event.getRepeatCount() == 0 && event.getAction() == KeyEvent.ACTION_UP && popupWindow != null && popupWindow.isShowing())
            {
                popupWindow.dismiss();
                return true;
            }
            return false;
        });
    }
    processedPopupClick = false;
    popupWindow.setFocusable(true);
    if (popupLayout.getMeasuredWidth() == 0)
    {
        updateOrShowPopup(true, true);
    }
    else
    {
        updateOrShowPopup(true, false);
    }
    popupWindow.startAnimation();
}