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