Daniel Sandler | 50a5313 | 2012-10-24 15:02:27 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 19 | import android.content.Context; |
felkachang | 0857955 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 20 | import android.os.Bundle; |
| 21 | import android.os.Parcelable; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 22 | import android.util.AttributeSet; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 23 | import android.util.Log; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 24 | import android.view.MotionEvent; |
Daniel Sandler | 173bae2 | 2012-09-25 14:37:42 -0400 | [diff] [blame] | 25 | import android.view.View; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 26 | import android.widget.FrameLayout; |
| 27 | |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 28 | public abstract class PanelBar extends FrameLayout { |
Daniel Sandler | bf4aa9d | 2012-08-15 10:49:28 -0400 | [diff] [blame] | 29 | public static final boolean DEBUG = false; |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 30 | public static final String TAG = PanelBar.class.getSimpleName(); |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 31 | private static final boolean SPEW = false; |
felkachang | 0857955 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 32 | private static final String PANEL_BAR_SUPER_PARCELABLE = "panel_bar_super_parcelable"; |
| 33 | private static final String STATE = "state"; |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 34 | private boolean mBouncerShowing; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 35 | private boolean mExpanded; |
Lucas Dupin | 95951a3 | 2018-06-21 11:41:34 -0700 | [diff] [blame] | 36 | protected float mPanelFraction; |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 37 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 38 | public static final void LOG(String fmt, Object... args) { |
| 39 | if (!DEBUG) return; |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 40 | Log.v(TAG, String.format(fmt, args)); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 41 | } |
| 42 | |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 43 | public static final int STATE_CLOSED = 0; |
| 44 | public static final int STATE_OPENING = 1; |
| 45 | public static final int STATE_OPEN = 2; |
| 46 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 47 | PanelView mPanel; |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 48 | private int mState = STATE_CLOSED; |
| 49 | private boolean mTracking; |
| 50 | |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 51 | public void go(int state) { |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 52 | if (DEBUG) LOG("go state: %d -> %d", mState, state); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 53 | mState = state; |
| 54 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 55 | |
felkachang | 0857955 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 56 | @Override |
| 57 | protected Parcelable onSaveInstanceState() { |
| 58 | Bundle bundle = new Bundle(); |
| 59 | bundle.putParcelable(PANEL_BAR_SUPER_PARCELABLE, super.onSaveInstanceState()); |
| 60 | bundle.putInt(STATE, mState); |
| 61 | return bundle; |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | protected void onRestoreInstanceState(Parcelable state) { |
| 66 | if (state == null || !(state instanceof Bundle)) { |
| 67 | super.onRestoreInstanceState(state); |
| 68 | return; |
| 69 | } |
| 70 | |
| 71 | Bundle bundle = (Bundle) state; |
| 72 | super.onRestoreInstanceState(bundle.getParcelable(PANEL_BAR_SUPER_PARCELABLE)); |
| 73 | if (((Bundle) state).containsKey(STATE)) { |
| 74 | go(bundle.getInt(STATE, STATE_CLOSED)); |
| 75 | } |
Jason Monk | 0a7d9f2 | 2017-03-15 11:03:06 -0400 | [diff] [blame] | 76 | } |
| 77 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 78 | public PanelBar(Context context, AttributeSet attrs) { |
| 79 | super(context, attrs); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | protected void onFinishInflate() { |
| 84 | super.onFinishInflate(); |
| 85 | } |
| 86 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 87 | public void setPanel(PanelView pv) { |
| 88 | mPanel = pv; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 89 | pv.setBar(this); |
| 90 | } |
| 91 | |
Adrian Roos | d0b2f7d | 2015-04-29 13:36:12 -0700 | [diff] [blame] | 92 | public void setBouncerShowing(boolean showing) { |
Lucas Dupin | bc9aac1 | 2018-03-04 20:18:15 -0800 | [diff] [blame] | 93 | mBouncerShowing = showing; |
Adrian Roos | 3531a95 | 2015-06-10 13:19:17 -0700 | [diff] [blame] | 94 | int important = showing ? IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS |
| 95 | : IMPORTANT_FOR_ACCESSIBILITY_AUTO; |
| 96 | |
| 97 | setImportantForAccessibility(important); |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 98 | updateVisibility(); |
Adrian Roos | 3531a95 | 2015-06-10 13:19:17 -0700 | [diff] [blame] | 99 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 100 | if (mPanel != null) mPanel.setImportantForAccessibility(important); |
Adrian Roos | d0b2f7d | 2015-04-29 13:36:12 -0700 | [diff] [blame] | 101 | } |
| 102 | |
Lucas Dupin | 95951a3 | 2018-06-21 11:41:34 -0700 | [diff] [blame] | 103 | public float getExpansionFraction() { |
| 104 | return mPanelFraction; |
| 105 | } |
| 106 | |
| 107 | public boolean isExpanded() { |
| 108 | return mExpanded; |
| 109 | } |
| 110 | |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 111 | private void updateVisibility() { |
| 112 | mPanel.setVisibility(mExpanded || mBouncerShowing ? VISIBLE : INVISIBLE); |
| 113 | } |
| 114 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 115 | public boolean panelEnabled() { |
Daniel Sandler | 1e8feef | 2012-08-16 11:37:41 -0400 | [diff] [blame] | 116 | return true; |
| 117 | } |
| 118 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 119 | @Override |
| 120 | public boolean onTouchEvent(MotionEvent event) { |
Daniel Sandler | 1e8feef | 2012-08-16 11:37:41 -0400 | [diff] [blame] | 121 | // Allow subclasses to implement enable/disable semantics |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 122 | if (!panelEnabled()) { |
Daniel Sandler | 2b99a49 | 2013-02-05 13:05:44 -0500 | [diff] [blame] | 123 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 124 | Log.v(TAG, String.format("onTouch: all panels disabled, ignoring touch at (%d,%d)", |
Daniel Sandler | 2b99a49 | 2013-02-05 13:05:44 -0500 | [diff] [blame] | 125 | (int) event.getX(), (int) event.getY())); |
| 126 | } |
| 127 | return false; |
| 128 | } |
Daniel Sandler | 1e8feef | 2012-08-16 11:37:41 -0400 | [diff] [blame] | 129 | |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 130 | if (event.getAction() == MotionEvent.ACTION_DOWN) { |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 131 | final PanelView panel = mPanel; |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 132 | if (panel == null) { |
| 133 | // panel is not there, so we'll eat the gesture |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 134 | Log.v(TAG, String.format("onTouch: no panel for touch at (%d,%d)", |
Daniel Sandler | 2b99a49 | 2013-02-05 13:05:44 -0500 | [diff] [blame] | 135 | (int) event.getX(), (int) event.getY())); |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 136 | return true; |
| 137 | } |
John Spurlock | 919adac | 2012-10-02 16:41:12 -0400 | [diff] [blame] | 138 | boolean enabled = panel.isEnabled(); |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 139 | if (DEBUG) LOG("PanelBar.onTouch: state=%d ACTION_DOWN: panel %s %s", mState, panel, |
John Spurlock | 919adac | 2012-10-02 16:41:12 -0400 | [diff] [blame] | 140 | (enabled ? "" : " (disabled)")); |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 141 | if (!enabled) { |
| 142 | // panel is disabled, so we'll eat the gesture |
John Spurlock | cd686b5 | 2013-06-05 10:13:46 -0400 | [diff] [blame] | 143 | Log.v(TAG, String.format( |
Daniel Sandler | 2b99a49 | 2013-02-05 13:05:44 -0500 | [diff] [blame] | 144 | "onTouch: panel (%s) is disabled, ignoring touch at (%d,%d)", |
| 145 | panel, (int) event.getX(), (int) event.getY())); |
Daniel Sandler | efb0faf | 2012-10-10 14:15:34 -0700 | [diff] [blame] | 146 | return true; |
| 147 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 148 | } |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 149 | return mPanel == null || mPanel.onTouchEvent(event); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 150 | } |
| 151 | |
Selim Cinek | 3d395c6 | 2015-06-16 19:37:37 -0700 | [diff] [blame] | 152 | public abstract void panelScrimMinFractionChanged(float minFraction); |
| 153 | |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 154 | /** |
Jorim Jaggi | b472b347 | 2014-06-30 19:56:24 +0200 | [diff] [blame] | 155 | * @param frac the fraction from the expansion in [0, 1] |
| 156 | * @param expanded whether the panel is currently expanded; this is independent from the |
| 157 | * fraction as the panel also might be expanded if the fraction is 0 |
| 158 | */ |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 159 | public void panelExpansionChanged(float frac, boolean expanded) { |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 160 | boolean fullyClosed = true; |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 161 | boolean fullyOpened = false; |
| 162 | if (SPEW) LOG("panelExpansionChanged: start state=%d", mState); |
| 163 | PanelView pv = mPanel; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 164 | mExpanded = expanded; |
Lucas Dupin | 95951a3 | 2018-06-21 11:41:34 -0700 | [diff] [blame] | 165 | mPanelFraction = frac; |
Lucas Dupin | 3d565fa | 2018-03-20 15:40:14 -0700 | [diff] [blame] | 166 | updateVisibility(); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 167 | // adjust any other panels that may be partially visible |
| 168 | if (expanded) { |
| 169 | if (mState == STATE_CLOSED) { |
| 170 | go(STATE_OPENING); |
| 171 | onPanelPeeked(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 172 | } |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 173 | fullyClosed = false; |
| 174 | final float thisFrac = pv.getExpandedFraction(); |
| 175 | if (SPEW) LOG("panelExpansionChanged: -> %s: f=%.1f", pv.getName(), thisFrac); |
| 176 | fullyOpened = thisFrac >= 1f; |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 177 | } |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 178 | if (fullyOpened && !mTracking) { |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 179 | go(STATE_OPEN); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 180 | onPanelFullyOpened(); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 181 | } else if (fullyClosed && !mTracking && mState != STATE_CLOSED) { |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 182 | go(STATE_CLOSED); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 183 | onPanelCollapsed(); |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 184 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 185 | |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 186 | if (SPEW) LOG("panelExpansionChanged: end state=%d [%s%s ]", mState, |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 187 | fullyOpened?" fullyOpened":"", fullyClosed?" fullyClosed":""); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 188 | } |
| 189 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 190 | public void collapsePanel(boolean animate, boolean delayed, float speedUpFactor) { |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 191 | boolean waiting = false; |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 192 | PanelView pv = mPanel; |
| 193 | if (animate && !pv.isFullyCollapsed()) { |
| 194 | pv.collapse(delayed, speedUpFactor); |
| 195 | waiting = true; |
| 196 | } else { |
| 197 | pv.resetViews(); |
| 198 | pv.setExpandedFraction(0); // just in case |
| 199 | pv.cancelPeek(); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 200 | } |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 201 | if (DEBUG) LOG("collapsePanel: animate=%s waiting=%s", animate, waiting); |
Daniel Sandler | c38bbc3 | 2012-10-05 12:21:38 -0400 | [diff] [blame] | 202 | if (!waiting && mState != STATE_CLOSED) { |
John Spurlock | 209bede | 2013-07-17 12:23:27 -0400 | [diff] [blame] | 203 | // it's possible that nothing animated, so we replicate the termination |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 204 | // conditions of panelExpansionChanged here |
| 205 | go(STATE_CLOSED); |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 206 | onPanelCollapsed(); |
Daniel Sandler | 198a030 | 2012-08-17 16:04:31 -0400 | [diff] [blame] | 207 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | public void onPanelPeeked() { |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 211 | if (DEBUG) LOG("onPanelPeeked"); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 214 | public boolean isClosed() { |
| 215 | return mState == STATE_CLOSED; |
| 216 | } |
| 217 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 218 | public void onPanelCollapsed() { |
| 219 | if (DEBUG) LOG("onPanelCollapsed"); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 222 | public void onPanelFullyOpened() { |
Daniel Sandler | 67eab79 | 2012-10-02 17:08:23 -0400 | [diff] [blame] | 223 | if (DEBUG) LOG("onPanelFullyOpened"); |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 224 | } |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 225 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 226 | public void onTrackingStarted() { |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 227 | mTracking = true; |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Xiaohui Chen | 9f96711 | 2016-01-07 14:14:06 -0800 | [diff] [blame] | 230 | public void onTrackingStopped(boolean expand) { |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 231 | mTracking = false; |
Daniel Sandler | 978f853 | 2012-08-15 15:48:16 -0400 | [diff] [blame] | 232 | } |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 233 | |
| 234 | public void onExpandingFinished() { |
Chris Wren | 1689594 | 2015-06-23 11:22:20 -0400 | [diff] [blame] | 235 | if (DEBUG) LOG("onExpandingFinished"); |
Jorim Jaggi | 2fbad7b | 2014-05-26 22:38:00 +0200 | [diff] [blame] | 236 | } |
Selim Cinek | dbbcfbe | 2014-10-24 17:52:35 +0200 | [diff] [blame] | 237 | |
| 238 | public void onClosingFinished() { |
| 239 | |
| 240 | } |
Daniel Sandler | 08d05e3 | 2012-08-08 16:39:54 -0400 | [diff] [blame] | 241 | } |