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();
}
}
Aggregations