Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
| 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 Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Daniel Sandler | 1c1edaa | 2012-08-14 11:14:45 -0400 | [diff] [blame] | 20 | import android.content.res.Resources; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.util.AttributeSet; |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 22 | import android.util.EventLog; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 23 | import android.util.Log; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.view.MotionEvent; |
| 25 | import android.view.View; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 26 | import android.view.accessibility.AccessibilityEvent; |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 27 | |
| 28 | import com.android.systemui.EventLogTags; |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 29 | import com.android.systemui.R; |
| 30 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 31 | public class PhoneStatusBarView extends PanelBar { |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 32 | private static final String TAG = "PhoneStatusBarView"; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 33 | private static final boolean DEBUG = PhoneStatusBar.DEBUG; |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 34 | private static final boolean DEBUG_GESTURES = true; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 35 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 36 | PhoneStatusBar mBar; |
Daniel Sandler | 5a8aefa | 2012-09-25 01:21:12 -0400 | [diff] [blame] | 37 | |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 38 | PanelView mLastFullyOpenedPanel = null; |
John Spurlock | 5072883 | 2014-04-17 19:05:28 -0400 | [diff] [blame] | 39 | PanelView mNotificationPanel; |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 40 | private final PhoneStatusBarTransitions mBarTransitions; |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 41 | private ScrimController mScrimController; |
Joe Onorato | 119a401 | 2010-06-30 14:49:51 -0400 | [diff] [blame] | 42 | |
Joe Onorato | fd52b18 | 2010-11-10 18:00:52 -0800 | [diff] [blame] | 43 | public PhoneStatusBarView(Context context, AttributeSet attrs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | super(context, attrs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
Daniel Sandler | 1c1edaa | 2012-08-14 11:14:45 -0400 | [diff] [blame] | 46 | Resources res = getContext().getResources(); |
John Spurlock | 7edfbca | 2013-09-14 11:58:55 -0400 | [diff] [blame] | 47 | mBarTransitions = new PhoneStatusBarTransitions(this); |
John Spurlock | e932e30 | 2013-08-12 10:16:29 -0400 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | public BarTransitions getBarTransitions() { |
| 51 | return mBarTransitions; |
Daniel Sandler | 1c1edaa | 2012-08-14 11:14:45 -0400 | [diff] [blame] | 52 | } |
| 53 | |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 54 | public void setBar(PhoneStatusBar bar) { |
| 55 | mBar = bar; |
| 56 | } |
| 57 | |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 58 | public void setScrimController(ScrimController scrimController) { |
| 59 | mScrimController = scrimController; |
| 60 | } |
| 61 | |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 62 | @Override |
Jorim Jaggi | acea100 | 2014-05-10 01:30:10 +0200 | [diff] [blame] | 63 | public void onFinishInflate() { |
John Spurlock | e6f0a71 | 2013-09-03 16:23:49 -0400 | [diff] [blame] | 64 | mBarTransitions.init(); |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Daniel Sandler | 1c1edaa | 2012-08-14 11:14:45 -0400 | [diff] [blame] | 67 | @Override |
Daniel Sandler | cf591db | 2012-08-15 16:11:55 -0400 | [diff] [blame] | 68 | public void addPanel(PanelView pv) { |
| 69 | super.addPanel(pv); |
| 70 | if (pv.getId() == R.id.notification_panel) { |
| 71 | mNotificationPanel = pv; |
Daniel Sandler | cf591db | 2012-08-15 16:11:55 -0400 | [diff] [blame] | 72 | } |
| 73 | } |
| 74 | |
| 75 | @Override |
Daniel Sandler | 5050813 | 2012-08-16 14:10:53 -0400 | [diff] [blame] | 76 | public boolean panelsEnabled() { |
John Spurlock | 9764218 | 2013-07-29 17:58:39 -0400 | [diff] [blame] | 77 | return mBar.panelsEnabled(); |
Daniel Sandler | 1e8feef | 2012-08-16 11:37:41 -0400 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | @Override |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 81 | 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 Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 94 | |
| 95 | @Override |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 96 | public PanelView selectPanelForTouch(MotionEvent touch) { |
John Spurlock | 5072883 | 2014-04-17 19:05:28 -0400 | [diff] [blame] | 97 | // No double swiping. If either panel is open, nothing else can be pulled down. |
| 98 | return mNotificationPanel.getExpandedHeight() > 0 |
| 99 | ? null |
| 100 | : mNotificationPanel; |
Daniel Sandler | cf591db | 2012-08-15 16:11:55 -0400 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | @Override |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 104 | public void onPanelPeeked() { |
| 105 | super.onPanelPeeked(); |
Jorim Jaggi | fa505a7 | 2014-04-28 20:04:11 +0200 | [diff] [blame] | 106 | mBar.makeExpandedVisible(false); |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | @Override |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 110 | public void onAllPanelsCollapsed() { |
| 111 | super.onAllPanelsCollapsed(); |
Jorim Jaggi | 2580a976 | 2014-06-25 03:08:25 +0200 | [diff] [blame] | 112 | |
| 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 Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 120 | mLastFullyOpenedPanel = null; |
Daniel Sandler | 8e72c9e | 2012-08-15 00:09:26 -0400 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void onPanelFullyOpened(PanelView openPanel) { |
Daniel Sandler | 750bb9b | 2012-10-03 16:24:00 -0400 | [diff] [blame] | 125 | super.onPanelFullyOpened(openPanel); |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 126 | if (openPanel != mLastFullyOpenedPanel) { |
| 127 | openPanel.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 128 | } |
Casey Burkhardt | bac221f | 2012-10-03 18:13:58 -0700 | [diff] [blame] | 129 | mLastFullyOpenedPanel = openPanel; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public boolean onTouchEvent(MotionEvent event) { |
Chris Wren | 64161cc | 2012-12-17 16:49:30 -0500 | [diff] [blame] | 134 | 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 Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | @Override |
Jorim Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 148 | public void onTrackingStarted(PanelView panel) { |
| 149 | super.onTrackingStarted(panel); |
| 150 | mBar.onTrackingStarted(); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 151 | mScrimController.onTrackingStarted(); |
Jorim Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | @Override |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 155 | 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 Jaggi | e70d31f | 2014-04-24 22:08:30 +0200 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | @Override |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 167 | public boolean onInterceptTouchEvent(MotionEvent event) { |
| 168 | return mBar.interceptTouchEvent(event) || super.onInterceptTouchEvent(event); |
| 169 | } |
| 170 | |
| 171 | @Override |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 172 | public void panelExpansionChanged(PanelView panel, float frac, boolean expanded) { |
| 173 | super.panelExpansionChanged(panel, frac, expanded); |
Jorim Jaggi | ecc798e | 2014-05-26 18:14:37 +0200 | [diff] [blame] | 174 | mScrimController.setPanelExpansion(frac); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 175 | mBar.updateCarrierLabelVisibility(false); |
Jorim Jaggi | 03c701e | 2014-04-02 12:39:51 +0200 | [diff] [blame] | 176 | mBar.userActivity(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 177 | } |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 178 | } |