1 /*
2  * Copyright (C) 2019 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.settings.gestures;
18 
19 import android.content.Context;
20 import android.content.res.TypedArray;
21 import android.graphics.PixelFormat;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.view.WindowManager;
26 import android.widget.ImageView;
27 import android.widget.LinearLayout;
28 
29 import com.android.settings.R;
30 
31 /**
32  * A linear layout containing the left and right location indicators.
33  */
34 public class BackGestureIndicatorView extends LinearLayout {
35     private ViewGroup mLayout;
36     private ImageView mLeftIndicator;
37     private ImageView mRightIndicator;
38     private BackGestureIndicatorDrawable mLeftDrawable;
39     private BackGestureIndicatorDrawable mRightDrawable;
40 
BackGestureIndicatorView(Context context)41     public BackGestureIndicatorView(Context context) {
42         super(context);
43 
44         LayoutInflater factory = LayoutInflater.from(context);
45         mLayout = (ViewGroup) factory.inflate(R.layout.back_gesture_indicator_container,
46                 this, false);
47 
48         if (mLayout == null) {
49             return;
50         }
51 
52         addView(mLayout);
53 
54         mLeftDrawable = new BackGestureIndicatorDrawable(context, false);
55         mRightDrawable = new BackGestureIndicatorDrawable(context, true);
56 
57         mLeftIndicator = mLayout.findViewById(R.id.indicator_left);
58         mRightIndicator = mLayout.findViewById(R.id.indicator_right);
59 
60         mLeftIndicator.setImageDrawable(mLeftDrawable);
61         mRightIndicator.setImageDrawable(mRightDrawable);
62 
63         int visibility = getSystemUiVisibility()
64                 | View.SYSTEM_UI_FLAG_IMMERSIVE
65                 | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
66                 | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
67                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
68                 | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
69                 | View.SYSTEM_UI_FLAG_FULLSCREEN;
70 
71         TypedArray a = context.obtainStyledAttributes(new int[] {
72                 android.R.attr.windowLightNavigationBar,
73                 android.R.attr.windowLightStatusBar});
74         if (a.getBoolean(0, false)) {
75             visibility |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
76         }
77         if (a.getBoolean(1, false)) {
78             visibility |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
79         }
80         a.recycle();
81 
82         setSystemUiVisibility(visibility);
83     }
84 
setIndicatorWidth(int width, boolean leftIndicator)85     public void setIndicatorWidth(int width, boolean leftIndicator) {
86         BackGestureIndicatorDrawable indicator = leftIndicator ? mLeftDrawable : mRightDrawable;
87         indicator.setWidth(width);
88     }
89 
getLayoutParams( WindowManager.LayoutParams parentWindowAttributes)90     public WindowManager.LayoutParams getLayoutParams(
91             WindowManager.LayoutParams parentWindowAttributes) {
92         int copiedFlags = (parentWindowAttributes.flags
93                 & WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
94         final WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
95                 WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
96                 WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
97                         | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
98                         | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
99                         | copiedFlags,
100                 PixelFormat.TRANSLUCENT);
101 
102         lp.setTitle("BackGestureIndicatorView");
103         lp.token = getContext().getActivityToken();
104         return lp;
105     }
106 }
107