1 /* 2 * Copyright (C) 2015 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.stackdivider; 18 19 import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; 20 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE; 21 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL; 22 import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY; 23 import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH; 24 import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH; 25 import static android.view.WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; 26 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION; 27 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER; 28 29 import android.graphics.PixelFormat; 30 import android.graphics.Region; 31 import android.os.Binder; 32 import android.view.View; 33 import android.view.WindowManager; 34 35 import com.android.systemui.wm.SystemWindows; 36 37 /** 38 * Manages the window parameters of the docked stack divider. 39 */ 40 public class DividerWindowManager { 41 42 private static final String WINDOW_TITLE = "DockedStackDivider"; 43 44 final SystemWindows mSystemWindows; 45 private WindowManager.LayoutParams mLp; 46 private View mView; 47 DividerWindowManager(SystemWindows systemWindows)48 public DividerWindowManager(SystemWindows systemWindows) { 49 mSystemWindows = systemWindows; 50 } 51 52 /** Add a divider view */ add(View view, int width, int height, int displayId)53 public void add(View view, int width, int height, int displayId) { 54 mLp = new WindowManager.LayoutParams( 55 width, height, TYPE_DOCK_DIVIDER, 56 FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL 57 | FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY, 58 PixelFormat.TRANSLUCENT); 59 mLp.token = new Binder(); 60 mLp.setTitle(WINDOW_TITLE); 61 mLp.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION; 62 mLp.layoutInDisplayCutoutMode = LAYOUT_IN_DISPLAY_CUTOUT_MODE_ALWAYS; 63 view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 64 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 65 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); 66 mSystemWindows.addView(view, mLp, displayId, TYPE_DOCK_DIVIDER); 67 mView = view; 68 } 69 remove()70 public void remove() { 71 if (mView != null) { 72 mSystemWindows.removeView(mView); 73 } 74 mView = null; 75 } 76 setSlippery(boolean slippery)77 public void setSlippery(boolean slippery) { 78 boolean changed = false; 79 if (slippery && (mLp.flags & FLAG_SLIPPERY) == 0) { 80 mLp.flags |= FLAG_SLIPPERY; 81 changed = true; 82 } else if (!slippery && (mLp.flags & FLAG_SLIPPERY) != 0) { 83 mLp.flags &= ~FLAG_SLIPPERY; 84 changed = true; 85 } 86 if (changed) { 87 mSystemWindows.updateViewLayout(mView, mLp); 88 } 89 } 90 setTouchable(boolean touchable)91 public void setTouchable(boolean touchable) { 92 if (mView == null) { 93 return; 94 } 95 boolean changed = false; 96 if (!touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) == 0) { 97 mLp.flags |= FLAG_NOT_TOUCHABLE; 98 changed = true; 99 } else if (touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) != 0) { 100 mLp.flags &= ~FLAG_NOT_TOUCHABLE; 101 changed = true; 102 } 103 if (changed) { 104 mSystemWindows.updateViewLayout(mView, mLp); 105 } 106 } 107 108 /** Sets the touch region to `touchRegion`. Use null to unset.*/ setTouchRegion(Region touchRegion)109 public void setTouchRegion(Region touchRegion) { 110 if (mView == null) { 111 return; 112 } 113 mSystemWindows.setTouchableRegion(mView, touchRegion); 114 } 115 } 116