blob: c10a0d4b8e59b7d7395b320c1fb6677f39930122 [file] [log] [blame]
Daniel Sandlercf591db2012-08-15 16:11:55 -04001/*
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
17package com.android.systemui.statusbar.phone;
18
19import android.content.Context;
Winson Chungd63c59782012-09-05 17:34:41 -070020import android.content.res.Resources;
Daniel Sandler13522a22012-09-27 14:46:58 -040021import android.graphics.Canvas;
22import android.graphics.drawable.Drawable;
Daniel Sandlercf591db2012-08-15 16:11:55 -040023import android.util.AttributeSet;
Chris Wren64161cc2012-12-17 16:49:30 -050024import android.util.EventLog;
Chris Wren64161cc2012-12-17 16:49:30 -050025import android.view.MotionEvent;
Winson Chungd63c59782012-09-05 17:34:41 -070026import android.view.View;
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070027import android.view.accessibility.AccessibilityEvent;
Winson Chungd63c59782012-09-05 17:34:41 -070028
Chris Wren64161cc2012-12-17 16:49:30 -050029import com.android.systemui.EventLogTags;
Winson Chungd63c59782012-09-05 17:34:41 -070030import com.android.systemui.R;
Daniel Sandler151f00d2012-10-02 22:33:08 -040031import com.android.systemui.statusbar.GestureRecorder;
Winson Chungd63c59782012-09-05 17:34:41 -070032import com.android.systemui.statusbar.policy.BatteryController;
33import com.android.systemui.statusbar.policy.BluetoothController;
34import com.android.systemui.statusbar.policy.LocationController;
35import com.android.systemui.statusbar.policy.NetworkController;
Svetoslav79578b22013-04-29 16:55:57 -070036import com.android.systemui.statusbar.policy.RotationLockController;
Daniel Sandlercf591db2012-08-15 16:11:55 -040037
38public class SettingsPanelView extends PanelView {
Chris Wren64161cc2012-12-17 16:49:30 -050039 public static final boolean DEBUG_GESTURES = true;
Winson Chungd63c59782012-09-05 17:34:41 -070040
41 private QuickSettings mQS;
42 private QuickSettingsContainerView mQSContainer;
43
Daniel Sandler13522a22012-09-27 14:46:58 -040044 Drawable mHandleBar;
Daniel Sandler076324ae2012-11-30 16:14:21 -050045 int mHandleBarHeight;
Daniel Sandler13522a22012-09-27 14:46:58 -040046 View mHandleView;
47
Daniel Sandlercf591db2012-08-15 16:11:55 -040048 public SettingsPanelView(Context context, AttributeSet attrs) {
49 super(context, attrs);
50 }
51
52 @Override
Winson Chungd63c59782012-09-05 17:34:41 -070053 protected void onFinishInflate() {
54 super.onFinishInflate();
55
56 mQSContainer = (QuickSettingsContainerView) findViewById(R.id.quick_settings_container);
Daniel Sandler13522a22012-09-27 14:46:58 -040057
58 Resources resources = getContext().getResources();
59 mHandleBar = resources.getDrawable(R.drawable.status_bar_close);
Daniel Sandler076324ae2012-11-30 16:14:21 -050060 mHandleBarHeight = resources.getDimensionPixelSize(R.dimen.close_handle_height);
Daniel Sandler13522a22012-09-27 14:46:58 -040061 mHandleView = findViewById(R.id.handle);
Winson Chungd63c59782012-09-05 17:34:41 -070062 }
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -070063
Daniel Sandler101784e2012-10-15 13:39:38 -040064 public void setQuickSettings(QuickSettings qs) {
65 mQS = qs;
66 }
Winson Chungd63c59782012-09-05 17:34:41 -070067
68 @Override
69 public void setBar(PanelBar panelBar) {
70 super.setBar(panelBar);
71
72 if (mQS != null) {
73 mQS.setBar(panelBar);
74 }
75 }
76
Winson Chung43229d72012-09-12 18:04:18 -070077 public void setImeWindowStatus(boolean visible) {
78 if (mQS != null) {
79 mQS.setImeWindowStatus(visible);
80 }
81 }
82
Winson Chungd63c59782012-09-05 17:34:41 -070083 public void setup(NetworkController networkController, BluetoothController bluetoothController,
Svetoslav79578b22013-04-29 16:55:57 -070084 BatteryController batteryController, LocationController locationController,
85 RotationLockController rotationLockController) {
Winson Chungd63c59782012-09-05 17:34:41 -070086 if (mQS != null) {
87 mQS.setup(networkController, bluetoothController, batteryController,
Svetoslav79578b22013-04-29 16:55:57 -070088 locationController, rotationLockController);
Winson Chungd63c59782012-09-05 17:34:41 -070089 }
90 }
91
92 void updateResources() {
93 if (mQS != null) {
94 mQS.updateResources();
95 }
96 if (mQSContainer != null) {
97 mQSContainer.updateResources();
98 }
99 requestLayout();
100 }
101
102 @Override
Daniel Sandlercf591db2012-08-15 16:11:55 -0400103 public void fling(float vel, boolean always) {
Daniel Sandler151f00d2012-10-02 22:33:08 -0400104 GestureRecorder gr = ((PhoneStatusBarView) mBar).mBar.getGestureRecorder();
105 if (gr != null) {
106 gr.tag(
107 "fling " + ((vel > 0) ? "open" : "closed"),
108 "settings,v=" + vel);
109 }
Daniel Sandlercf591db2012-08-15 16:11:55 -0400110 super.fling(vel, always);
111 }
Daniel Sandler3ffdcc72012-09-23 14:31:48 -0400112
113 public void setService(PhoneStatusBar phoneStatusBar) {
114 if (mQS != null) {
115 mQS.setService(phoneStatusBar);
116 }
117 }
Daniel Sandler13522a22012-09-27 14:46:58 -0400118
Casey Burkhardt23b0a4e2013-04-29 12:18:32 -0700119 @Override
120 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) {
121 if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
122 event.getText()
123 .add(getContext().getString(R.string.accessibility_desc_quick_settings));
124 return true;
125 }
126
127 return super.dispatchPopulateAccessibilityEvent(event);
128 }
129
Daniel Sandler13522a22012-09-27 14:46:58 -0400130 // We draw the handle ourselves so that it's always glued to the bottom of the window.
131 @Override
132 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
133 super.onLayout(changed, left, top, right, bottom);
134 if (changed) {
135 final int pl = getPaddingLeft();
136 final int pr = getPaddingRight();
137 mHandleBar.setBounds(pl, 0, getWidth() - pr, (int) mHandleBarHeight);
138 }
139 }
140
141 @Override
142 public void draw(Canvas canvas) {
143 super.draw(canvas);
144 final int off = (int) (getHeight() - mHandleBarHeight - getPaddingBottom());
145 canvas.translate(0, off);
146 mHandleBar.setState(mHandleView.getDrawableState());
147 mHandleBar.draw(canvas);
148 canvas.translate(0, -off);
149 }
Chris Wren64161cc2012-12-17 16:49:30 -0500150
151 @Override
152 public boolean onTouchEvent(MotionEvent event) {
153 if (DEBUG_GESTURES) {
154 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
155 EventLog.writeEvent(EventLogTags.SYSUI_QUICKPANEL_TOUCH,
156 event.getActionMasked(), (int) event.getX(), (int) event.getY());
157 }
158 }
159 return super.onTouchEvent(event);
160 }
Daniel Sandlercf591db2012-08-15 16:11:55 -0400161}