Я пытаюсь открыть окно наложения, когда нажимаю на свою плитку. Окно наложения появляется, но панель быстрых настроек не увольняется. Пробовал прочитать документы и реализованные намерения - единственный подход к закрытию панели. Но я знаю, что есть способ сделать это без использования намерений. Просто не удалось найти способ, который работает.@Override
public void onClick() {
// Using the proper TileService method to handle clicks
if (isLocked()) {
// If device is locked, unlock it first and then run our code
unlockAndRun(this::toggleScannerWindow);
} else {
// If device is already unlocked, just run our code directly
// The panel will close automatically when onClick() returns
toggleScannerWindow();
}
}
private void toggleScannerWindow() {
if (qrWindow == null) {
qrWindow = new QRScannerWindow(getApplicationContext());
qrWindow.open();
} else {
qrWindow.close();
qrWindow = null;
}
}
< /code>
Я бы добавил фрагмент моего класса Overlay Window. < /p>
public QRScannerWindow(Context context) {
this.context = context;
this.cameraExecutor = Executors.newSingleThreadExecutor();
// Get ViewModel using application context
// ViewModel setup
Application application = (Application) context.getApplicationContext();
viewModel = new ViewModelProvider.AndroidViewModelFactory(application)
.create(QRScannerViewModel.class);
// Window setup
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
);
// Inflate layout
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rootView = inflater.inflate(R.layout.qr_scanner_overlay, null);
rootView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
close_button = rootView.findViewById(R.id.close);
baseRoot = rootView.findViewById(R.id.root);
root = rootView.findViewById(R.id.root); // This is to be used by TransitionManager
header_layout = rootView.findViewById(R.id.header_layout);
bodyLayout = rootView.findViewById(R.id.bodyLayout);
actions();
// Define the position of the
// window within the screen
params.gravity = Gravity.BOTTOM;
windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
}
private void actions() {
baseRoot.setOnClickListener(view -> close());
}
public void open() {
try {
TransitionManager.beginDelayedTransition(root);
header_layout.setVisibility(View.VISIBLE);
bodyLayout.setVisibility(View.VISIBLE);
openingTransitionAnimationHandler.post(() -> {
TransitionManager.beginDelayedTransition(root);
header_layout.setVisibility(View.VISIBLE);
bodyLayout.setVisibility(View.VISIBLE);
});
// check if the view is already
// inflated or present in the window
if (rootView.getWindowToken() == null) {
if (rootView.getParent() == null) {
windowManager.addView(rootView, params);
}
}
} catch (Exception e) {
Log.d("Error1", e.toString());
}
}
public void close() {
TransitionManager.beginDelayedTransition(root);
header_layout.setVisibility(View.GONE);
bodyLayout.setVisibility(View.GONE);
close_button.setVisibility(View.GONE);
getHandler.postDelayed(() -> {
try {
Log.d("DEBUG", "close method called");
ViewParent parent = rootView.getParent();
if (parent instanceof ViewGroup parentViewGroup) {
parentViewGroup.removeAllViews();
}
// remove the view from the window
((WindowManager) context.getSystemService(WINDOW_SERVICE)).removeView(rootView);
// invalidate the view
rootView.invalidate();
} catch (Exception e) {
Log.e("Error2", e.toString());
}
getHandler.removeCallbacksAndMessages(null);
}, 1000);
}
Подробнее здесь: https://stackoverflow.com/questions/795 ... -an-activi
Уволить панель плитки быстрых настроек, когда я нажимаю на плитку? Не открывать занятие, а окно наложения ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как добавить плитку быстрых настроек Android сразу после установки приложения
Anonymous » » в форуме Android - 0 Ответы
- 32 Просмотры
-
Последнее сообщение Anonymous
-
-
-
В группе активности, как восстановить предыдущее занятие (без перезапуска)
Anonymous » » в форуме Android - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-