1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.systemui.accessibility.floatingmenu; 18 19 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION; 20 21 import android.content.Context; 22 import android.graphics.PixelFormat; 23 import android.view.WindowInsets; 24 import android.view.WindowManager; 25 import android.view.accessibility.AccessibilityManager; 26 27 import com.android.systemui.util.settings.SecureSettings; 28 29 /** 30 * Controls the {@link MenuViewLayer} whether to be attached to the window via the interface 31 * of {@link IAccessibilityFloatingMenu}. 32 */ 33 class MenuViewLayerController implements IAccessibilityFloatingMenu { 34 private final WindowManager mWindowManager; 35 private final MenuViewLayer mMenuViewLayer; 36 private boolean mIsShowing; 37 MenuViewLayerController(Context context, WindowManager windowManager, AccessibilityManager accessibilityManager, SecureSettings secureSettings)38 MenuViewLayerController(Context context, WindowManager windowManager, 39 AccessibilityManager accessibilityManager, SecureSettings secureSettings) { 40 mWindowManager = windowManager; 41 mMenuViewLayer = new MenuViewLayer(context, windowManager, accessibilityManager, this, 42 secureSettings); 43 } 44 45 @Override isShowing()46 public boolean isShowing() { 47 return mIsShowing; 48 } 49 50 @Override show()51 public void show() { 52 if (isShowing()) { 53 return; 54 } 55 56 mIsShowing = true; 57 mWindowManager.addView(mMenuViewLayer, createDefaultLayerLayoutParams()); 58 } 59 60 @Override hide()61 public void hide() { 62 if (!isShowing()) { 63 return; 64 } 65 66 mIsShowing = false; 67 mWindowManager.removeView(mMenuViewLayer); 68 } 69 createDefaultLayerLayoutParams()70 private static WindowManager.LayoutParams createDefaultLayerLayoutParams() { 71 final WindowManager.LayoutParams params = new WindowManager.LayoutParams( 72 WindowManager.LayoutParams.MATCH_PARENT, 73 WindowManager.LayoutParams.MATCH_PARENT, 74 WindowManager.LayoutParams.TYPE_NAVIGATION_BAR_PANEL, 75 WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, 76 PixelFormat.TRANSLUCENT); 77 params.receiveInsetsIgnoringZOrder = true; 78 params.privateFlags |= PRIVATE_FLAG_EXCLUDE_FROM_SCREEN_MAGNIFICATION; 79 params.windowAnimations = android.R.style.Animation_Translucent; 80 params.setFitInsetsTypes( 81 WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout()); 82 return params; 83 } 84 } 85