blob: e4eae38fcdcdc80b10278febbb6f5a6329f5a617 [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
19import android.content.Context;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040020import android.content.res.Resources;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080021import android.util.AttributeSet;
Chris Wren64161cc2012-12-17 16:49:30 -050022import android.util.EventLog;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.view.MotionEvent;
24import android.view.View;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070025import android.view.accessibility.AccessibilityEvent;
Chris Wren64161cc2012-12-17 16:49:30 -050026
27import com.android.systemui.EventLogTags;
Joe Onorato79de0c52010-05-26 17:03:26 -040028import com.android.systemui.R;
29
Daniel Sandler08d05e32012-08-08 16:39:54 -040030public class PhoneStatusBarView extends PanelBar {
Joe Onoratofd52b182010-11-10 18:00:52 -080031 private static final String TAG = "PhoneStatusBarView";
Daniel Sandler198a0302012-08-17 16:04:31 -040032 private static final boolean DEBUG = PhoneStatusBar.DEBUG;
Chris Wren64161cc2012-12-17 16:49:30 -050033 private static final boolean DEBUG_GESTURES = true;
Daniel Sandler198a0302012-08-17 16:04:31 -040034
Daniel Sandler08d05e32012-08-08 16:39:54 -040035 PhoneStatusBar mBar;
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040036
Casey Burkhardtbac221f2012-10-03 18:13:58 -070037 PanelView mLastFullyOpenedPanel = null;
John Spurlock50728832014-04-17 19:05:28 -040038 PanelView mNotificationPanel;
John Spurlock7edfbca2013-09-14 11:58:55 -040039 private final PhoneStatusBarTransitions mBarTransitions;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020040 private ScrimController mScrimController;
Joe Onorato119a4012010-06-30 14:49:51 -040041
Joe Onoratofd52b182010-11-10 18:00:52 -080042 public PhoneStatusBarView(Context context, AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080043 super(context, attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040045 Resources res = getContext().getResources();
John Spurlock7edfbca2013-09-14 11:58:55 -040046 mBarTransitions = new PhoneStatusBarTransitions(this);
John Spurlocke932e302013-08-12 10:16:29 -040047 }
48
49 public BarTransitions getBarTransitions() {
50 return mBarTransitions;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040051 }
52
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070053 public void setBar(PhoneStatusBar bar) {
54 mBar = bar;
55 }
56
Jorim Jaggiecc798e2014-05-26 18:14:37 +020057 public void setScrimController(ScrimController scrimController) {
58 mScrimController = scrimController;
59 }
60
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070061 @Override
Jorim Jaggiacea1002014-05-10 01:30:10 +020062 public void onFinishInflate() {
John Spurlocke6f0a712013-09-03 16:23:49 -040063 mBarTransitions.init();
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070064 }
65
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040066 @Override
Daniel Sandlercf591db2012-08-15 16:11:55 -040067 public void addPanel(PanelView pv) {
68 super.addPanel(pv);
69 if (pv.getId() == R.id.notification_panel) {
70 mNotificationPanel = pv;
Daniel Sandlercf591db2012-08-15 16:11:55 -040071 }
72 }
73
74 @Override
Daniel Sandler50508132012-08-16 14:10:53 -040075 public boolean panelsEnabled() {
John Spurlock97642182013-07-29 17:58:39 -040076 return mBar.panelsEnabled();
Daniel Sandler1e8feef2012-08-16 11:37:41 -040077 }
78
79 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070080 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
81 if (super.onRequestSendAccessibilityEvent(child, event)) {
82 // The status bar is very small so augment the view that the user is touching
83 // with the content of the status bar a whole. This way an accessibility service
84 // may announce the current item as well as the entire content if appropriate.
85 AccessibilityEvent record = AccessibilityEvent.obtain();
86 onInitializeAccessibilityEvent(record);
87 dispatchPopulateAccessibilityEvent(record);
88 event.appendRecord(record);
89 return true;
90 }
91 return false;
92 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040093
94 @Override
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070095 public PanelView selectPanelForTouch(MotionEvent touch) {
John Spurlock50728832014-04-17 19:05:28 -040096 // No double swiping. If either panel is open, nothing else can be pulled down.
97 return mNotificationPanel.getExpandedHeight() > 0
98 ? null
99 : mNotificationPanel;
Daniel Sandlercf591db2012-08-15 16:11:55 -0400100 }
101
102 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400103 public void onPanelPeeked() {
104 super.onPanelPeeked();
Jorim Jaggifa505a72014-04-28 20:04:11 +0200105 mBar.makeExpandedVisible(false);
Daniel Sandler67eab792012-10-02 17:08:23 -0400106 }
107
108 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400109 public void onAllPanelsCollapsed() {
110 super.onAllPanelsCollapsed();
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200111
112 // Close the status bar in the next frame so we can show the end of the animation.
113 postOnAnimation(new Runnable() {
114 @Override
115 public void run() {
116 mBar.makeExpandedInvisible();
117 }
118 });
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700119 mLastFullyOpenedPanel = null;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400120 }
121
122 @Override
123 public void onPanelFullyOpened(PanelView openPanel) {
Daniel Sandler750bb9b2012-10-03 16:24:00 -0400124 super.onPanelFullyOpened(openPanel);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700125 if (openPanel != mLastFullyOpenedPanel) {
126 openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
127 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700128 mLastFullyOpenedPanel = openPanel;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400129 }
130
131 @Override
132 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -0500133 boolean barConsumedEvent = mBar.interceptTouchEvent(event);
134
135 if (DEBUG_GESTURES) {
136 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
137 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
138 event.getActionMasked(), (int) event.getX(), (int) event.getY(),
139 barConsumedEvent ? 1 : 0);
140 }
141 }
142
143 return barConsumedEvent || super.onTouchEvent(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400144 }
145
146 @Override
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200147 public void onTrackingStarted(PanelView panel) {
148 super.onTrackingStarted(panel);
149 mBar.onTrackingStarted();
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200150 mScrimController.onTrackingStarted();
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200151 }
152
153 @Override
Selim Cinekdbbcfbe2014-10-24 17:52:35 +0200154 public void onClosingFinished() {
155 super.onClosingFinished();
156 mBar.onClosingFinished();
157 }
158
159 @Override
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200160 public void onTrackingStopped(PanelView panel, boolean expand) {
161 super.onTrackingStopped(panel, expand);
162 mBar.onTrackingStopped(expand);
163 }
164
165 @Override
166 public void onExpandingFinished() {
167 super.onExpandingFinished();
168 mScrimController.onExpandingFinished();
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200169 }
170
171 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400172 public boolean onInterceptTouchEvent(MotionEvent event) {
173 return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
174 }
175
176 @Override
Jorim Jaggib472b3472014-06-30 19:56:24 +0200177 public void panelExpansionChanged(PanelView panel, float frac, boolean expanded) {
178 super.panelExpansionChanged(panel, frac, expanded);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200179 mScrimController.setPanelExpansion(frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400180 mBar.updateCarrierLabelVisibility(false);
181 }
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700182}