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

The following examples show how to use org.telegram.messenger.AndroidUtilities#runOnUIThread() . 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: ChatActivityEnterView.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public void onResume()
{
    isPaused = false;
    if (showKeyboardOnResume)
    {
        showKeyboardOnResume = false;
        if (!searchingStickers)
        {
            messageEditText.requestFocus();
        }
        AndroidUtilities.showKeyboard(messageEditText);
        if (!AndroidUtilities.usingHardwareInput && !keyboardVisible && !AndroidUtilities.isInMultiwindow)
        {
            waitingForKeyboardOpen = true;
            AndroidUtilities.cancelRunOnUIThread(openKeyboardRunnable);
            AndroidUtilities.runOnUIThread(openKeyboardRunnable, 100);
        }
    }
}
 
Example 2
Source File: PipVideoView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void run() {
    if (photoViewer == null) {
        return;
    }
    VideoPlayer videoPlayer = photoViewer.getVideoPlayer();
    if (videoPlayer == null) {
        return;
    }
    setProgress(videoPlayer.getCurrentPosition() / (float) videoPlayer.getDuration());
    if (photoViewer == null) {
        setBufferedProgress(videoPlayer.getBufferedPosition() / (float) videoPlayer.getDuration());
    }

    AndroidUtilities.runOnUIThread(progressRunnable, 1000);
}
 
Example 3
Source File: StickersAdapter.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void searchEmojiByKeyword() {
    String[] newLanguage = AndroidUtilities.getCurrentKeyboardLanguage();
    if (!Arrays.equals(newLanguage, lastSearchKeyboardLanguage)) {
        MediaDataController.getInstance(currentAccount).fetchNewEmojiKeywords(newLanguage);
    }
    lastSearchKeyboardLanguage = newLanguage;
    String query = lastSticker;
    cancelEmojiSearch();
    searchRunnable = () -> MediaDataController.getInstance(currentAccount).getEmojiSuggestions(lastSearchKeyboardLanguage, query, true, (param, alias) -> {
        if (query.equals(lastSticker)) {
            if (!param.isEmpty()) {
                keywordResults = param;
            }
            notifyDataSetChanged();
            delegate.needChangePanelVisibility(visible = !param.isEmpty());
        }
    });
    if (keywordResults == null || keywordResults.isEmpty()) {
        AndroidUtilities.runOnUIThread(searchRunnable, 1000);
    } else {
        searchRunnable.run();
    }
}
 
Example 4
Source File: ChangeChatNameActivity.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void onTransitionAnimationEnd(boolean isOpen, boolean backward)
{
    if (isOpen)
    {
        AndroidUtilities.runOnUIThread(new Runnable()
        {
            @Override
            public void run()
            {
                if (nameTextView != null)
                {
                    nameTextView.requestFocus();
                    AndroidUtilities.showKeyboard(nameTextView);
                }
            }
        }, 100);
    }
}
 
Example 5
Source File: ChannelUsersActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void updateSearchResults(final ArrayList<TLRPC.User> users, final ArrayList<CharSequence> names) {
    AndroidUtilities.runOnUIThread(() -> {
        searchResult = users;
        searchResultNames = names;
        notifyDataSetChanged();
    });
}
 
Example 6
Source File: WebviewActivity.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
    if (currentMessageObject == null || getParentActivity() == null || typingRunnable == null) {
        return;
    }
    MessagesController.getInstance(currentAccount).sendTyping(currentMessageObject.getDialogId(), 6, 0);
    AndroidUtilities.runOnUIThread(typingRunnable, 25000);
}
 
Example 7
Source File: WebPlayerView.java    From Telegram 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 8
Source File: EmojiView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private void postBackspaceRunnable(final int time) {
    AndroidUtilities.runOnUIThread(new Runnable() {
        @Override
        public void run() {
            if (!backspacePressed) {
                return;
            }
            if (listener != null && listener.onBackspace()) {
                backspaceButton.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP);
            }
            backspaceOnce = true;
            postBackspaceRunnable(Math.max(50, time - 100));
        }
    }, time);
}
 
Example 9
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 10
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 11
Source File: CameraScanActivity.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
private void onNoQrFound() {
    AndroidUtilities.runOnUIThread(() -> {
        if (recognizedMrzView.getTag() != null) {
            recognizedMrzView.setTag(null);
            recognizedMrzView.animate().setDuration(200).alpha(0.0f).setInterpolator(CubicBezierInterpolator.DEFAULT).start();
        }
    });
}
 
Example 12
Source File: ConnectionsManager.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public static void onProxyError()
{
    AndroidUtilities.runOnUIThread(() -> NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needShowAlert, 3));
}
 
Example 13
Source File: StickerPreviewViewer.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
public boolean onInterceptTouchEvent(MotionEvent event, final View listView, final int height, StickerPreviewViewerDelegate stickerPreviewViewerDelegate) {
    delegate = stickerPreviewViewerDelegate;
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int x = (int) event.getX();
        int y = (int) event.getY();
        int count = 0;
        if (listView instanceof AbsListView) {
            count = ((AbsListView) listView).getChildCount();
        } else if (listView instanceof RecyclerListView) {
            count = ((RecyclerListView) listView).getChildCount();
        }
        for (int a = 0; a < count; a++) {
            View view = null;
            if (listView instanceof AbsListView) {
                view = ((AbsListView) listView).getChildAt(a);
            } else if (listView instanceof RecyclerListView) {
                view = ((RecyclerListView) listView).getChildAt(a);
            }
            if (view == null) {
                return false;
            }
            int top = view.getTop();
            int bottom = view.getBottom();
            int left = view.getLeft();
            int right = view.getRight();
            if (top > y || bottom < y || left > x || right < x) {
                continue;
            }
            boolean ok = false;
            if (view instanceof StickerEmojiCell) {
                ok = ((StickerEmojiCell) view).showingBitmap();
            } else if (view instanceof StickerCell) {
                ok = ((StickerCell) view).showingBitmap();
            } else if (view instanceof ContextLinkCell) {
                ContextLinkCell cell = (ContextLinkCell) view;
                ok = cell.isSticker() && cell.showingBitmap();
            }
            if (!ok) {
                return false;
            }
            startX = x;
            startY = y;
            currentStickerPreviewCell = view;
            openStickerPreviewRunnable = new Runnable() {
                @Override
                public void run() {
                    if (openStickerPreviewRunnable == null) {
                        return;
                    }
                    if (listView instanceof AbsListView) {
                        ((AbsListView) listView).setOnItemClickListener(null);
                        ((AbsListView) listView).requestDisallowInterceptTouchEvent(true);
                    } else if (listView instanceof RecyclerListView) {
                        ((RecyclerListView) listView).setOnItemClickListener((RecyclerListView.OnItemClickListener) null);
                        ((RecyclerListView) listView).requestDisallowInterceptTouchEvent(true);
                    }
                    openStickerPreviewRunnable = null;
                    setParentActivity((Activity) listView.getContext());
                    setKeyboardHeight(height);
                    if (currentStickerPreviewCell instanceof StickerEmojiCell) {
                        open(((StickerEmojiCell) currentStickerPreviewCell).getSticker(), ((StickerEmojiCell) currentStickerPreviewCell).isRecent());
                        ((StickerEmojiCell) currentStickerPreviewCell).setScaled(true);
                    } else if (currentStickerPreviewCell instanceof StickerCell) {
                        open(((StickerCell) currentStickerPreviewCell).getSticker(), false);
                        ((StickerCell) currentStickerPreviewCell).setScaled(true);
                    } else if (currentStickerPreviewCell instanceof ContextLinkCell) {
                        open(((ContextLinkCell) currentStickerPreviewCell).getDocument(), false);
                        ((ContextLinkCell) currentStickerPreviewCell).setScaled(true);
                    }
                }
            };
            AndroidUtilities.runOnUIThread(openStickerPreviewRunnable, 200);
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: ChannelEditInfoActivity.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private boolean checkUserName(final String name) {
    if (name != null && name.length() > 0) {
        checkTextView.setVisibility(View.VISIBLE);
    } else {
        checkTextView.setVisibility(View.GONE);
    }
    if (checkRunnable != null) {
        AndroidUtilities.cancelRunOnUIThread(checkRunnable);
        checkRunnable = null;
        lastCheckName = null;
        if (checkReqId != 0) {
            ConnectionsManager.getInstance(currentAccount).cancelRequest(checkReqId, true);
        }
    }
    lastNameAvailable = false;
    if (name != null) {
        if (name.startsWith("_") || name.endsWith("_")) {
            checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
            checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
            checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
            return false;
        }
        for (int a = 0; a < name.length(); a++) {
            char ch = name.charAt(a);
            if (a == 0 && ch >= '0' && ch <= '9') {
                if (currentChat.megagroup) {
                    checkTextView.setText(LocaleController.getString("LinkInvalidStartNumberMega", R.string.LinkInvalidStartNumberMega));
                    checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
                    checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                } else {
                    checkTextView.setText(LocaleController.getString("LinkInvalidStartNumber", R.string.LinkInvalidStartNumber));
                    checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
                    checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                }
                return false;
            }
            if (!(ch >= '0' && ch <= '9' || ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch == '_')) {
                checkTextView.setText(LocaleController.getString("LinkInvalid", R.string.LinkInvalid));
                checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
                checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                return false;
            }
        }
    }
    if (name == null || name.length() < 5) {
        if (currentChat.megagroup) {
            checkTextView.setText(LocaleController.getString("LinkInvalidShortMega", R.string.LinkInvalidShortMega));
            checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
            checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
        } else {
            checkTextView.setText(LocaleController.getString("LinkInvalidShort", R.string.LinkInvalidShort));
            checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
            checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
        }
        return false;
    }
    if (name.length() > 32) {
        checkTextView.setText(LocaleController.getString("LinkInvalidLong", R.string.LinkInvalidLong));
        checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
        checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
        return false;
    }

    checkTextView.setText(LocaleController.getString("LinkChecking", R.string.LinkChecking));
    checkTextView.setTag(Theme.key_windowBackgroundWhiteGrayText8);
    checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText8));
    lastCheckName = name;
    checkRunnable = () -> {
        TLRPC.TL_channels_checkUsername req = new TLRPC.TL_channels_checkUsername();
        req.username = name;
        req.channel = MessagesController.getInstance(currentAccount).getInputChannel(chatId);
        checkReqId = ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
            checkReqId = 0;
            if (lastCheckName != null && lastCheckName.equals(name)) {
                if (error == null && response instanceof TLRPC.TL_boolTrue) {
                    checkTextView.setText(LocaleController.formatString("LinkAvailable", R.string.LinkAvailable, name));
                    checkTextView.setTag(Theme.key_windowBackgroundWhiteGreenText);
                    checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGreenText));
                    lastNameAvailable = true;
                } else {
                    if (error != null && error.text.equals("CHANNELS_ADMIN_PUBLIC_TOO_MUCH")) {
                        canCreatePublic = false;
                        loadAdminedChannels();
                    } else {
                        checkTextView.setText(LocaleController.getString("LinkInUse", R.string.LinkInUse));
                    }
                    checkTextView.setTag(Theme.key_windowBackgroundWhiteRedText4);
                    checkTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                    lastNameAvailable = false;
                }
            }
        }), ConnectionsManager.RequestFlagFailOnServerErrors);
    };
    AndroidUtilities.runOnUIThread(checkRunnable, 300);
    return true;
}
 
Example 15
Source File: SendLocationCell.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    checkText();
    invalidate((int) rect.left - 5, (int) rect.top - 5, (int) rect.right + 5, (int) rect.bottom + 5);
    AndroidUtilities.runOnUIThread(invalidateRunnable, 1000);
}
 
Example 16
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
protected void callEnded() {
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("Call " + getCallID() + " ended");
	}
	dispatchStateChanged(STATE_ENDED);
	if (needPlayEndSound) {
		playingSound = true;
		soundPool.play(spEndId, 1, 1, 0, 0, 1);
		AndroidUtilities.runOnUIThread(afterSoundRunnable, 700);
	}
	if(timeoutRunnable!=null){
		AndroidUtilities.cancelRunOnUIThread(timeoutRunnable);
		timeoutRunnable=null;
	}
	if(USE_CONNECTION_SERVICE){
		Runnable r=new Runnable(){
			@Override
			public void run(){
				if(systemCallConnection!=null){
					switch(callDiscardReason){
						case DISCARD_REASON_HANGUP:
							systemCallConnection.setDisconnected(new DisconnectCause(isOutgoing ? DisconnectCause.LOCAL : DisconnectCause.REJECTED));
							break;
						case DISCARD_REASON_DISCONNECT:
							systemCallConnection.setDisconnected(new DisconnectCause(DisconnectCause.ERROR));
							break;
						case DISCARD_REASON_LINE_BUSY:
							systemCallConnection.setDisconnected(new DisconnectCause(DisconnectCause.BUSY));
							break;
						case DISCARD_REASON_MISSED:
							systemCallConnection.setDisconnected(new DisconnectCause(isOutgoing ? DisconnectCause.CANCELED : DisconnectCause.MISSED));
							break;
						default:
							systemCallConnection.setDisconnected(new DisconnectCause(DisconnectCause.REMOTE));
							break;
					}
					systemCallConnection.destroy();
					systemCallConnection=null;
				}
			}
		};
		if(needPlayEndSound)
			AndroidUtilities.runOnUIThread(r, 700);
		else
			r.run();
	}
	stopSelf();
}
 
Example 17
Source File: VoIPBaseService.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onConnectionStateChanged(int newState) {
	if (newState == STATE_FAILED) {
		callFailed();
		return;
	}
	if (newState == STATE_ESTABLISHED) {
		if(connectingSoundRunnable!=null){
			AndroidUtilities.cancelRunOnUIThread(connectingSoundRunnable);
			connectingSoundRunnable=null;
		}
		if (spPlayID != 0) {
			soundPool.stop(spPlayID);
			spPlayID = 0;
		}
		if(!wasEstablished){
			wasEstablished=true;
			if(!isProximityNear){
				Vibrator vibrator=(Vibrator) getSystemService(VIBRATOR_SERVICE);
				if(vibrator.hasVibrator())
					vibrator.vibrate(100);
			}
			AndroidUtilities.runOnUIThread(new Runnable(){
				@Override
				public void run(){
					if (tgVoip != null) {
						StatsController.getInstance(currentAccount).incrementTotalCallsTime(getStatsNetworkType(), 5);
						AndroidUtilities.runOnUIThread(this, 5000);
					}
				}
			}, 5000);
			if(isOutgoing)
				StatsController.getInstance(currentAccount).incrementSentItemsCount(getStatsNetworkType(), StatsController.TYPE_CALLS, 1);
			else
				StatsController.getInstance(currentAccount).incrementReceivedItemsCount(getStatsNetworkType(), StatsController.TYPE_CALLS, 1);
		}
	}
	if(newState==STATE_RECONNECTING){
		if(spPlayID!=0)
			soundPool.stop(spPlayID);
		spPlayID=soundPool.play(spConnectingId, 1, 1, 0, -1, 1);
	}
	dispatchStateChanged(newState);
}
 
Example 18
Source File: AudioPlayerAlert.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
private void processSearch(final String query) {
    AndroidUtilities.runOnUIThread(() -> {
        final ArrayList<MessageObject> copy = new ArrayList<>(playlist);
        Utilities.searchQueue.postRunnable(() -> {
            String search1 = query.trim().toLowerCase();
            if (search1.length() == 0) {
                updateSearchResults(new ArrayList<>());
                return;
            }
            String search2 = LocaleController.getInstance().getTranslitString(search1);
            if (search1.equals(search2) || search2.length() == 0) {
                search2 = null;
            }
            String[] search = new String[1 + (search2 != null ? 1 : 0)];
            search[0] = search1;
            if (search2 != null) {
                search[1] = search2;
            }

            ArrayList<MessageObject> resultArray = new ArrayList<>();

            for (int a = 0; a < copy.size(); a++) {
                MessageObject messageObject = copy.get(a);
                for (int b = 0; b < search.length; b++) {
                    String q = search[b];
                    String name = messageObject.getDocumentName();
                    if (name == null || name.length() == 0) {
                        continue;
                    }
                    name = name.toLowerCase();
                    if (name.contains(q)) {
                        resultArray.add(messageObject);
                        break;
                    }
                    TLRPC.Document document;
                    if (messageObject.type == 0) {
                        document = messageObject.messageOwner.media.webpage.document;
                    } else {
                        document = messageObject.messageOwner.media.document;
                    }
                    boolean ok = false;
                    for (int c = 0; c < document.attributes.size(); c++) {
                        TLRPC.DocumentAttribute attribute = document.attributes.get(c);
                        if (attribute instanceof TLRPC.TL_documentAttributeAudio) {
                            if (attribute.performer != null) {
                                ok = attribute.performer.toLowerCase().contains(q);
                            }
                            if (!ok && attribute.title != null) {
                                ok = attribute.title.toLowerCase().contains(q);
                            }
                            break;
                        }
                    }
                    if (ok) {
                        resultArray.add(messageObject);
                        break;
                    }
                }
            }

            updateSearchResults(resultArray);
        });
    });
}
 
Example 19
Source File: VoIPBaseService.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void onDestroy() {
	if (BuildVars.LOGS_ENABLED) {
		FileLog.d("=============== VoIPService STOPPING ===============");
	}
	stopForeground(true);
	stopRinging();
	NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.appDidLogout);
	SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
	Sensor proximity = sm.getDefaultSensor(Sensor.TYPE_PROXIMITY);
	if (proximity != null) {
		sm.unregisterListener(this);
	}
	if (proximityWakelock != null && proximityWakelock.isHeld()) {
		proximityWakelock.release();
	}
	unregisterReceiver(receiver);
	if(timeoutRunnable!=null){
		AndroidUtilities.cancelRunOnUIThread(timeoutRunnable);
		timeoutRunnable=null;
	}
	super.onDestroy();
	sharedInstance = null;
	AndroidUtilities.runOnUIThread(new Runnable(){
		@Override
		public void run(){
			NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.didEndedCall);
		}
	});
	if (controller != null && controllerStarted) {
		lastKnownDuration = controller.getCallDuration();
		updateStats();
		StatsController.getInstance(currentAccount).incrementTotalCallsTime(getStatsNetworkType(), (int) (lastKnownDuration / 1000) % 5);
		onControllerPreRelease();
		controller.release();
		controller = null;
	}
	cpuWakelock.release();
	AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
	if(!USE_CONNECTION_SERVICE){
		if(isBtHeadsetConnected && !playingSound){
			am.stopBluetoothSco();
			am.setSpeakerphoneOn(false);
		}
		try{
			am.setMode(AudioManager.MODE_NORMAL);
		}catch(SecurityException x){
			if(BuildVars.LOGS_ENABLED){
				FileLog.e("Error setting audio more to normal", x);
			}
		}
		am.abandonAudioFocus(this);
	}
	am.unregisterMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class));
	if (haveAudioFocus)
		am.abandonAudioFocus(this);

	if (!playingSound)
		soundPool.release();

	if(USE_CONNECTION_SERVICE){
		if(systemCallConnection!=null && !playingSound){
			systemCallConnection.destroy();
		}
	}

	ConnectionsManager.getInstance(currentAccount).setAppPaused(true, false);
	VoIPHelper.lastCallTime=System.currentTimeMillis();
}
 
Example 20
Source File: ConnectionsManager.java    From Telegram-FOSS with GNU General Public License v2.0 4 votes vote down vote up
public static void onConnectionStateChanged(final int state, final int currentAccount) {
    AndroidUtilities.runOnUIThread(() -> {
        getInstance(currentAccount).connectionState = state;
        AccountInstance.getInstance(currentAccount).getNotificationCenter().postNotificationName(NotificationCenter.didUpdateConnectionState);
    });
}