blob: 103a582ff8f41f7a08800f979f3492d1d4b78663 [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;
John Spurlockcd686b52013-06-05 10:13:46 -040023import android.util.Log;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.view.MotionEvent;
25import android.view.View;
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070026import android.view.accessibility.AccessibilityEvent;
Chris Wren64161cc2012-12-17 16:49:30 -050027
28import com.android.systemui.EventLogTags;
Joe Onorato79de0c52010-05-26 17:03:26 -040029import com.android.systemui.R;
30
Daniel Sandler08d05e32012-08-08 16:39:54 -040031public class PhoneStatusBarView extends PanelBar {
Joe Onoratofd52b182010-11-10 18:00:52 -080032 private static final String TAG = "PhoneStatusBarView";
Daniel Sandler198a0302012-08-17 16:04:31 -040033 private static final boolean DEBUG = PhoneStatusBar.DEBUG;
Chris Wren64161cc2012-12-17 16:49:30 -050034 private static final boolean DEBUG_GESTURES = true;
Daniel Sandler198a0302012-08-17 16:04:31 -040035
Daniel Sandler08d05e32012-08-08 16:39:54 -040036 PhoneStatusBar mBar;
Daniel Sandler5a8aefa2012-09-25 01:21:12 -040037
Casey Burkhardtbac221f2012-10-03 18:13:58 -070038 PanelView mLastFullyOpenedPanel = null;
John Spurlock50728832014-04-17 19:05:28 -040039 PanelView mNotificationPanel;
John Spurlock7edfbca2013-09-14 11:58:55 -040040 private final PhoneStatusBarTransitions mBarTransitions;
Jorim Jaggiecc798e2014-05-26 18:14:37 +020041 private ScrimController mScrimController;
Joe Onorato119a4012010-06-30 14:49:51 -040042
Joe Onoratofd52b182010-11-10 18:00:52 -080043 public PhoneStatusBarView(Context context, AttributeSet attrs) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 super(context, attrs);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080045
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040046 Resources res = getContext().getResources();
John Spurlock7edfbca2013-09-14 11:58:55 -040047 mBarTransitions = new PhoneStatusBarTransitions(this);
John Spurlocke932e302013-08-12 10:16:29 -040048 }
49
50 public BarTransitions getBarTransitions() {
51 return mBarTransitions;
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040052 }
53
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070054 public void setBar(PhoneStatusBar bar) {
55 mBar = bar;
56 }
57
Jorim Jaggiecc798e2014-05-26 18:14:37 +020058 public void setScrimController(ScrimController scrimController) {
59 mScrimController = scrimController;
60 }
61
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070062 @Override
Jorim Jaggiacea1002014-05-10 01:30:10 +020063 public void onFinishInflate() {
John Spurlocke6f0a712013-09-03 16:23:49 -040064 mBarTransitions.init();
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070065 }
66
Daniel Sandler1c1edaa2012-08-14 11:14:45 -040067 @Override
Daniel Sandlercf591db2012-08-15 16:11:55 -040068 public void addPanel(PanelView pv) {
69 super.addPanel(pv);
70 if (pv.getId() == R.id.notification_panel) {
71 mNotificationPanel = pv;
Daniel Sandlercf591db2012-08-15 16:11:55 -040072 }
73 }
74
75 @Override
Daniel Sandler50508132012-08-16 14:10:53 -040076 public boolean panelsEnabled() {
John Spurlock97642182013-07-29 17:58:39 -040077 return mBar.panelsEnabled();
Daniel Sandler1e8feef2012-08-16 11:37:41 -040078 }
79
80 @Override
Svetoslav Ganov6179ea32011-06-28 01:12:41 -070081 public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) {
82 if (super.onRequestSendAccessibilityEvent(child, event)) {
83 // The status bar is very small so augment the view that the user is touching
84 // with the content of the status bar a whole. This way an accessibility service
85 // may announce the current item as well as the entire content if appropriate.
86 AccessibilityEvent record = AccessibilityEvent.obtain();
87 onInitializeAccessibilityEvent(record);
88 dispatchPopulateAccessibilityEvent(record);
89 event.appendRecord(record);
90 return true;
91 }
92 return false;
93 }
Daniel Sandler08d05e32012-08-08 16:39:54 -040094
95 @Override
Daniel Sandlerefb0faf2012-10-10 14:15:34 -070096 public PanelView selectPanelForTouch(MotionEvent touch) {
John Spurlock50728832014-04-17 19:05:28 -040097 // No double swiping. If either panel is open, nothing else can be pulled down.
98 return mNotificationPanel.getExpandedHeight() > 0
99 ? null
100 : mNotificationPanel;
Daniel Sandlercf591db2012-08-15 16:11:55 -0400101 }
102
103 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400104 public void onPanelPeeked() {
105 super.onPanelPeeked();
Jorim Jaggifa505a72014-04-28 20:04:11 +0200106 mBar.makeExpandedVisible(false);
Daniel Sandler67eab792012-10-02 17:08:23 -0400107 }
108
109 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400110 public void onAllPanelsCollapsed() {
111 super.onAllPanelsCollapsed();
Jorim Jaggi2580a9762014-06-25 03:08:25 +0200112
113 // Close the status bar in the next frame so we can show the end of the animation.
114 postOnAnimation(new Runnable() {
115 @Override
116 public void run() {
117 mBar.makeExpandedInvisible();
118 }
119 });
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700120 mLastFullyOpenedPanel = null;
Daniel Sandler8e72c9e2012-08-15 00:09:26 -0400121 }
122
123 @Override
124 public void onPanelFullyOpened(PanelView openPanel) {
Daniel Sandler750bb9b2012-10-03 16:24:00 -0400125 super.onPanelFullyOpened(openPanel);
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700126 if (openPanel != mLastFullyOpenedPanel) {
127 openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED);
128 }
Casey Burkhardtbac221f2012-10-03 18:13:58 -0700129 mLastFullyOpenedPanel = openPanel;
Daniel Sandler08d05e32012-08-08 16:39:54 -0400130 }
131
132 @Override
133 public boolean onTouchEvent(MotionEvent event) {
Chris Wren64161cc2012-12-17 16:49:30 -0500134 boolean barConsumedEvent = mBar.interceptTouchEvent(event);
135
136 if (DEBUG_GESTURES) {
137 if (event.getActionMasked() != MotionEvent.ACTION_MOVE) {
138 EventLog.writeEvent(EventLogTags.SYSUI_PANELBAR_TOUCH,
139 event.getActionMasked(), (int) event.getX(), (int) event.getY(),
140 barConsumedEvent ? 1 : 0);
141 }
142 }
143
144 return barConsumedEvent || super.onTouchEvent(event);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400145 }
146
147 @Override
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200148 public void onTrackingStarted(PanelView panel) {
149 super.onTrackingStarted(panel);
150 mBar.onTrackingStarted();
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200151 mScrimController.onTrackingStarted();
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200152 }
153
154 @Override
Jorim Jaggi2fbad7b2014-05-26 22:38:00 +0200155 public void onTrackingStopped(PanelView panel, boolean expand) {
156 super.onTrackingStopped(panel, expand);
157 mBar.onTrackingStopped(expand);
158 }
159
160 @Override
161 public void onExpandingFinished() {
162 super.onExpandingFinished();
163 mScrimController.onExpandingFinished();
Jorim Jaggie70d31f2014-04-24 22:08:30 +0200164 }
165
166 @Override
Daniel Sandler08d05e32012-08-08 16:39:54 -0400167 public boolean onInterceptTouchEvent(MotionEvent event) {
168 return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event);
169 }
170
171 @Override
Jorim Jaggib472b3472014-06-30 19:56:24 +0200172 public void panelExpansionChanged(PanelView panel, float frac, boolean expanded) {
173 super.panelExpansionChanged(panel, frac, expanded);
Jorim Jaggiecc798e2014-05-26 18:14:37 +0200174 mScrimController.setPanelExpansion(frac);
Daniel Sandler08d05e32012-08-08 16:39:54 -0400175 mBar.updateCarrierLabelVisibility(false);
Jorim Jaggi03c701e2014-04-02 12:39:51 +0200176 mBar.userActivity();
Daniel Sandler08d05e32012-08-08 16:39:54 -0400177 }
Svetoslav Ganov6179ea32011-06-28 01:12:41 -0700178}