Search in sources :

Example 1 with VoIPWindowView

use of org.telegram.ui.Components.voip.VoIPWindowView in project Telegram-FOSS by Telegram-FOSS-Team.

the class VoIPFragment method show.

public static void show(Activity activity, boolean overlay, int account) {
    if (instance != null && instance.windowView.getParent() == null) {
        if (instance != null) {
            instance.callingUserTextureView.renderer.release();
            instance.currentUserTextureView.renderer.release();
            instance.callingUserMiniTextureRenderer.release();
            instance.destroy();
        }
        instance = null;
    }
    if (instance != null || activity.isFinishing()) {
        return;
    }
    boolean transitionFromPip = VoIPPiPView.getInstance() != null;
    if (VoIPService.getSharedInstance() == null || VoIPService.getSharedInstance().getUser() == null) {
        return;
    }
    VoIPFragment fragment = new VoIPFragment(account);
    fragment.activity = activity;
    instance = fragment;
    VoIPWindowView windowView = new VoIPWindowView(activity, !transitionFromPip) {

        @Override
        public boolean dispatchKeyEvent(KeyEvent event) {
            if (fragment.isFinished || fragment.switchingToPip) {
                return false;
            }
            final int keyCode = event.getKeyCode();
            if (keyCode == KeyEvent.KEYCODE_BACK && event.getAction() == KeyEvent.ACTION_UP && !fragment.lockOnScreen) {
                fragment.onBackPressed();
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN || keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                if (fragment.currentState == VoIPService.STATE_WAITING_INCOMING) {
                    final VoIPService service = VoIPService.getSharedInstance();
                    if (service != null) {
                        service.stopRinging();
                        return true;
                    }
                }
            }
            return super.dispatchKeyEvent(event);
        }
    };
    instance.deviceIsLocked = ((KeyguardManager) activity.getSystemService(Context.KEYGUARD_SERVICE)).inKeyguardRestrictedInputMode();
    PowerManager pm = (PowerManager) activity.getSystemService(Context.POWER_SERVICE);
    boolean screenOn;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        screenOn = pm.isInteractive();
    } else {
        screenOn = pm.isScreenOn();
    }
    instance.screenWasWakeup = !screenOn;
    windowView.setLockOnScreen(instance.deviceIsLocked);
    fragment.windowView = windowView;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        windowView.setOnApplyWindowInsetsListener((view, windowInsets) -> {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                fragment.setInsets(windowInsets);
            }
            if (Build.VERSION.SDK_INT >= 30) {
                return WindowInsets.CONSUMED;
            } else {
                return windowInsets.consumeSystemWindowInsets();
            }
        });
    }
    WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
    WindowManager.LayoutParams layoutParams = windowView.createWindowLayoutParams();
    if (overlay) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
        } else {
            layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
        }
    }
    wm.addView(windowView, layoutParams);
    View view = fragment.createView(activity);
    windowView.addView(view);
    if (transitionFromPip) {
        fragment.enterTransitionProgress = 0f;
        fragment.startTransitionFromPiP();
    } else {
        fragment.enterTransitionProgress = 1f;
        fragment.updateSystemBarColors();
    }
}
Also used : KeyEvent(android.view.KeyEvent) PowerManager(android.os.PowerManager) VoIPWindowView(org.telegram.ui.Components.voip.VoIPWindowView) ImageView(android.widget.ImageView) VoIPPiPView(org.telegram.ui.Components.voip.VoIPPiPView) View(android.view.View) AcceptDeclineView(org.telegram.ui.Components.voip.AcceptDeclineView) VoIPStatusTextView(org.telegram.ui.Components.voip.VoIPStatusTextView) TextView(android.widget.TextView) VoIPWindowView(org.telegram.ui.Components.voip.VoIPWindowView) HintView(org.telegram.ui.Components.HintView) VoIPTextureView(org.telegram.ui.Components.voip.VoIPTextureView) BackupImageView(org.telegram.ui.Components.BackupImageView) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) VoIPService(org.telegram.messenger.voip.VoIPService) WindowManager(android.view.WindowManager)

Aggregations

SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 PowerManager (android.os.PowerManager)1 KeyEvent (android.view.KeyEvent)1 View (android.view.View)1 WindowManager (android.view.WindowManager)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 VoIPService (org.telegram.messenger.voip.VoIPService)1 BackupImageView (org.telegram.ui.Components.BackupImageView)1 HintView (org.telegram.ui.Components.HintView)1 AcceptDeclineView (org.telegram.ui.Components.voip.AcceptDeclineView)1 VoIPPiPView (org.telegram.ui.Components.voip.VoIPPiPView)1 VoIPStatusTextView (org.telegram.ui.Components.voip.VoIPStatusTextView)1 VoIPTextureView (org.telegram.ui.Components.voip.VoIPTextureView)1 VoIPWindowView (org.telegram.ui.Components.voip.VoIPWindowView)1