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