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