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 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ValueAnimator; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 22 | import android.content.Context; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 23 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 24 | import android.graphics.drawable.AnimationDrawable; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 25 | import android.graphics.drawable.ColorDrawable; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 27 | import android.service.notification.StatusBarNotification; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 29 | import android.view.MotionEvent; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 30 | import android.view.View; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 31 | import android.view.ViewStub; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 32 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 33 | import android.view.animation.LinearInterpolator; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 34 | import android.widget.ImageView; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 35 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 36 | import com.android.systemui.R; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 37 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
| 38 | import com.android.systemui.statusbar.phone.PhoneStatusBar; |
| 39 | import com.android.systemui.statusbar.stack.NotificationChildrenContainer; |
| 40 | import com.android.systemui.statusbar.stack.StackScrollState; |
| 41 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 42 | import com.android.systemui.statusbar.stack.StackViewState; |
| 43 | |
| 44 | import java.util.List; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 45 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 46 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 47 | |
| 48 | private static final int DEFAULT_DIVIDER_ALPHA = 0x29; |
| 49 | private static final int COLORED_DIVIDER_ALPHA = 0x7B; |
| 50 | private final LinearInterpolator mLinearInterpolator = new LinearInterpolator(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 51 | private int mRowMinHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 52 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 53 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 54 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 55 | /** Has the user actively changed the expansion state of this row */ |
| 56 | private boolean mHasUserChangedExpansion; |
| 57 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 58 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 59 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 60 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 61 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 62 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 63 | private boolean mSensitive; |
| 64 | private boolean mShowingPublicInitialized; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame^] | 65 | private boolean mHideSensitiveForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 66 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 67 | /** |
| 68 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 69 | * user expansion. |
| 70 | */ |
| 71 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * Whether the notification expansion is disabled. This is the case on Keyguard. |
| 75 | */ |
| 76 | private boolean mExpansionDisabled; |
| 77 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 78 | private NotificationContentView mPublicLayout; |
| 79 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 80 | private int mMaxExpandHeight; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 81 | private int mHeadsUpHeight; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 82 | private View mVetoButton; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 83 | private boolean mClearable; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 84 | private ExpansionLogger mLogger; |
| 85 | private String mLoggingKey; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 86 | private boolean mWasReset; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 87 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 88 | private NotificationGuts mGuts; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 89 | private StatusBarNotification mStatusBarNotification; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 90 | private boolean mIsHeadsUp; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 91 | private View mExpandButton; |
| 92 | private View mExpandButtonDivider; |
| 93 | private ViewStub mExpandButtonStub; |
| 94 | private ViewStub mChildrenContainerStub; |
| 95 | private NotificationGroupManager mGroupManager; |
| 96 | private View mExpandButtonContainer; |
| 97 | private boolean mChildrenExpanded; |
| 98 | private NotificationChildrenContainer mChildrenContainer; |
| 99 | private ValueAnimator mChildExpandAnimator; |
| 100 | private float mChildrenExpandProgress; |
| 101 | private float mExpandButtonStart; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 102 | private ViewStub mGutsStub; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 103 | private boolean mHasExpandAction; |
| 104 | private boolean mIsSystemChildExpanded; |
| 105 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 106 | @Override |
| 107 | public void onClick(View v) { |
| 108 | mGroupManager.setGroupExpanded(mStatusBarNotification, |
| 109 | !mChildrenExpanded); |
| 110 | } |
| 111 | }; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 112 | private boolean mInShade; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 113 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 114 | public NotificationContentView getPrivateLayout() { |
| 115 | return mPrivateLayout; |
| 116 | } |
| 117 | |
| 118 | public NotificationContentView getPublicLayout() { |
| 119 | return mPublicLayout; |
| 120 | } |
| 121 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 122 | public void setIconAnimationRunning(boolean running) { |
| 123 | setIconAnimationRunning(running, mPublicLayout); |
| 124 | setIconAnimationRunning(running, mPrivateLayout); |
| 125 | } |
| 126 | |
| 127 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 128 | if (layout != null) { |
| 129 | View contractedChild = layout.getContractedChild(); |
| 130 | View expandedChild = layout.getExpandedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 131 | View headsUpChild = layout.getHeadsUpChild(); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 132 | setIconAnimationRunningForChild(running, contractedChild); |
| 133 | setIconAnimationRunningForChild(running, expandedChild); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 134 | setIconAnimationRunningForChild(running, headsUpChild); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 139 | if (child != null) { |
| 140 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 141 | setIconRunning(icon, running); |
| 142 | ImageView rightIcon = (ImageView) child.findViewById( |
| 143 | com.android.internal.R.id.right_icon); |
| 144 | setIconRunning(rightIcon, running); |
| 145 | } |
| 146 | } |
| 147 | |
| 148 | private void setIconRunning(ImageView imageView, boolean running) { |
| 149 | if (imageView != null) { |
| 150 | Drawable drawable = imageView.getDrawable(); |
| 151 | if (drawable instanceof AnimationDrawable) { |
| 152 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 153 | if (running) { |
| 154 | animationDrawable.start(); |
| 155 | } else { |
| 156 | animationDrawable.stop(); |
| 157 | } |
| 158 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 159 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 160 | if (running) { |
| 161 | animationDrawable.start(); |
| 162 | } else { |
| 163 | animationDrawable.stop(); |
| 164 | } |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 169 | public void setStatusBarNotification(StatusBarNotification statusBarNotification) { |
| 170 | mStatusBarNotification = statusBarNotification; |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 171 | updateVetoButton(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 172 | updateExpandButton(); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | public StatusBarNotification getStatusBarNotification() { |
| 176 | return mStatusBarNotification; |
| 177 | } |
| 178 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 179 | public boolean isHeadsUp() { |
| 180 | return mIsHeadsUp; |
| 181 | } |
| 182 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 183 | public void setHeadsUp(boolean isHeadsUp) { |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 184 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 185 | mIsHeadsUp = isHeadsUp; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 186 | mPrivateLayout.setHeadsUp(isHeadsUp); |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 187 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 188 | notifyHeightChanged(false /* needsAnimation */); |
| 189 | } |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 192 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 193 | mGroupManager = groupManager; |
| 194 | } |
| 195 | |
| 196 | public void addChildNotification(ExpandableNotificationRow row) { |
| 197 | addChildNotification(row, -1); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Add a child notification to this view. |
| 202 | * |
| 203 | * @param row the row to add |
| 204 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 205 | */ |
| 206 | public void addChildNotification(ExpandableNotificationRow row, int childIndex) { |
| 207 | if (mChildrenContainer == null) { |
| 208 | mChildrenContainerStub.inflate(); |
| 209 | } |
| 210 | mChildrenContainer.addNotification(row, childIndex); |
| 211 | } |
| 212 | |
| 213 | public void removeChildNotification(ExpandableNotificationRow row) { |
| 214 | if (mChildrenContainer != null) { |
| 215 | mChildrenContainer.removeNotification(row); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | @Override |
| 220 | public boolean areChildrenExpanded() { |
| 221 | return mChildrenExpanded; |
| 222 | } |
| 223 | |
| 224 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 225 | return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren(); |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Apply the order given in the list to the children. |
| 230 | * |
| 231 | * @param childOrder the new list order |
| 232 | * @return whether the list order has changed |
| 233 | */ |
| 234 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) { |
| 235 | return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder); |
| 236 | } |
| 237 | |
| 238 | public void getChildrenStates(StackScrollState resultState) { |
| 239 | if (mChildrenExpanded) { |
| 240 | StackViewState parentState = resultState.getViewStateForView(this); |
| 241 | mChildrenContainer.getState(resultState, parentState); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | public void applyChildrenState(StackScrollState state) { |
| 246 | if (mChildrenExpanded) { |
| 247 | mChildrenContainer.applyState(state); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | public void prepareExpansionChanged(StackScrollState state) { |
| 252 | if (mChildrenExpanded) { |
| 253 | mChildrenContainer.prepareExpansionChanged(state); |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | public void startChildAnimation(StackScrollState finalState, |
| 258 | StackStateAnimator stateAnimator, boolean withDelays, long delay, long duration) { |
| 259 | if (mChildrenExpanded) { |
| 260 | mChildrenContainer.startAnimationToState(finalState, stateAnimator, withDelays, delay, |
| 261 | duration); |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | public ExpandableNotificationRow getViewAtPosition(float y) { |
| 266 | if (!mChildrenExpanded) { |
| 267 | return this; |
| 268 | } else { |
| 269 | ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y); |
| 270 | return view == null ? this : view; |
| 271 | } |
| 272 | } |
| 273 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 274 | public NotificationGuts getGuts() { |
| 275 | return mGuts; |
| 276 | } |
| 277 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 278 | protected int calculateContentHeightFromActualHeight(int actualHeight) { |
| 279 | int realActualHeight = actualHeight; |
| 280 | if (hasBottomDecor()) { |
| 281 | realActualHeight -= getBottomDecorHeight(); |
| 282 | } |
| 283 | realActualHeight = Math.max(getMinHeight(), realActualHeight); |
| 284 | return realActualHeight; |
| 285 | } |
| 286 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 287 | public void setInShade(boolean inShade) { |
| 288 | mInShade = inShade; |
| 289 | } |
| 290 | |
| 291 | public boolean isInShade() { |
| 292 | return mInShade; |
| 293 | } |
| 294 | |
| 295 | public int getHeadsUpHeight() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 296 | return mHeadsUpHeight; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 297 | } |
| 298 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 299 | public interface ExpansionLogger { |
| 300 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 301 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 302 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 303 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 304 | super(context, attrs); |
| 305 | } |
| 306 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 307 | /** |
| 308 | * Resets this view so it can be re-used for an updated notification. |
| 309 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 310 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 311 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 312 | super.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 313 | mRowMinHeight = 0; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 314 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 315 | mMaxViewHeight = 0; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 316 | mExpandable = false; |
| 317 | mHasUserChangedExpansion = false; |
| 318 | mUserLocked = false; |
| 319 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 320 | mSensitive = false; |
| 321 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 322 | mIsSystemExpanded = false; |
| 323 | mExpansionDisabled = false; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 324 | mPublicLayout.reset(mIsHeadsUp); |
| 325 | mPrivateLayout.reset(mIsHeadsUp); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 326 | resetHeight(); |
| 327 | logExpansionEvent(false, wasExpanded); |
| 328 | } |
| 329 | |
| 330 | public void resetHeight() { |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 331 | if (mIsHeadsUp) { |
| 332 | resetActualHeight(); |
| 333 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 334 | mMaxExpandHeight = 0; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 335 | mHeadsUpHeight = 0; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 336 | mWasReset = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 337 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame] | 338 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 341 | @Override |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 342 | protected boolean filterMotionEvent(MotionEvent event) { |
| 343 | return mIsHeadsUp || super.filterMotionEvent(event); |
| 344 | } |
| 345 | |
| 346 | @Override |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 347 | protected void onFinishInflate() { |
| 348 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 349 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 350 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 351 | mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub); |
| 352 | mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 353 | @Override |
| 354 | public void onInflate(ViewStub stub, View inflated) { |
| 355 | mGuts = (NotificationGuts) inflated; |
| 356 | mGuts.setClipTopAmount(getClipTopAmount()); |
| 357 | mGuts.setActualHeight(getActualHeight()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 358 | mGutsStub = null; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 359 | } |
| 360 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 361 | mExpandButtonStub = (ViewStub) findViewById(R.id.more_button_stub); |
| 362 | mExpandButtonStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 363 | |
| 364 | @Override |
| 365 | public void onInflate(ViewStub stub, View inflated) { |
| 366 | mExpandButtonContainer = inflated; |
| 367 | mExpandButton = inflated.findViewById(R.id.notification_expand_button); |
| 368 | mExpandButtonDivider = inflated.findViewById(R.id.notification_expand_divider); |
| 369 | mExpandButtonContainer.setOnClickListener(mExpandClickListener); |
| 370 | } |
| 371 | }); |
| 372 | mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub); |
| 373 | mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 374 | |
| 375 | @Override |
| 376 | public void onInflate(ViewStub stub, View inflated) { |
| 377 | mChildrenContainer = (NotificationChildrenContainer) inflated; |
| 378 | mChildrenContainer.setCollapseClickListener(mExpandClickListener); |
| 379 | updateChildrenVisibility(false); |
| 380 | } |
| 381 | }); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 382 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 383 | } |
| 384 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 385 | public void inflateGuts() { |
| 386 | if (mGuts == null) { |
| 387 | mGutsStub.inflate(); |
| 388 | } |
| 389 | } |
| 390 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 391 | private void updateChildrenVisibility(boolean animated) { |
| 392 | if (mChildrenContainer == null) { |
| 393 | return; |
| 394 | } |
| 395 | if (mChildExpandAnimator != null) { |
| 396 | mChildExpandAnimator.cancel(); |
| 397 | } |
| 398 | float targetProgress = mChildrenExpanded ? 1.0f : 0.0f; |
| 399 | if (animated) { |
| 400 | if (mChildrenExpanded) { |
| 401 | mChildrenContainer.setVisibility(VISIBLE); |
| 402 | } |
| 403 | mExpandButtonStart = mExpandButtonContainer.getTranslationY(); |
| 404 | mChildExpandAnimator = ValueAnimator.ofFloat(mChildrenExpandProgress, targetProgress); |
| 405 | mChildExpandAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 406 | @Override |
| 407 | public void onAnimationUpdate(ValueAnimator animation) { |
| 408 | setChildrenExpandProgress((float) animation.getAnimatedValue()); |
| 409 | } |
| 410 | }); |
| 411 | mChildExpandAnimator.addListener(new AnimatorListenerAdapter() { |
| 412 | @Override |
| 413 | public void onAnimationEnd(Animator animation) { |
| 414 | mChildExpandAnimator = null; |
| 415 | if (!mChildrenExpanded) { |
| 416 | mChildrenContainer.setVisibility(INVISIBLE); |
| 417 | } |
| 418 | } |
| 419 | }); |
| 420 | mChildExpandAnimator.setInterpolator(mLinearInterpolator); |
| 421 | mChildExpandAnimator.setDuration( |
| 422 | StackStateAnimator.ANIMATION_DURATION_EXPAND_CLICKED); |
| 423 | mChildExpandAnimator.start(); |
| 424 | } else { |
| 425 | setChildrenExpandProgress(targetProgress); |
| 426 | mChildrenContainer.setVisibility(mChildrenExpanded ? VISIBLE : INVISIBLE); |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | private void setChildrenExpandProgress(float progress) { |
| 431 | mChildrenExpandProgress = progress; |
| 432 | updateExpandButtonAppearance(); |
| 433 | NotificationContentView showingLayout = getShowingLayout(); |
| 434 | float alpha = 1.0f - mChildrenExpandProgress; |
| 435 | alpha = PhoneStatusBar.ALPHA_OUT.getInterpolation(alpha); |
| 436 | showingLayout.setAlpha(alpha); |
| 437 | } |
| 438 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 439 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 440 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 441 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 442 | // Add a record for the entire layout since its content is somehow small. |
| 443 | // The event comes from a leaf view that is interacted with. |
| 444 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 445 | onInitializeAccessibilityEvent(record); |
| 446 | dispatchPopulateAccessibilityEvent(record); |
| 447 | event.appendRecord(record); |
| 448 | return true; |
| 449 | } |
| 450 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 451 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 452 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 453 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 454 | public void setDark(boolean dark, boolean fade, long delay) { |
| 455 | super.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 456 | final NotificationContentView showing = getShowingLayout(); |
| 457 | if (showing != null) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 458 | showing.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 462 | public void setHeightRange(int rowMinHeight, int rowMaxHeight) { |
| 463 | mRowMinHeight = rowMinHeight; |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 464 | mMaxViewHeight = rowMaxHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | public boolean isExpandable() { |
| 468 | return mExpandable; |
| 469 | } |
| 470 | |
| 471 | public void setExpandable(boolean expandable) { |
| 472 | mExpandable = expandable; |
| 473 | } |
| 474 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 475 | /** |
| 476 | * @return whether the user has changed the expansion state |
| 477 | */ |
| 478 | public boolean hasUserChangedExpansion() { |
| 479 | return mHasUserChangedExpansion; |
| 480 | } |
| 481 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 482 | public boolean isUserExpanded() { |
| 483 | return mUserExpanded; |
| 484 | } |
| 485 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 486 | /** |
| 487 | * Set this notification to be expanded by the user |
| 488 | * |
| 489 | * @param userExpanded whether the user wants this notification to be expanded |
| 490 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 491 | public void setUserExpanded(boolean userExpanded) { |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 492 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 493 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 494 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 495 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 496 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 497 | } |
| 498 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 499 | public void resetUserExpansion() { |
| 500 | mHasUserChangedExpansion = false; |
| 501 | mUserExpanded = false; |
| 502 | } |
| 503 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 504 | public boolean isUserLocked() { |
| 505 | return mUserLocked; |
| 506 | } |
| 507 | |
| 508 | public void setUserLocked(boolean userLocked) { |
| 509 | mUserLocked = userLocked; |
| 510 | } |
| 511 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 512 | /** |
| 513 | * @return has the system set this notification to be expanded |
| 514 | */ |
| 515 | public boolean isSystemExpanded() { |
| 516 | return mIsSystemExpanded; |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * Set this notification to be expanded by the system. |
| 521 | * |
| 522 | * @param expand whether the system wants this notification to be expanded. |
| 523 | */ |
| 524 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 525 | if (expand != mIsSystemExpanded) { |
| 526 | final boolean wasExpanded = isExpanded(); |
| 527 | mIsSystemExpanded = expand; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 528 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 529 | logExpansionEvent(false, wasExpanded); |
| 530 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /** |
| 534 | * @param expansionDisabled whether to prevent notification expansion |
| 535 | */ |
| 536 | public void setExpansionDisabled(boolean expansionDisabled) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 537 | if (expansionDisabled != mExpansionDisabled) { |
| 538 | final boolean wasExpanded = isExpanded(); |
| 539 | mExpansionDisabled = expansionDisabled; |
| 540 | logExpansionEvent(false, wasExpanded); |
| 541 | if (wasExpanded != isExpanded()) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 542 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 543 | } |
| 544 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 545 | } |
| 546 | |
| 547 | /** |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 548 | * @return Can the underlying notification be cleared? |
| 549 | */ |
| 550 | public boolean isClearable() { |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 551 | return mStatusBarNotification != null && mStatusBarNotification.isClearable(); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 552 | } |
| 553 | |
| 554 | /** |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 555 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 556 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 557 | public void applyExpansionToLayout() { |
| 558 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 559 | if (expand && mExpandable) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 560 | setContentHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 561 | } else { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 562 | setContentHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 563 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 564 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 565 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 566 | @Override |
| 567 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 568 | if (isUserLocked()) { |
| 569 | return getActualHeight(); |
| 570 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 571 | boolean inExpansionState = isExpanded(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 572 | int maxContentHeight; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame^] | 573 | if (mSensitive && mHideSensitiveForIntrinsicHeight) { |
| 574 | return mRowMinHeight; |
| 575 | } else if (mIsHeadsUp) { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 576 | if (inExpansionState) { |
| 577 | maxContentHeight = Math.max(mMaxExpandHeight, mHeadsUpHeight); |
| 578 | } else { |
| 579 | maxContentHeight = Math.max(mRowMinHeight, mHeadsUpHeight); |
| 580 | } |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame^] | 581 | } else if ((!inExpansionState && !mChildrenExpanded)) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 582 | maxContentHeight = mRowMinHeight; |
| 583 | } else if (mChildrenExpanded) { |
| 584 | maxContentHeight = mChildrenContainer.getIntrinsicHeight(); |
| 585 | } else { |
| 586 | maxContentHeight = getMaxExpandHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 587 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 588 | return maxContentHeight + getBottomDecorHeight(); |
| 589 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 590 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 591 | @Override |
| 592 | protected boolean hasBottomDecor() { |
| 593 | return BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS |
| 594 | && !mIsHeadsUp && mGroupManager.hasGroupChildren(mStatusBarNotification); |
| 595 | } |
| 596 | |
| 597 | @Override |
| 598 | protected boolean canHaveBottomDecor() { |
| 599 | return BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && !mIsHeadsUp; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 602 | /** |
| 603 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 604 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 605 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 606 | * view can differ from this state, if layout params are modified from outside. |
| 607 | * |
| 608 | * @return whether the view state is currently expanded. |
| 609 | */ |
| 610 | private boolean isExpanded() { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 611 | return !mExpansionDisabled |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 612 | && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) |
| 613 | || isUserExpanded()); |
| 614 | } |
| 615 | |
| 616 | private boolean isSystemChildExpanded() { |
| 617 | return mIsSystemChildExpanded; |
| 618 | } |
| 619 | |
| 620 | public void setSystemChildExpanded(boolean expanded) { |
| 621 | mIsSystemChildExpanded = expanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | @Override |
| 625 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 626 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 627 | boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 628 | updateMaxHeights(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 629 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 630 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 631 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 632 | mWasReset = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 633 | } |
| 634 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 635 | @Override |
| 636 | protected boolean isChildInvisible(View child) { |
| 637 | |
| 638 | // We don't want to layout the ChildrenContainer if this is a heads-up view, otherwise the |
| 639 | // view will get too high and the shadows will be off. |
| 640 | boolean isInvisibleChildContainer = child == mChildrenContainer && mIsHeadsUp; |
| 641 | return super.isChildInvisible(child) || isInvisibleChildContainer; |
| 642 | } |
| 643 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 644 | private void updateMaxHeights() { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 645 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 646 | View expandedChild = mPrivateLayout.getExpandedChild(); |
| 647 | if (expandedChild == null) { |
| 648 | expandedChild = mPrivateLayout.getContractedChild(); |
| 649 | } |
| 650 | mMaxExpandHeight = expandedChild.getHeight(); |
| 651 | View headsUpChild = mPrivateLayout.getHeadsUpChild(); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 652 | if (headsUpChild == null) { |
| 653 | headsUpChild = mPrivateLayout.getContractedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 654 | } |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 655 | mHeadsUpHeight = headsUpChild.getHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 656 | if (intrinsicBefore != getIntrinsicHeight()) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 657 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 658 | } |
| 659 | } |
| 660 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 661 | public void setSensitive(boolean sensitive) { |
| 662 | mSensitive = sensitive; |
| 663 | } |
| 664 | |
| 665 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame^] | 666 | mHideSensitiveForIntrinsicHeight = hideSensitive; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 670 | long duration) { |
| 671 | boolean oldShowingPublic = mShowingPublic; |
| 672 | mShowingPublic = mSensitive && hideSensitive; |
| 673 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 674 | return; |
| 675 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 676 | |
| 677 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 678 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 679 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 680 | if (!animated) { |
| 681 | mPublicLayout.animate().cancel(); |
| 682 | mPrivateLayout.animate().cancel(); |
| 683 | mPublicLayout.setAlpha(1f); |
| 684 | mPrivateLayout.setAlpha(1f); |
| 685 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
| 686 | mPrivateLayout.setVisibility(mShowingPublic ? View.INVISIBLE : View.VISIBLE); |
| 687 | } else { |
| 688 | animateShowingPublic(delay, duration); |
| 689 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 690 | |
| 691 | updateVetoButton(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 692 | mShowingPublicInitialized = true; |
| 693 | } |
| 694 | |
| 695 | private void animateShowingPublic(long delay, long duration) { |
| 696 | final View source = mShowingPublic ? mPrivateLayout : mPublicLayout; |
| 697 | View target = mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 698 | source.setVisibility(View.VISIBLE); |
| 699 | target.setVisibility(View.VISIBLE); |
| 700 | target.setAlpha(0f); |
| 701 | source.animate().cancel(); |
| 702 | target.animate().cancel(); |
| 703 | source.animate() |
| 704 | .alpha(0f) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 705 | .setStartDelay(delay) |
| 706 | .setDuration(duration) |
| 707 | .withEndAction(new Runnable() { |
| 708 | @Override |
| 709 | public void run() { |
| 710 | source.setVisibility(View.INVISIBLE); |
| 711 | } |
| 712 | }); |
| 713 | target.animate() |
| 714 | .alpha(1f) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 715 | .setStartDelay(delay) |
| 716 | .setDuration(duration); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | private void updateVetoButton() { |
| 720 | // public versions cannot be dismissed |
| 721 | mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 722 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 723 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 724 | public void setChildrenExpanded(boolean expanded, boolean animate) { |
| 725 | mChildrenExpanded = expanded; |
| 726 | updateChildrenVisibility(animate); |
| 727 | } |
| 728 | |
| 729 | public void updateExpandButton() { |
| 730 | boolean hasExpand = hasBottomDecor(); |
| 731 | if (hasExpand != mHasExpandAction) { |
| 732 | if (hasExpand) { |
| 733 | if (mExpandButtonContainer == null) { |
| 734 | mExpandButtonStub.inflate(); |
| 735 | } |
| 736 | mExpandButtonContainer.setVisibility(View.VISIBLE); |
| 737 | updateExpandButtonAppearance(); |
| 738 | updateExpandButtonColor(); |
| 739 | } else if (mExpandButtonContainer != null) { |
| 740 | mExpandButtonContainer.setVisibility(View.GONE); |
| 741 | } |
| 742 | notifyHeightChanged(true /* needsAnimation */); |
| 743 | } |
| 744 | mHasExpandAction = hasExpand; |
| 745 | } |
| 746 | |
| 747 | private void updateExpandButtonAppearance() { |
| 748 | if (mExpandButtonContainer == null) { |
| 749 | return; |
| 750 | } |
| 751 | float expandButtonAlpha = 0.0f; |
| 752 | float expandButtonTranslation = 0.0f; |
| 753 | float containerTranslation = 0.0f; |
| 754 | int minHeight = getMinHeight(); |
| 755 | if (!mChildrenExpanded || mChildExpandAnimator != null) { |
| 756 | int expandActionHeight = getBottomDecorHeight(); |
| 757 | int translationY = getActualHeight() - expandActionHeight; |
| 758 | if (translationY > minHeight) { |
| 759 | containerTranslation = translationY; |
| 760 | expandButtonAlpha = 1.0f; |
| 761 | expandButtonTranslation = 0.0f; |
| 762 | } else { |
| 763 | containerTranslation = minHeight; |
| 764 | float progress = expandActionHeight != 0 |
| 765 | ? (minHeight - translationY) / (float) expandActionHeight |
| 766 | : 1.0f; |
| 767 | expandButtonTranslation = -progress * expandActionHeight * 0.7f; |
| 768 | float alphaProgress = Math.min(progress / 0.7f, 1.0f); |
| 769 | alphaProgress = PhoneStatusBar.ALPHA_OUT.getInterpolation(alphaProgress); |
| 770 | expandButtonAlpha = 1.0f - alphaProgress; |
| 771 | } |
| 772 | } |
| 773 | if (mChildExpandAnimator != null || mChildrenExpanded) { |
| 774 | expandButtonAlpha = (1.0f - mChildrenExpandProgress) |
| 775 | * expandButtonAlpha; |
| 776 | expandButtonTranslation = (1.0f - mChildrenExpandProgress) |
| 777 | * expandButtonTranslation; |
| 778 | float newTranslation = -getBottomDecorHeight(); |
| 779 | |
| 780 | // We don't want to take the actual height of the view as this is already |
| 781 | // interpolated by a custom interpolator leading to a confusing animation. We want |
| 782 | // to have a stable end value to interpolate in between |
| 783 | float collapsedHeight = !mChildrenExpanded |
| 784 | ? Math.max(StackStateAnimator.getFinalActualHeight(this) |
| 785 | - getBottomDecorHeight(), minHeight) |
| 786 | : mExpandButtonStart; |
| 787 | float translationProgress = mFastOutSlowInInterpolator.getInterpolation( |
| 788 | mChildrenExpandProgress); |
| 789 | containerTranslation = (1.0f - translationProgress) * collapsedHeight |
| 790 | + translationProgress * newTranslation; |
| 791 | } |
| 792 | mExpandButton.setAlpha(expandButtonAlpha); |
| 793 | mExpandButtonDivider.setAlpha(expandButtonAlpha); |
| 794 | mExpandButton.setTranslationY(expandButtonTranslation); |
| 795 | mExpandButtonContainer.setTranslationY(containerTranslation); |
| 796 | NotificationContentView showingLayout = getShowingLayout(); |
| 797 | float layoutTranslation = |
| 798 | mExpandButtonContainer.getTranslationY() - showingLayout.getContentHeight(); |
| 799 | layoutTranslation = Math.min(layoutTranslation, 0); |
| 800 | if (!mChildrenExpanded && mChildExpandAnimator == null) { |
| 801 | // Needed for the DragDownHelper in order not to jump there, as the position |
| 802 | // can be negative for a short time. |
| 803 | layoutTranslation = 0; |
| 804 | } |
| 805 | showingLayout.setTranslationY(layoutTranslation); |
| 806 | if (mChildrenContainer != null) { |
| 807 | mChildrenContainer.setTranslationY( |
| 808 | mExpandButtonContainer.getTranslationY() + getBottomDecorHeight()); |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | private void updateExpandButtonColor() { |
| 813 | // TODO: This needs some more baking, currently only the divider is colored according to |
| 814 | // the tint, but legacy black doesn't work yet perfectly for the button etc. |
| 815 | int color = getRippleColor(); |
| 816 | if (color == mNormalRippleColor) { |
| 817 | color = 0; |
| 818 | } |
| 819 | if (mExpandButtonDivider != null) { |
| 820 | applyTint(mExpandButtonDivider, color); |
| 821 | } |
| 822 | if (mChildrenContainer != null) { |
| 823 | mChildrenContainer.setTintColor(color); |
| 824 | } |
| 825 | } |
| 826 | |
| 827 | public static void applyTint(View v, int color) { |
| 828 | int alpha; |
| 829 | if (color != 0) { |
| 830 | alpha = COLORED_DIVIDER_ALPHA; |
| 831 | } else { |
| 832 | color = 0xff000000; |
| 833 | alpha = DEFAULT_DIVIDER_ALPHA; |
| 834 | } |
| 835 | if (v.getBackground() instanceof ColorDrawable) { |
| 836 | ColorDrawable background = (ColorDrawable) v.getBackground(); |
| 837 | background.mutate(); |
| 838 | background.setColor(color); |
| 839 | background.setAlpha(alpha); |
| 840 | } |
| 841 | } |
| 842 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 843 | public int getMaxExpandHeight() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 844 | return mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 845 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 846 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 847 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 848 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 849 | NotificationContentView showingLayout = getShowingLayout(); |
| 850 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 854 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 855 | super.setActualHeight(height, notifyListeners); |
| 856 | int contentHeight = calculateContentHeightFromActualHeight(height); |
| 857 | mPrivateLayout.setContentHeight(contentHeight); |
| 858 | mPublicLayout.setContentHeight(contentHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 859 | if (mGuts != null) { |
| 860 | mGuts.setActualHeight(height); |
| 861 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 862 | invalidate(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 863 | updateExpandButtonAppearance(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 867 | public int getMaxContentHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 868 | NotificationContentView showingLayout = getShowingLayout(); |
| 869 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 873 | public int getMinHeight() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 874 | NotificationContentView showingLayout = getShowingLayout(); |
| 875 | return showingLayout.getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 879 | public void setClipTopAmount(int clipTopAmount) { |
| 880 | super.setClipTopAmount(clipTopAmount); |
| 881 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 882 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 883 | if (mGuts != null) { |
| 884 | mGuts.setClipTopAmount(clipTopAmount); |
| 885 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | public void notifyContentUpdated() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 889 | mPublicLayout.notifyContentUpdated(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 890 | mPrivateLayout.notifyContentUpdated(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 891 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 892 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 893 | public boolean isMaxExpandHeightInitialized() { |
| 894 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 895 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 896 | |
| 897 | private NotificationContentView getShowingLayout() { |
| 898 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 899 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 900 | |
| 901 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 902 | mLogger = logger; |
| 903 | mLoggingKey = key; |
| 904 | } |
| 905 | |
| 906 | |
| 907 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
| 908 | final boolean nowExpanded = isExpanded(); |
| 909 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 910 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 911 | } |
| 912 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 913 | } |