• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.content.Context;
20 import android.graphics.PixelFormat;
21 import android.os.Binder;
22 import android.view.View;
23 import android.view.WindowManager;
24 
25 import static android.view.WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
26 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
27 import static android.view.WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
28 import static android.view.WindowManager.LayoutParams.FLAG_SLIPPERY;
29 import static android.view.WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
30 import static android.view.WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
31 import static android.view.WindowManager.LayoutParams.PRIVATE_FLAG_NO_MOVE_ANIMATION;
32 import static android.view.WindowManager.LayoutParams.TYPE_DOCK_DIVIDER;
33 
34 /**
35  * Manages the window parameters of the docked stack divider.
36  */
37 public class DividerWindowManager {
38 
39     private static final String WINDOW_TITLE = "DockedStackDivider";
40 
41     private final WindowManager mWindowManager;
42     private WindowManager.LayoutParams mLp;
43     private View mView;
44 
DividerWindowManager(Context ctx)45     public DividerWindowManager(Context ctx) {
46         mWindowManager = ctx.getSystemService(WindowManager.class);
47     }
48 
add(View view, int width, int height)49     public void add(View view, int width, int height) {
50         mLp = new WindowManager.LayoutParams(
51                 width, height, TYPE_DOCK_DIVIDER,
52                 FLAG_NOT_FOCUSABLE | FLAG_NOT_TOUCH_MODAL
53                         | FLAG_WATCH_OUTSIDE_TOUCH | FLAG_SPLIT_TOUCH | FLAG_SLIPPERY,
54                 PixelFormat.TRANSLUCENT);
55         mLp.token = new Binder();
56         mLp.setTitle(WINDOW_TITLE);
57         mLp.privateFlags |= PRIVATE_FLAG_NO_MOVE_ANIMATION;
58         view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
59                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
60                 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
61         mWindowManager.addView(view, mLp);
62         mView = view;
63     }
64 
remove()65     public void remove() {
66         if (mView != null) {
67             mWindowManager.removeView(mView);
68         }
69         mView = null;
70     }
71 
setSlippery(boolean slippery)72     public void setSlippery(boolean slippery) {
73         boolean changed = false;
74         if (slippery && (mLp.flags & FLAG_SLIPPERY) == 0) {
75             mLp.flags |= FLAG_SLIPPERY;
76             changed = true;
77         } else if (!slippery && (mLp.flags & FLAG_SLIPPERY) != 0) {
78             mLp.flags &= ~FLAG_SLIPPERY;
79             changed = true;
80         }
81         if (changed) {
82             mWindowManager.updateViewLayout(mView, mLp);
83         }
84     }
85 
setTouchable(boolean touchable)86     public void setTouchable(boolean touchable) {
87         boolean changed = false;
88         if (!touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) == 0) {
89             mLp.flags |= FLAG_NOT_TOUCHABLE;
90             changed = true;
91         } else if (touchable && (mLp.flags & FLAG_NOT_TOUCHABLE) != 0) {
92             mLp.flags &= ~FLAG_NOT_TOUCHABLE;
93             changed = true;
94         }
95         if (changed) {
96             mWindowManager.updateViewLayout(mView, mLp);
97         }
98     }
99 }
100