Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 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 | |
| 17 | package com.android.systemui.statusbar; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.util.AttributeSet; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 21 | import android.view.View; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 22 | import android.view.accessibility.AccessibilityEvent; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 23 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 24 | import com.android.systemui.R; |
| 25 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 26 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 27 | private int mRowMinHeight; |
| 28 | private int mRowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 29 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 30 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 31 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 32 | /** Has the user actively changed the expansion state of this row */ |
| 33 | private boolean mHasUserChangedExpansion; |
| 34 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 35 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 36 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 37 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 38 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 39 | private boolean mShowingPublic; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 40 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 41 | /** |
| 42 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 43 | * user expansion. |
| 44 | */ |
| 45 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 46 | |
| 47 | /** |
| 48 | * Whether the notification expansion is disabled. This is the case on Keyguard. |
| 49 | */ |
| 50 | private boolean mExpansionDisabled; |
| 51 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 52 | private NotificationContentView mPublicLayout; |
| 53 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 54 | private int mMaxExpandHeight; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 55 | private boolean mIsBelowSpeedBump; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 56 | private View mVetoButton; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 57 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 58 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 59 | super(context, attrs); |
| 60 | } |
| 61 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 62 | @Override |
| 63 | protected void onFinishInflate() { |
| 64 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 65 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 66 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 67 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 72 | if (super.onRequestSendAccessibilityEvent(child, event)) { |
| 73 | // Add a record for the entire layout since its content is somehow small. |
| 74 | // The event comes from a leaf view that is interacted with. |
| 75 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 76 | onInitializeAccessibilityEvent(record); |
| 77 | dispatchPopulateAccessibilityEvent(record); |
| 78 | event.appendRecord(record); |
| 79 | return true; |
| 80 | } |
| 81 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 82 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 83 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 84 | public void setHeightRange(int rowMinHeight, int rowMaxHeight) { |
| 85 | mRowMinHeight = rowMinHeight; |
| 86 | mRowMaxHeight = rowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | public boolean isExpandable() { |
| 90 | return mExpandable; |
| 91 | } |
| 92 | |
| 93 | public void setExpandable(boolean expandable) { |
| 94 | mExpandable = expandable; |
| 95 | } |
| 96 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 97 | /** |
| 98 | * @return whether the user has changed the expansion state |
| 99 | */ |
| 100 | public boolean hasUserChangedExpansion() { |
| 101 | return mHasUserChangedExpansion; |
| 102 | } |
| 103 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 104 | public boolean isUserExpanded() { |
| 105 | return mUserExpanded; |
| 106 | } |
| 107 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 108 | /** |
| 109 | * Set this notification to be expanded by the user |
| 110 | * |
| 111 | * @param userExpanded whether the user wants this notification to be expanded |
| 112 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 113 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 114 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 115 | mUserExpanded = userExpanded; |
| 116 | } |
| 117 | |
| 118 | public boolean isUserLocked() { |
| 119 | return mUserLocked; |
| 120 | } |
| 121 | |
| 122 | public void setUserLocked(boolean userLocked) { |
| 123 | mUserLocked = userLocked; |
| 124 | } |
| 125 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 126 | /** |
| 127 | * @return has the system set this notification to be expanded |
| 128 | */ |
| 129 | public boolean isSystemExpanded() { |
| 130 | return mIsSystemExpanded; |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Set this notification to be expanded by the system. |
| 135 | * |
| 136 | * @param expand whether the system wants this notification to be expanded. |
| 137 | */ |
| 138 | public void setSystemExpanded(boolean expand) { |
| 139 | mIsSystemExpanded = expand; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 140 | notifyHeightChanged(); |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | /** |
| 144 | * @param expansionDisabled whether to prevent notification expansion |
| 145 | */ |
| 146 | public void setExpansionDisabled(boolean expansionDisabled) { |
| 147 | mExpansionDisabled = expansionDisabled; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 148 | notifyHeightChanged(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 153 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 154 | public void applyExpansionToLayout() { |
| 155 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 156 | if (expand && mExpandable) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 157 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 158 | } else { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 159 | setActualHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 160 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 161 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 162 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 163 | @Override |
| 164 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 165 | if (isUserLocked()) { |
| 166 | return getActualHeight(); |
| 167 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 168 | boolean inExpansionState = isExpanded(); |
| 169 | if (!inExpansionState) { |
| 170 | // not expanded, so we return the collapsed size |
| 171 | return mRowMinHeight; |
| 172 | } |
| 173 | |
| 174 | return mShowingPublic ? mRowMinHeight : getMaxExpandHeight(); |
| 175 | } |
| 176 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 177 | /** |
| 178 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 179 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 180 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 181 | * view can differ from this state, if layout params are modified from outside. |
| 182 | * |
| 183 | * @return whether the view state is currently expanded. |
| 184 | */ |
| 185 | private boolean isExpanded() { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 186 | return !mExpansionDisabled |
| 187 | && (!hasUserChangedExpansion() && isSystemExpanded() || isUserExpanded()); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | @Override |
| 191 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 192 | super.onLayout(changed, left, top, right, bottom); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 193 | boolean updateExpandHeight = mMaxExpandHeight == 0; |
| 194 | mMaxExpandHeight = mPrivateLayout.getMaxHeight(); |
| 195 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 196 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 197 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 200 | public void setShowingPublic(boolean show) { |
| 201 | mShowingPublic = show; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 202 | |
| 203 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 204 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 205 | |
| 206 | // TODO: animation? |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 207 | mPublicLayout.setVisibility(show ? View.VISIBLE : View.GONE); |
| 208 | mPrivateLayout.setVisibility(show ? View.GONE : View.VISIBLE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 209 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 210 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 211 | public int getMaxExpandHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 212 | return mShowingPublic ? mRowMinHeight : mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 213 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 214 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 215 | /** |
| 216 | * @return the potential height this view could expand in addition. |
| 217 | */ |
| 218 | public int getExpandPotential() { |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 219 | return getIntrinsicHeight() - getActualHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 223 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 224 | NotificationContentView showingLayout = getShowingLayout(); |
| 225 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 229 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 230 | mPrivateLayout.setActualHeight(height); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 231 | mPublicLayout.setActualHeight(height); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 232 | invalidate(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 233 | super.setActualHeight(height, notifyListeners); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | @Override |
| 237 | public int getMaxHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 238 | NotificationContentView showingLayout = getShowingLayout(); |
| 239 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 243 | public int getMinHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 244 | NotificationContentView showingLayout = getShowingLayout(); |
| 245 | return showingLayout.getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 249 | public void setClipTopAmount(int clipTopAmount) { |
| 250 | super.setClipTopAmount(clipTopAmount); |
| 251 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 252 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 253 | } |
| 254 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 255 | public boolean isBelowSpeedBump() { |
| 256 | return mIsBelowSpeedBump; |
| 257 | } |
| 258 | |
| 259 | public void setIsBelowSpeedBump(boolean isBelow) { |
| 260 | this.mIsBelowSpeedBump = isBelow; |
| 261 | } |
| 262 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 263 | public void notifyContentUpdated() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 264 | mPublicLayout.notifyContentUpdated(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 265 | mPrivateLayout.notifyContentUpdated(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 266 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 267 | |
| 268 | public boolean isShowingLayoutLayouted() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 269 | NotificationContentView showingLayout = getShowingLayout(); |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 270 | return showingLayout.getWidth() != 0; |
| 271 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame^] | 272 | |
| 273 | private NotificationContentView getShowingLayout() { |
| 274 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 275 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 276 | } |