• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2012 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.statusbar.phone;
18 
19 import android.animation.LayoutTransition;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.res.Resources;
23 import android.graphics.Canvas;
24 import android.graphics.drawable.Drawable;
25 import android.util.AttributeSet;
26 import android.util.EventLog;
27 import android.view.LayoutInflater;
28 import android.view.MotionEvent;
29 import android.view.View;
30 import android.view.ViewGroup;
31 import android.view.accessibility.AccessibilityEvent;
32 
33 import com.android.systemui.EventLogTags;
34 import com.android.systemui.R;
35 import com.android.systemui.statusbar.BaseStatusBar;
36 import com.android.systemui.statusbar.GestureRecorder;
37 import com.android.systemui.statusbar.policy.BatteryController;
38 import com.android.systemui.statusbar.policy.BluetoothController;
39 import com.android.systemui.statusbar.policy.LocationController;
40 import com.android.systemui.statusbar.policy.NetworkController;
41 
42 public class SettingsPanelView extends PanelView {
43     public static final boolean DEBUG_GESTURES = true;
44 
45     private QuickSettings mQS;
46     private QuickSettingsContainerView mQSContainer;
47 
48     Drawable mHandleBar;
49     int mHandleBarHeight;
50     View mHandleView;
51 
SettingsPanelView(Context context, AttributeSet attrs)52     public SettingsPanelView(Context context, AttributeSet attrs) {
53         super(context, attrs);
54     }
55 
56     @Override
onFinishInflate()57     protected void onFinishInflate() {
58         super.onFinishInflate();
59 
60         mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container);
61 
62         Resources resources = getContext().getResources();
63         mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
64         mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
65         mHandleView = findViewById(R.id.handle);
66     }
67 
setQuickSettings(QuickSettings qs)68     public void setQuickSettings(QuickSettings qs) {
69         mQS = qs;
70     }
71 
72     @Override
setBar(PanelBar panelBar)73     public void setBar(PanelBar panelBar) {
74         super.setBar(panelBar);
75 
76         if (mQS != null) {
77             mQS.setBar(panelBar);
78         }
79     }
80 
setImeWindowStatus(boolean visible)81     public void setImeWindowStatus(boolean visible) {
82         if (mQS != null) {
83             mQS.setImeWindowStatus(visible);
84         }
85     }
86 
setup(NetworkController networkController, BluetoothController bluetoothController, BatteryController batteryController, LocationController locationController)87     public void setup(NetworkController networkController, BluetoothController bluetoothController,
88             BatteryController batteryController, LocationController locationController) {
89         if (mQS != null) {
90             mQS.setup(networkController, bluetoothController, batteryController,
91                     locationController);
92         }
93     }
94 
updateResources()95     void updateResources() {
96         if (mQS != null) {
97             mQS.updateResources();
98         }
99         if (mQSContainer != null) {
100             mQSContainer.updateResources();
101         }
102         requestLayout();
103     }
104 
105     @Override
fling(float vel, boolean always)106     public void fling(float vel, boolean always) {
107         GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
108         if (gr != null) {
109             gr.tag(
110                 "fling " + ((vel > 0) ? "open" : "closed"),
111                 "settings,v=" + vel);
112         }
113         super.fling(vel, always);
114     }
115 
setService(PhoneStatusBar phoneStatusBar)116     public void setService(PhoneStatusBar phoneStatusBar) {
117         if (mQS != null) {
118             mQS.setService(phoneStatusBar);
119         }
120     }
121 
122     @Override
dispatchPopulateAccessibilityEvent(AccessibilityEvent event)123     public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
124         if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
125             event.getText()
126                     .add(getContext().getString(R.string.accessibility_desc_quick_settings));
127             return true;
128         }
129 
130         return super.dispatchPopulateAccessibilityEvent(event);
131     }
132 
133     // We draw the handle ourselves so that it's always glued to the bottom of the window.
134     @Override
onLayout(boolean changed, int left, int top, int right, int bottom)135     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
136         super.onLayout(changed, left, top, right, bottom);
137         if (changed) {
138             final int pl = getPaddingLeft();
139             final int pr = getPaddingRight();
140             mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
141         }
142     }
143 
144     @Override
draw(Canvas canvas)145     public void draw(Canvas canvas) {
146         super.draw(canvas);
147         final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
148         canvas.translate(0, off);
149         mHandleBar.setState(mHandleView.getDrawableState());
150         mHandleBar.draw(canvas);
151         canvas.translate(0, -off);
152     }
153 
154     @Override
onTouchEvent(MotionEvent event)155     public boolean onTouchEvent(MotionEvent event) {
156         if (DEBUG_GESTURES) {
157             if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
158                 EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH,
159                        event.getActionMasked(), (int) event.getX(), (int) event.getY());
160             }
161         }
162         return super.onTouchEvent(event);
163     }
164 }
165