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