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