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