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; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 20 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 21 | import android.graphics.drawable.AnimationDrawable; |
| 22 | import android.graphics.drawable.Drawable; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 23 | import android.util.AttributeSet; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 24 | import android.view.View; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 25 | import android.view.ViewGroup; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 26 | import android.view.accessibility.AccessibilityEvent; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 27 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 28 | import android.widget.ImageView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 29 | import com.android.systemui.R; |
| 30 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 31 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 32 | private int mRowMinHeight; |
| 33 | private int mRowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 34 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 35 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 36 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 37 | /** Has the user actively changed the expansion state of this row */ |
| 38 | private boolean mHasUserChangedExpansion; |
| 39 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 40 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 41 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 42 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 43 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 44 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 45 | private boolean mSensitive; |
| 46 | private boolean mShowingPublicInitialized; |
| 47 | private boolean mShowingPublicForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 48 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 49 | /** |
| 50 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 51 | * user expansion. |
| 52 | */ |
| 53 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 54 | |
| 55 | /** |
| 56 | * Whether the notification expansion is disabled. This is the case on Keyguard. |
| 57 | */ |
| 58 | private boolean mExpansionDisabled; |
| 59 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 60 | private NotificationContentView mPublicLayout; |
| 61 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 62 | private int mMaxExpandHeight; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 63 | private View mVetoButton; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 64 | private boolean mClearable; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 65 | private ExpansionLogger mLogger; |
| 66 | private String mLoggingKey; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 67 | private boolean mWasReset; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 68 | private NotificationGuts mGuts; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 69 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 70 | public void setIconAnimationRunning(boolean running) { |
| 71 | setIconAnimationRunning(running, mPublicLayout); |
| 72 | setIconAnimationRunning(running, mPrivateLayout); |
| 73 | } |
| 74 | |
| 75 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 76 | if (layout != null) { |
| 77 | View contractedChild = layout.getContractedChild(); |
| 78 | View expandedChild = layout.getExpandedChild(); |
| 79 | setIconAnimationRunningForChild(running, contractedChild); |
| 80 | setIconAnimationRunningForChild(running, expandedChild); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 85 | if (child != null) { |
| 86 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 87 | setIconRunning(icon, running); |
| 88 | ImageView rightIcon = (ImageView) child.findViewById( |
| 89 | com.android.internal.R.id.right_icon); |
| 90 | setIconRunning(rightIcon, running); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | private void setIconRunning(ImageView imageView, boolean running) { |
| 95 | if (imageView != null) { |
| 96 | Drawable drawable = imageView.getDrawable(); |
| 97 | if (drawable instanceof AnimationDrawable) { |
| 98 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 99 | if (running) { |
| 100 | animationDrawable.start(); |
| 101 | } else { |
| 102 | animationDrawable.stop(); |
| 103 | } |
| 104 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 105 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 106 | if (running) { |
| 107 | animationDrawable.start(); |
| 108 | } else { |
| 109 | animationDrawable.stop(); |
| 110 | } |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 115 | public interface ExpansionLogger { |
| 116 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 117 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 118 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 119 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 120 | super(context, attrs); |
| 121 | } |
| 122 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 123 | /** |
| 124 | * Resets this view so it can be re-used for an updated notification. |
| 125 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 126 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 127 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 128 | super.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 129 | mRowMinHeight = 0; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 130 | final boolean wasExpanded = isExpanded(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 131 | mRowMaxHeight = 0; |
| 132 | mExpandable = false; |
| 133 | mHasUserChangedExpansion = false; |
| 134 | mUserLocked = false; |
| 135 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 136 | mSensitive = false; |
| 137 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 138 | mIsSystemExpanded = false; |
| 139 | mExpansionDisabled = false; |
| 140 | mPublicLayout.reset(); |
| 141 | mPrivateLayout.reset(); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 142 | resetHeight(); |
| 143 | logExpansionEvent(false, wasExpanded); |
| 144 | } |
| 145 | |
| 146 | public void resetHeight() { |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 147 | mMaxExpandHeight = 0; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 148 | mWasReset = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 149 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame^] | 150 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 151 | } |
| 152 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 153 | @Override |
| 154 | protected void onFinishInflate() { |
| 155 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 156 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 157 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 158 | mGuts = (NotificationGuts) findViewById(R.id.notification_guts); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 159 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | @Override |
| 163 | public boolean onRequestSendAccessibilityEvent(View child, AccessibilityEvent event) { |
| 164 | if (super.onRequestSendAccessibilityEvent(child, event)) { |
| 165 | // Add a record for the entire layout since its content is somehow small. |
| 166 | // The event comes from a leaf view that is interacted with. |
| 167 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 168 | onInitializeAccessibilityEvent(record); |
| 169 | dispatchPopulateAccessibilityEvent(record); |
| 170 | event.appendRecord(record); |
| 171 | return true; |
| 172 | } |
| 173 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 174 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 175 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 176 | @Override |
| 177 | public void setDark(boolean dark, boolean fade) { |
| 178 | super.setDark(dark, fade); |
| 179 | final NotificationContentView showing = getShowingLayout(); |
| 180 | if (showing != null) { |
| 181 | showing.setDark(dark, fade); |
| 182 | } |
| 183 | } |
| 184 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 185 | public void setHeightRange(int rowMinHeight, int rowMaxHeight) { |
| 186 | mRowMinHeight = rowMinHeight; |
| 187 | mRowMaxHeight = rowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 188 | } |
| 189 | |
| 190 | public boolean isExpandable() { |
| 191 | return mExpandable; |
| 192 | } |
| 193 | |
| 194 | public void setExpandable(boolean expandable) { |
| 195 | mExpandable = expandable; |
| 196 | } |
| 197 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 198 | /** |
| 199 | * @return whether the user has changed the expansion state |
| 200 | */ |
| 201 | public boolean hasUserChangedExpansion() { |
| 202 | return mHasUserChangedExpansion; |
| 203 | } |
| 204 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 205 | public boolean isUserExpanded() { |
| 206 | return mUserExpanded; |
| 207 | } |
| 208 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 209 | /** |
| 210 | * Set this notification to be expanded by the user |
| 211 | * |
| 212 | * @param userExpanded whether the user wants this notification to be expanded |
| 213 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 214 | public void setUserExpanded(boolean userExpanded) { |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 215 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 216 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 217 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 218 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 219 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 220 | } |
| 221 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 222 | public void resetUserExpansion() { |
| 223 | mHasUserChangedExpansion = false; |
| 224 | mUserExpanded = false; |
| 225 | } |
| 226 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 227 | public boolean isUserLocked() { |
| 228 | return mUserLocked; |
| 229 | } |
| 230 | |
| 231 | public void setUserLocked(boolean userLocked) { |
| 232 | mUserLocked = userLocked; |
| 233 | } |
| 234 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 235 | /** |
| 236 | * @return has the system set this notification to be expanded |
| 237 | */ |
| 238 | public boolean isSystemExpanded() { |
| 239 | return mIsSystemExpanded; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Set this notification to be expanded by the system. |
| 244 | * |
| 245 | * @param expand whether the system wants this notification to be expanded. |
| 246 | */ |
| 247 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 248 | if (expand != mIsSystemExpanded) { |
| 249 | final boolean wasExpanded = isExpanded(); |
| 250 | mIsSystemExpanded = expand; |
| 251 | notifyHeightChanged(); |
| 252 | logExpansionEvent(false, wasExpanded); |
| 253 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /** |
| 257 | * @param expansionDisabled whether to prevent notification expansion |
| 258 | */ |
| 259 | public void setExpansionDisabled(boolean expansionDisabled) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 260 | if (expansionDisabled != mExpansionDisabled) { |
| 261 | final boolean wasExpanded = isExpanded(); |
| 262 | mExpansionDisabled = expansionDisabled; |
| 263 | logExpansionEvent(false, wasExpanded); |
| 264 | if (wasExpanded != isExpanded()) { |
| 265 | notifyHeightChanged(); |
| 266 | } |
| 267 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /** |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 271 | * @return Can the underlying notification be cleared? |
| 272 | */ |
| 273 | public boolean isClearable() { |
| 274 | return mClearable; |
| 275 | } |
| 276 | |
| 277 | /** |
| 278 | * Set whether the notification can be cleared. |
| 279 | * |
| 280 | * @param clearable |
| 281 | */ |
| 282 | public void setClearable(boolean clearable) { |
| 283 | mClearable = clearable; |
| 284 | updateVetoButton(); |
| 285 | } |
| 286 | |
| 287 | /** |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 288 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 289 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 290 | public void applyExpansionToLayout() { |
| 291 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 292 | if (expand && mExpandable) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 293 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 294 | } else { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 295 | setActualHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 296 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 297 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 298 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 299 | @Override |
| 300 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 301 | if (isUserLocked()) { |
| 302 | return getActualHeight(); |
| 303 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 304 | boolean inExpansionState = isExpanded(); |
| 305 | if (!inExpansionState) { |
| 306 | // not expanded, so we return the collapsed size |
| 307 | return mRowMinHeight; |
| 308 | } |
| 309 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 310 | return mShowingPublicForIntrinsicHeight ? mRowMinHeight : getMaxExpandHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 311 | } |
| 312 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 313 | /** |
| 314 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 315 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 316 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 317 | * view can differ from this state, if layout params are modified from outside. |
| 318 | * |
| 319 | * @return whether the view state is currently expanded. |
| 320 | */ |
| 321 | private boolean isExpanded() { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 322 | return !mExpansionDisabled |
| 323 | && (!hasUserChangedExpansion() && isSystemExpanded() || isUserExpanded()); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | @Override |
| 327 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 328 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 329 | boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 330 | updateMaxExpandHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 331 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 332 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 333 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 334 | mWasReset = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 335 | } |
| 336 | |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 337 | private void updateMaxExpandHeight() { |
| 338 | int intrinsicBefore = getIntrinsicHeight(); |
| 339 | mMaxExpandHeight = mPrivateLayout.getMaxHeight(); |
| 340 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 341 | notifyHeightChanged(); |
| 342 | } |
| 343 | } |
| 344 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 345 | public void setSensitive(boolean sensitive) { |
| 346 | mSensitive = sensitive; |
| 347 | } |
| 348 | |
| 349 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
| 350 | mShowingPublicForIntrinsicHeight = mSensitive && hideSensitive; |
| 351 | } |
| 352 | |
| 353 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 354 | long duration) { |
| 355 | boolean oldShowingPublic = mShowingPublic; |
| 356 | mShowingPublic = mSensitive && hideSensitive; |
| 357 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 358 | return; |
| 359 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 360 | |
| 361 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 362 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 363 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 364 | if (!animated) { |
| 365 | mPublicLayout.animate().cancel(); |
| 366 | mPrivateLayout.animate().cancel(); |
| 367 | mPublicLayout.setAlpha(1f); |
| 368 | mPrivateLayout.setAlpha(1f); |
| 369 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
| 370 | mPrivateLayout.setVisibility(mShowingPublic ? View.INVISIBLE : View.VISIBLE); |
| 371 | } else { |
| 372 | animateShowingPublic(delay, duration); |
| 373 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 374 | |
| 375 | updateVetoButton(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 376 | mShowingPublicInitialized = true; |
| 377 | } |
| 378 | |
| 379 | private void animateShowingPublic(long delay, long duration) { |
| 380 | final View source = mShowingPublic ? mPrivateLayout : mPublicLayout; |
| 381 | View target = mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 382 | source.setVisibility(View.VISIBLE); |
| 383 | target.setVisibility(View.VISIBLE); |
| 384 | target.setAlpha(0f); |
| 385 | source.animate().cancel(); |
| 386 | target.animate().cancel(); |
| 387 | source.animate() |
| 388 | .alpha(0f) |
| 389 | .withLayer() |
| 390 | .setStartDelay(delay) |
| 391 | .setDuration(duration) |
| 392 | .withEndAction(new Runnable() { |
| 393 | @Override |
| 394 | public void run() { |
| 395 | source.setVisibility(View.INVISIBLE); |
| 396 | } |
| 397 | }); |
| 398 | target.animate() |
| 399 | .alpha(1f) |
| 400 | .withLayer() |
| 401 | .setStartDelay(delay) |
| 402 | .setDuration(duration); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | private void updateVetoButton() { |
| 406 | // public versions cannot be dismissed |
| 407 | mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 408 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 409 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 410 | public int getMaxExpandHeight() { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 411 | return mShowingPublicForIntrinsicHeight ? mRowMinHeight : mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 412 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 413 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 414 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 415 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 416 | NotificationContentView showingLayout = getShowingLayout(); |
| 417 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 421 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 422 | mPrivateLayout.setActualHeight(height); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 423 | mPublicLayout.setActualHeight(height); |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 424 | mGuts.setActualHeight(height); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 425 | invalidate(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 426 | super.setActualHeight(height, notifyListeners); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public int getMaxHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 431 | NotificationContentView showingLayout = getShowingLayout(); |
| 432 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 436 | public int getMinHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 437 | NotificationContentView showingLayout = getShowingLayout(); |
| 438 | return showingLayout.getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 442 | public void setClipTopAmount(int clipTopAmount) { |
| 443 | super.setClipTopAmount(clipTopAmount); |
| 444 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 445 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 446 | mGuts.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | public void notifyContentUpdated() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 450 | mPublicLayout.notifyContentUpdated(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 451 | mPrivateLayout.notifyContentUpdated(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 452 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 453 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 454 | public boolean isMaxExpandHeightInitialized() { |
| 455 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 456 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 457 | |
| 458 | private NotificationContentView getShowingLayout() { |
| 459 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 460 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 461 | |
| 462 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 463 | mLogger = logger; |
| 464 | mLoggingKey = key; |
| 465 | } |
| 466 | |
| 467 | |
| 468 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
| 469 | final boolean nowExpanded = isExpanded(); |
| 470 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 471 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 472 | } |
| 473 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 474 | } |