blob: de9f7506dd1d0985eda34fa351515898ad278a00 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
2 * Copyright (C) 2008 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
Joe Onoratofd52b182010-11-10 18:00:52 -080017package com.android.systemui.statusbar.phone;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Daniel Sandler08d05e32012-08-08 16:39:54 -040019import android.app.ActivityManager;
Daniel Sandler1e8feef2012-08-16 11:37:41 -040020import android.app.StatusBarManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.content.Context;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040022import android.content.res.Resources;
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040023import android.content.res.Resources.NotFoundException;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.util.AttributeSet;
Chris Wren64161cc2012-12-17 16:49:30 -050025import android.util.EventLog;
Daniel Sandler198a0302012-08-17 16:04:31 -040026import android.util.Slog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.view.MotionEvent;
28import android.view.View;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070029import android.view.accessibility.AccessibilityEvent;
Chris Wren64161cc2012-12-17 16:49:30 -050030
31import com.android.systemui.EventLogTags;
Joe Onorato79de0c52010-05-26 17:03:26 -040032import com.android.systemui.R;
33
Daniel Sandler08d05e32012-08-08 16:39:54 -040034public class PhoneStatusBarView extends PanelBar {
Joe Onoratofd52b182010-11-10 18:00:52 -080035 private static final String TAG = "PhoneStatusBarView";
Daniel Sandler198a0302012-08-17 16:04:31 -040036 private static final boolean DEBUG = PhoneStatusBar.DEBUG;
Chris Wren64161cc2012-12-17 16:49:30 -050037 private static final boolean DEBUG_GESTURES = true;
Daniel Sandler198a0302012-08-17 16:04:31 -040038
Daniel Sandler08d05e32012-08-08 16:39:54 -040039 PhoneStatusBar mBar;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040040 int mScrimColor;
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040041 float mSettingsPanelDragzoneFrac;
42 float mSettingsPanelDragzoneMin;
43
Chris Wrenb8ea2f52012-08-24 11:50:55 -040044 boolean mFullWidthNotifications;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -040045 PanelView mFadingPanel = null;
Casey Burkhardtbac221f2012-10-03 18:13:58 -070046 PanelView mLastFullyOpenedPanel = null;
Daniel Sandlercf591db2012-08-15 16:11:55 -040047 PanelView mNotificationPanel, mSettingsPanel;
Daniel Sandler67eab792012-10-02 17:08:23 -040048 private boolean mShouldFade;
Joe Onorato119a4012010-06-30 14:49:51 -040049
Joe Onoratofd52b182010-11-10 18:00:52 -080050 public PhoneStatusBarView(Context context, AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080051 super(context, attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080052
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040053 Resources res = getContext().getResources();
54 mScrimColor = res.getColor(R.color.notification_panel_scrim_color);
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040055 mSettingsPanelDragzoneMin = res.getDimension(R.dimen.settings_panel_dragzone_min);
Chris Wrenb8ea2f52012-08-24 11:50:55 -040056 try {
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040057 mSettingsPanelDragzoneFrac = res.getFraction(R.dimen.settings_panel_dragzone_fraction, 1, 1);
58 } catch (NotFoundException ex) {
59 mSettingsPanelDragzoneFrac = 0f;
Chris Wrenb8ea2f52012-08-24 11:50:55 -040060 }
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040061 mFullWidthNotifications = mSettingsPanelDragzoneFrac <= 0f;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040062 }
63
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070064 public void setBar(PhoneStatusBar bar) {
65 mBar = bar;
66 }
67
68 public boolean hasFullWidthNotifications() {
69 return mFullWidthNotifications;
70 }
71
72 @Override
73 public void onAttachedToWindow() {
74 for (PanelView pv : mPanels) {
75 pv.setRubberbandingEnabled(!mFullWidthNotifications);
76 }
77 }
78
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040079 @Override
Daniel Sandlercf591db2012-08-15 16:11:55 -040080 public void addPanel(PanelView pv) {
81 super.addPanel(pv);
82 if (pv.getId() == R.id.notification_panel) {
83 mNotificationPanel = pv;
84 } else if (pv.getId() == R.id.settings_panel){
85 mSettingsPanel = pv;
86 }
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070087 pv.setRubberbandingEnabled(!mFullWidthNotifications);
Daniel Sandlercf591db2012-08-15 16:11:55 -040088 }
89
90 @Override
Daniel Sandler50508132012-08-16 14:10:53 -040091 public boolean panelsEnabled() {
Daniel Sandler1e8feef2012-08-16 11:37:41 -040092 return ((mBar.mDisabled & StatusBarManager.DISABLE_EXPAND) == 0);
93 }
94
95 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070096 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
97 if (super.onRequestSendAccessibilityEvent(child, event)) {
98 // The status bar is very small so augment the view that the user is touching
99 // with the content of the status bar a whole. This way an accessibility service
100 // may announce the current item as well as the entire content if appropriate.
101 AccessibilityEvent record = AccessibilityEvent.obtain();
102 onInitializeAccessibilityEvent(record);
103 dispatchPopulateAccessibilityEvent(record);
104 event.appendRecord(record);
105 return true;
106 }
107 return false;
108 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400109
110 @Override
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700111 public PanelView selectPanelForTouch(MotionEvent touch) {
112 final float x = touch.getX();
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700113 final boolean isLayoutRtl = isLayoutRtl();
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700114
Daniel Sandler5a8aefa2012-09-25 01:21:12 -0400115 if (mFullWidthNotifications) {
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700116 // No double swiping. If either panel is open, nothing else can be pulled down.
Daniel Sandlere111ad32012-10-13 15:17:45 -0400117 return ((mSettingsPanel == null ? 0 : mSettingsPanel.getExpandedHeight())
118 + mNotificationPanel.getExpandedHeight() > 0)
Daniel Sandlerefb0faf2012-10-10 14:15:34 -0700119 ? null
120 : mNotificationPanel;
Daniel Sandler5a8aefa2012-09-25 01:21:12 -0400121 }
122
123 // We split the status bar into thirds: the left 2/3 are for notifications, and the
Daniel Sandlercf591db2012-08-15 16:11:55 -0400124 // right 1/3 for quick settings. If you pull the status bar down a second time you'll
125 // toggle panels no matter where you pull it down.
Daniel Sandler5a8aefa2012-09-25 01:21:12 -0400126
Daniel Sandler67eab792012-10-02 17:08:23 -0400127 final float w = getMeasuredWidth();
Daniel Sandler5a8aefa2012-09-25 01:21:12 -0400128 float region = (w * mSettingsPanelDragzoneFrac);
129
130 if (DEBUG) {
131 Slog.v(TAG, String.format(
132 "w=%.1f frac=%.3f region=%.1f min=%.1f x=%.1f w-x=%.1f",
133 w, mSettingsPanelDragzoneFrac, region, mSettingsPanelDragzoneMin, x, (w-x)));
Daniel Sandlercf591db2012-08-15 16:11:55 -0400134 }
Daniel Sandler5a8aefa2012-09-25 01:21:12 -0400135
136 if (region < mSettingsPanelDragzoneMin) region = mSettingsPanelDragzoneMin;
137
Fabrice Di Meglio8afcd142012-07-27 18:27:11 -0700138 final boolean showSettings = isLayoutRtl ? (x < region) : (w - region < x);
139 return showSettings ? mSettingsPanel : mNotificationPanel;
Daniel Sandlercf591db2012-08-15 16:11:55 -0400140 }
141
142 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400143 public void onPanelPeeked() {
144 super.onPanelPeeked();
145 mBar.makeExpandedVisible(true);
Daniel Sandler67eab792012-10-02 17:08:23 -0400146 }
147
148 @Override
149 public void startOpeningPanel(PanelView panel) {
150 super.startOpeningPanel(panel);
151 // we only want to start fading if this is the "first" or "last" panel,
152 // which is kind of tricky to determine
153 mShouldFade = (mFadingPanel == null || mFadingPanel.isFullyExpanded());
154 if (DEBUG) {
155 Slog.v(TAG, "start opening: " + panel + " shouldfade=" + mShouldFade);
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400156 }
Daniel Sandler67eab792012-10-02 17:08:23 -0400157 mFadingPanel = panel;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400158 }
159
160 @Override
161 public void onAllPanelsCollapsed() {
162 super.onAllPanelsCollapsed();
Daniel Sandler6e2810b2012-10-17 09:40:09 -0400163 // give animations time to settle
164 mBar.makeExpandedInvisibleSoon();
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400165 mFadingPanel = null;
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700166 mLastFullyOpenedPanel = null;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400167 }
168
169 @Override
170 public void onPanelFullyOpened(PanelView openPanel) {
Daniel Sandler750bb9b2012-10-03 16:24:00 -0400171 super.onPanelFullyOpened(openPanel);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700172 if (openPanel != mLastFullyOpenedPanel) {
173 openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
174 }
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400175 mFadingPanel = openPanel;
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700176 mLastFullyOpenedPanel = openPanel;
Daniel Sandler67eab792012-10-02 17:08:23 -0400177 mShouldFade = true; // now you own the fade, mister
Daniel Sandler08d05e32012-08-08 16:39:54 -0400178 }
179
180 @Override
181 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -0500182 boolean barConsumedEvent = mBar.interceptTouchEvent(event);
183
184 if (DEBUG_GESTURES) {
185 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
186 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
187 event.getActionMasked(), (int) event.getX(), (int) event.getY(),
188 barConsumedEvent ? 1 : 0);
189 }
190 }
191
192 return barConsumedEvent || super.onTouchEvent(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400193 }
194
195 @Override
196 public boolean onInterceptTouchEvent(MotionEvent event) {
197 return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
198 }
199
200 @Override
Daniel Sandler67eab792012-10-02 17:08:23 -0400201 public void panelExpansionChanged(PanelView panel, float frac) {
202 super.panelExpansionChanged(panel, frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400203
Daniel Sandler198a0302012-08-17 16:04:31 -0400204 if (DEBUG) {
205 Slog.v(TAG, "panelExpansionChanged: f=" + frac);
206 }
207
Daniel Sandler67eab792012-10-02 17:08:23 -0400208 if (panel == mFadingPanel && mScrimColor != 0 && ActivityManager.isHighEndGfx()) {
209 if (mShouldFade) {
210 frac = mPanelExpandedFractionSum; // don't judge me
Daniel Sandler3679bf52012-10-16 21:30:28 -0400211 // let's start this 20% of the way down the screen
212 frac = frac * 1.2f - 0.2f;
213 if (frac <= 0) {
214 mBar.mStatusBarWindow.setBackgroundColor(0);
215 } else {
216 // woo, special effects
217 final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f))));
218 // attenuate background color alpha by k
219 final int color = (int) ((mScrimColor >>> 24) * k) << 24 | (mScrimColor & 0xFFFFFF);
220 mBar.mStatusBarWindow.setBackgroundColor(color);
221 }
Daniel Sandler67eab792012-10-02 17:08:23 -0400222 }
Daniel Sandler08d05e32012-08-08 16:39:54 -0400223 }
224
Daniel Sandler025e7cb2012-10-17 10:15:37 -0400225 // fade out the panel as it gets buried into the status bar to avoid overdrawing the
226 // status bar on the last frame of a close animation
227 final int H = mBar.getStatusBarHeight();
228 final float ph = panel.getExpandedHeight() + panel.getPaddingBottom();
229 float alpha = 1f;
230 if (ph < 2*H) {
231 if (ph < H) alpha = 0f;
232 else alpha = (ph - H) / H;
233 alpha = alpha * alpha; // get there faster
234 }
235 if (panel.getAlpha() != alpha) {
236 panel.setAlpha(alpha);
237 }
238
Daniel Sandler08d05e32012-08-08 16:39:54 -0400239 mBar.updateCarrierLabelVisibility(false);
240 }
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700241}