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 | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 19 | import android.app.Notification; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 20 | import android.content.Context; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 21 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 22 | import android.graphics.drawable.AnimationDrawable; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 23 | import android.graphics.drawable.ColorDrawable; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 24 | import android.graphics.drawable.Drawable; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 25 | import android.os.Build; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 26 | import android.service.notification.StatusBarNotification; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 28 | import android.view.MotionEvent; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 29 | import android.view.NotificationHeaderView; |
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 | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 34 | import android.widget.Chronometer; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 35 | import android.widget.ImageView; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 36 | import android.widget.RemoteViews; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 37 | |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 38 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 39 | import com.android.systemui.classifier.FalsingManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 40 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 41 | import com.android.systemui.statusbar.stack.NotificationChildrenContainer; |
| 42 | import com.android.systemui.statusbar.stack.StackScrollState; |
| 43 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
| 44 | import com.android.systemui.statusbar.stack.StackViewState; |
| 45 | |
| 46 | import java.util.List; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 47 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 48 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 49 | |
| 50 | private static final int DEFAULT_DIVIDER_ALPHA = 0x29; |
| 51 | private static final int COLORED_DIVIDER_ALPHA = 0x7B; |
| 52 | private final LinearInterpolator mLinearInterpolator = new LinearInterpolator(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 53 | private final int mNotificationMinHeightLegacy; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 54 | private final int mMaxHeadsUpHeightLegacy; |
| 55 | private final int mMaxHeadsUpHeight; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 56 | private final int mNotificationMinHeight; |
| 57 | private final int mNotificationMaxHeight; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 58 | private int mRowMinHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 59 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 60 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 61 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 62 | /** Has the user actively changed the expansion state of this row */ |
| 63 | private boolean mHasUserChangedExpansion; |
| 64 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 65 | private boolean mUserExpanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 66 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 67 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 68 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 69 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 70 | private boolean mSensitive; |
| 71 | private boolean mShowingPublicInitialized; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 72 | private boolean mHideSensitiveForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 73 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 74 | /** |
| 75 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 76 | * user expansion. |
| 77 | */ |
| 78 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 79 | |
| 80 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 81 | * Whether the notification is on the keyguard and the expansion is disabled. |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 82 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 83 | private boolean mOnKeyguard; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 84 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 85 | private NotificationContentView mPublicLayout; |
| 86 | private NotificationContentView mPrivateLayout; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 87 | private int mMaxExpandHeight; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 88 | private int mHeadsUpHeight; |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 89 | private View mVetoButton; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 90 | private boolean mClearable; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 91 | private ExpansionLogger mLogger; |
| 92 | private String mLoggingKey; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 93 | private boolean mWasReset; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 94 | private NotificationGuts mGuts; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 95 | private NotificationData.Entry mEntry; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 96 | private StatusBarNotification mStatusBarNotification; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 97 | private boolean mIsHeadsUp; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 98 | private boolean mLastChronometerRunning = true; |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 99 | private NotificationHeaderView mNotificationHeader; |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 100 | private NotificationViewWrapper mNotificationHeaderWrapper; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 101 | private ViewStub mChildrenContainerStub; |
| 102 | private NotificationGroupManager mGroupManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 103 | private boolean mChildrenExpanded; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 104 | private boolean mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 105 | private NotificationChildrenContainer mChildrenContainer; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 106 | private ViewStub mGutsStub; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 107 | private boolean mIsSystemChildExpanded; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 108 | private boolean mIsPinned; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 109 | private FalsingManager mFalsingManager; |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 110 | private NotificationHeaderUtil mHeaderUtil = new NotificationHeaderUtil(this); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 111 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 112 | private boolean mJustClicked; |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 113 | private boolean mIconAnimationRunning; |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 114 | private boolean mShowNoBackground; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 115 | private ExpandableNotificationRow mNotificationParent; |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 116 | private OnExpandClickListener mOnExpandClickListener; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 117 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 118 | @Override |
| 119 | public void onClick(View v) { |
| 120 | if (mGroupManager.isSummaryOfGroup(mStatusBarNotification)) { |
| 121 | mGroupManager.toggleGroupExpansion(mStatusBarNotification); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 122 | mOnExpandClickListener.onExpandClicked(ExpandableNotificationRow.this, |
| 123 | mGroupManager.isGroupExpanded(mStatusBarNotification)); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 124 | } else { |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 125 | boolean nowExpanded = !isExpanded(); |
| 126 | setUserExpanded(nowExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 127 | notifyHeightChanged(true); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 128 | mOnExpandClickListener.onExpandClicked(ExpandableNotificationRow.this, |
| 129 | nowExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | }; |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 133 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 134 | public NotificationContentView getPrivateLayout() { |
| 135 | return mPrivateLayout; |
| 136 | } |
| 137 | |
| 138 | public NotificationContentView getPublicLayout() { |
| 139 | return mPublicLayout; |
| 140 | } |
| 141 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 142 | public void setIconAnimationRunning(boolean running) { |
| 143 | setIconAnimationRunning(running, mPublicLayout); |
| 144 | setIconAnimationRunning(running, mPrivateLayout); |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 145 | setIconAnimationRunningForChild(running, mNotificationHeader); |
| 146 | if (mIsSummaryWithChildren) { |
| 147 | List<ExpandableNotificationRow> notificationChildren = |
| 148 | mChildrenContainer.getNotificationChildren(); |
| 149 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 150 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 151 | child.setIconAnimationRunning(running); |
| 152 | } |
| 153 | } |
| 154 | mIconAnimationRunning = running; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 158 | if (layout != null) { |
| 159 | View contractedChild = layout.getContractedChild(); |
| 160 | View expandedChild = layout.getExpandedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 161 | View headsUpChild = layout.getHeadsUpChild(); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 162 | setIconAnimationRunningForChild(running, contractedChild); |
| 163 | setIconAnimationRunningForChild(running, expandedChild); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 164 | setIconAnimationRunningForChild(running, headsUpChild); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
| 168 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 169 | if (child != null) { |
| 170 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 171 | setIconRunning(icon, running); |
| 172 | ImageView rightIcon = (ImageView) child.findViewById( |
| 173 | com.android.internal.R.id.right_icon); |
| 174 | setIconRunning(rightIcon, running); |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | private void setIconRunning(ImageView imageView, boolean running) { |
| 179 | if (imageView != null) { |
| 180 | Drawable drawable = imageView.getDrawable(); |
| 181 | if (drawable instanceof AnimationDrawable) { |
| 182 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 183 | if (running) { |
| 184 | animationDrawable.start(); |
| 185 | } else { |
| 186 | animationDrawable.stop(); |
| 187 | } |
| 188 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 189 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 190 | if (running) { |
| 191 | animationDrawable.start(); |
| 192 | } else { |
| 193 | animationDrawable.stop(); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 199 | public void onNotificationUpdated(NotificationData.Entry entry) { |
| 200 | mEntry = entry; |
| 201 | mStatusBarNotification = entry.notification; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame^] | 202 | mPrivateLayout.onNotificationUpdated(entry); |
| 203 | mPublicLayout.onNotificationUpdated(entry); |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 204 | updateVetoButton(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 205 | if (mIsSummaryWithChildren) { |
| 206 | recreateNotificationHeader(); |
| 207 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 208 | if (mIconAnimationRunning) { |
| 209 | setIconAnimationRunning(true); |
| 210 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 211 | if (mNotificationParent != null) { |
| 212 | mNotificationParent.updateChildrenHeaderAppearance(); |
| 213 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 214 | onChildrenCountChanged(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 215 | updateLimits(); |
| 216 | } |
| 217 | |
| 218 | private void updateLimits() { |
| 219 | boolean customView = getPrivateLayout().getContractedChild().getId() |
| 220 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 221 | boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N; |
| 222 | int minHeight = customView && beforeN && !mIsSummaryWithChildren ? |
| 223 | mNotificationMinHeightLegacy : mNotificationMinHeight; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 224 | boolean headsUpCustom = getPrivateLayout().getHeadsUpChild() != null && |
| 225 | getPrivateLayout().getHeadsUpChild().getId() |
| 226 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 227 | int headsUpheight = headsUpCustom && beforeN ? mMaxHeadsUpHeightLegacy |
| 228 | : mMaxHeadsUpHeight; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 229 | mRowMinHeight = minHeight; |
| 230 | mMaxViewHeight = mNotificationMaxHeight; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 231 | mPrivateLayout.setHeights(mRowMinHeight, headsUpheight); |
| 232 | mPublicLayout.setHeights(mRowMinHeight, headsUpheight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | public StatusBarNotification getStatusBarNotification() { |
| 236 | return mStatusBarNotification; |
| 237 | } |
| 238 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 239 | public boolean isHeadsUp() { |
| 240 | return mIsHeadsUp; |
| 241 | } |
| 242 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 243 | public void setHeadsUp(boolean isHeadsUp) { |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 244 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 245 | mIsHeadsUp = isHeadsUp; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 246 | mPrivateLayout.setHeadsUp(isHeadsUp); |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 247 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 248 | notifyHeightChanged(false /* needsAnimation */); |
| 249 | } |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 252 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 253 | mGroupManager = groupManager; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 254 | mPrivateLayout.setGroupManager(groupManager); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 255 | } |
| 256 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame^] | 257 | public void setRemoteInputController(RemoteInputController r) { |
| 258 | mPrivateLayout.setRemoteInputController(r); |
| 259 | } |
| 260 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 261 | public void addChildNotification(ExpandableNotificationRow row) { |
| 262 | addChildNotification(row, -1); |
| 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Add a child notification to this view. |
| 267 | * |
| 268 | * @param row the row to add |
| 269 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 270 | */ |
| 271 | public void addChildNotification(ExpandableNotificationRow row, int childIndex) { |
| 272 | if (mChildrenContainer == null) { |
| 273 | mChildrenContainerStub.inflate(); |
| 274 | } |
| 275 | mChildrenContainer.addNotification(row, childIndex); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 276 | onChildrenCountChanged(); |
| 277 | row.setIsChildInGroup(true, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | public void removeChildNotification(ExpandableNotificationRow row) { |
| 281 | if (mChildrenContainer != null) { |
| 282 | mChildrenContainer.removeNotification(row); |
| 283 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 284 | mHeaderUtil.restoreNotificationHeader(row); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 285 | onChildrenCountChanged(); |
| 286 | row.setIsChildInGroup(false, null); |
| 287 | } |
| 288 | |
| 289 | public boolean isChildInGroup() { |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 290 | return mNotificationParent != null; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 291 | } |
| 292 | |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 293 | public ExpandableNotificationRow getNotificationParent() { |
| 294 | return mNotificationParent; |
| 295 | } |
| 296 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 297 | /** |
| 298 | * @param isChildInGroup Is this notification now in a group |
| 299 | * @param parent the new parent notification |
| 300 | */ |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 301 | public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {; |
| 302 | boolean childInGroup = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup; |
| 303 | mNotificationParent = childInGroup ? parent : null; |
| 304 | mPrivateLayout.setIsChildInGroup(childInGroup); |
| 305 | updateNoBackgroundState(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | @Override |
| 309 | protected boolean shouldHideBackground() { |
| 310 | return super.shouldHideBackground() || mShowNoBackground; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | @Override |
| 314 | public boolean isSummaryWithChildren() { |
| 315 | return mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public boolean areChildrenExpanded() { |
| 320 | return mChildrenExpanded; |
| 321 | } |
| 322 | |
| 323 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 324 | return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren(); |
| 325 | } |
| 326 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 327 | public int getNumberOfNotificationChildren() { |
| 328 | if (mChildrenContainer == null) { |
| 329 | return 0; |
| 330 | } |
| 331 | return mChildrenContainer.getNotificationChildren().size(); |
| 332 | } |
| 333 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 334 | /** |
| 335 | * Apply the order given in the list to the children. |
| 336 | * |
| 337 | * @param childOrder the new list order |
| 338 | * @return whether the list order has changed |
| 339 | */ |
| 340 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder) { |
| 341 | return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder); |
| 342 | } |
| 343 | |
| 344 | public void getChildrenStates(StackScrollState resultState) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 345 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 346 | StackViewState parentState = resultState.getViewStateForView(this); |
| 347 | mChildrenContainer.getState(resultState, parentState); |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | public void applyChildrenState(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 352 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 353 | mChildrenContainer.applyState(state); |
| 354 | } |
| 355 | } |
| 356 | |
| 357 | public void prepareExpansionChanged(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 358 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 359 | mChildrenContainer.prepareExpansionChanged(state); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | public void startChildAnimation(StackScrollState finalState, |
| 364 | StackStateAnimator stateAnimator, boolean withDelays, long delay, long duration) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 365 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 366 | mChildrenContainer.startAnimationToState(finalState, stateAnimator, withDelays, delay, |
| 367 | duration); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | public ExpandableNotificationRow getViewAtPosition(float y) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 372 | if (!mIsSummaryWithChildren || !mChildrenExpanded) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 373 | return this; |
| 374 | } else { |
| 375 | ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y); |
| 376 | return view == null ? this : view; |
| 377 | } |
| 378 | } |
| 379 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 380 | public NotificationGuts getGuts() { |
| 381 | return mGuts; |
| 382 | } |
| 383 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 384 | /** |
| 385 | * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this |
| 386 | * the notification will be rendered on top of the screen. |
| 387 | * |
| 388 | * @param pinned whether it is pinned |
| 389 | */ |
| 390 | public void setPinned(boolean pinned) { |
| 391 | mIsPinned = pinned; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 392 | setChronometerRunning(mLastChronometerRunning); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 395 | public boolean isPinned() { |
| 396 | return mIsPinned; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | public int getHeadsUpHeight() { |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 400 | if (mIsSummaryWithChildren) { |
| 401 | return mChildrenContainer.getIntrinsicHeight(); |
| 402 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 403 | return mHeadsUpHeight; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 406 | /** |
| 407 | * Mark whether this notification was just clicked, i.e. the user has just clicked this |
| 408 | * notification in this frame. |
| 409 | */ |
| 410 | public void setJustClicked(boolean justClicked) { |
| 411 | mJustClicked = justClicked; |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * @return true if this notification has been clicked in this frame, false otherwise |
| 416 | */ |
| 417 | public boolean wasJustClicked() { |
| 418 | return mJustClicked; |
| 419 | } |
| 420 | |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 421 | public void setChronometerRunning(boolean running) { |
| 422 | mLastChronometerRunning = running; |
| 423 | setChronometerRunning(running, mPrivateLayout); |
| 424 | setChronometerRunning(running, mPublicLayout); |
| 425 | if (mChildrenContainer != null) { |
| 426 | List<ExpandableNotificationRow> notificationChildren = |
| 427 | mChildrenContainer.getNotificationChildren(); |
| 428 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 429 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 430 | child.setChronometerRunning(running); |
| 431 | } |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | private void setChronometerRunning(boolean running, NotificationContentView layout) { |
| 436 | if (layout != null) { |
| 437 | running = running || isPinned(); |
| 438 | View contractedChild = layout.getContractedChild(); |
| 439 | View expandedChild = layout.getExpandedChild(); |
| 440 | View headsUpChild = layout.getHeadsUpChild(); |
| 441 | setChronometerRunningForChild(running, contractedChild); |
| 442 | setChronometerRunningForChild(running, expandedChild); |
| 443 | setChronometerRunningForChild(running, headsUpChild); |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | private void setChronometerRunningForChild(boolean running, View child) { |
| 448 | if (child != null) { |
| 449 | View chronometer = child.findViewById(com.android.internal.R.id.chronometer); |
| 450 | if (chronometer instanceof Chronometer) { |
| 451 | ((Chronometer) chronometer).setStarted(running); |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 456 | public NotificationHeaderView getNotificationHeader() { |
| 457 | if (mNotificationHeader != null) { |
| 458 | return mNotificationHeader; |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 459 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 460 | return mPrivateLayout.getNotificationHeader(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 461 | } |
| 462 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 463 | public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) { |
| 464 | mOnExpandClickListener = onExpandClickListener; |
| 465 | } |
| 466 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 467 | public interface ExpansionLogger { |
| 468 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 469 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 470 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 471 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 472 | super(context, attrs); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 473 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 474 | mNotificationMinHeightLegacy = getResources().getDimensionPixelSize( |
| 475 | R.dimen.notification_min_height_legacy); |
| 476 | mNotificationMinHeight = getResources().getDimensionPixelSize( |
| 477 | R.dimen.notification_min_height); |
| 478 | mNotificationMaxHeight = getResources().getDimensionPixelSize( |
| 479 | R.dimen.notification_max_height); |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 480 | mMaxHeadsUpHeightLegacy = getResources().getDimensionPixelSize( |
| 481 | R.dimen.notification_max_heads_up_height_legacy); |
| 482 | mMaxHeadsUpHeight = getResources().getDimensionPixelSize( |
| 483 | R.dimen.notification_max_heads_up_height); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 484 | } |
| 485 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 486 | /** |
| 487 | * Resets this view so it can be re-used for an updated notification. |
| 488 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 489 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 490 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 491 | super.reset(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 492 | mRowMinHeight = 0; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 493 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 379ff8f | 2015-02-20 17:03:16 +0100 | [diff] [blame] | 494 | mMaxViewHeight = 0; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 495 | mExpandable = false; |
| 496 | mHasUserChangedExpansion = false; |
| 497 | mUserLocked = false; |
| 498 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 499 | mSensitive = false; |
| 500 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 501 | mIsSystemExpanded = false; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 502 | mOnKeyguard = false; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 503 | mPublicLayout.reset(mIsHeadsUp); |
| 504 | mPrivateLayout.reset(mIsHeadsUp); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 505 | resetHeight(); |
| 506 | logExpansionEvent(false, wasExpanded); |
| 507 | } |
| 508 | |
| 509 | public void resetHeight() { |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 510 | if (mIsHeadsUp) { |
| 511 | resetActualHeight(); |
| 512 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 513 | mMaxExpandHeight = 0; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 514 | mHeadsUpHeight = 0; |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 515 | mWasReset = true; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 516 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame] | 517 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 520 | @Override |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 521 | protected boolean filterMotionEvent(MotionEvent event) { |
| 522 | return mIsHeadsUp || super.filterMotionEvent(event); |
| 523 | } |
| 524 | |
| 525 | @Override |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 526 | protected void onFinishInflate() { |
| 527 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 528 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 529 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 530 | mPrivateLayout.setExpandClickListener(mExpandClickListener); |
| 531 | mPublicLayout.setExpandClickListener(mExpandClickListener); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 532 | mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub); |
| 533 | mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 534 | @Override |
| 535 | public void onInflate(ViewStub stub, View inflated) { |
| 536 | mGuts = (NotificationGuts) inflated; |
| 537 | mGuts.setClipTopAmount(getClipTopAmount()); |
| 538 | mGuts.setActualHeight(getActualHeight()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 539 | mGutsStub = null; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 540 | } |
| 541 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 542 | mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub); |
| 543 | mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 544 | |
| 545 | @Override |
| 546 | public void onInflate(ViewStub stub, View inflated) { |
| 547 | mChildrenContainer = (NotificationChildrenContainer) inflated; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 548 | mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 549 | } |
| 550 | }); |
Selim Cinek | 863834b | 2014-05-20 04:20:25 +0200 | [diff] [blame] | 551 | mVetoButton = findViewById(R.id.veto); |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 554 | public void inflateGuts() { |
| 555 | if (mGuts == null) { |
| 556 | mGutsStub.inflate(); |
| 557 | } |
| 558 | } |
| 559 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 560 | private void updateChildrenVisibility() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 561 | if (mChildrenContainer == null) { |
| 562 | return; |
| 563 | } |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 564 | mChildrenContainer.setVisibility(mIsSummaryWithChildren ? VISIBLE : INVISIBLE); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 565 | mNotificationHeader.setVisibility(mIsSummaryWithChildren ? VISIBLE : INVISIBLE); |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 566 | mPrivateLayout.setVisibility(!mIsSummaryWithChildren ? VISIBLE : INVISIBLE); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 567 | // The limits might have changed if the view suddenly became a group or vice versa |
| 568 | updateLimits(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 571 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 572 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 573 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 574 | // Add a record for the entire layout since its content is somehow small. |
| 575 | // The event comes from a leaf view that is interacted with. |
| 576 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 577 | onInitializeAccessibilityEvent(record); |
| 578 | dispatchPopulateAccessibilityEvent(record); |
| 579 | event.appendRecord(record); |
| 580 | return true; |
| 581 | } |
| 582 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 583 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 584 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 585 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 586 | public void setDark(boolean dark, boolean fade, long delay) { |
| 587 | super.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 588 | final NotificationContentView showing = getShowingLayout(); |
| 589 | if (showing != null) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 590 | showing.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 591 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 592 | if (mIsSummaryWithChildren) { |
| 593 | mChildrenContainer.setDark(dark, fade, delay); |
| 594 | mNotificationHeaderWrapper.setDark(dark, fade, delay); |
| 595 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 598 | public boolean isExpandable() { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 599 | if (mIsSummaryWithChildren && !mShowingPublic) { |
| 600 | return !mChildrenExpanded; |
| 601 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 602 | return mExpandable; |
| 603 | } |
| 604 | |
| 605 | public void setExpandable(boolean expandable) { |
| 606 | mExpandable = expandable; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 607 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 608 | } |
| 609 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 610 | /** |
| 611 | * @return whether the user has changed the expansion state |
| 612 | */ |
| 613 | public boolean hasUserChangedExpansion() { |
| 614 | return mHasUserChangedExpansion; |
| 615 | } |
| 616 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 617 | public boolean isUserExpanded() { |
| 618 | return mUserExpanded; |
| 619 | } |
| 620 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 621 | /** |
| 622 | * Set this notification to be expanded by the user |
| 623 | * |
| 624 | * @param userExpanded whether the user wants this notification to be expanded |
| 625 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 626 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 627 | setUserExpanded(userExpanded, false /* allowChildExpansion */); |
| 628 | } |
| 629 | |
| 630 | /** |
| 631 | * Set this notification to be expanded by the user |
| 632 | * |
| 633 | * @param userExpanded whether the user wants this notification to be expanded |
| 634 | * @param allowChildExpansion whether a call to this method allows expanding children |
| 635 | */ |
| 636 | public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 637 | mFalsingManager.setNotificationExpanded(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 638 | if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) { |
| 639 | mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded); |
| 640 | return; |
| 641 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 642 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 643 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 644 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 645 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 646 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 647 | } |
| 648 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 649 | public void resetUserExpansion() { |
| 650 | mHasUserChangedExpansion = false; |
| 651 | mUserExpanded = false; |
| 652 | } |
| 653 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 654 | public boolean isUserLocked() { |
| 655 | return mUserLocked; |
| 656 | } |
| 657 | |
| 658 | public void setUserLocked(boolean userLocked) { |
| 659 | mUserLocked = userLocked; |
| 660 | } |
| 661 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 662 | /** |
| 663 | * @return has the system set this notification to be expanded |
| 664 | */ |
| 665 | public boolean isSystemExpanded() { |
| 666 | return mIsSystemExpanded; |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Set this notification to be expanded by the system. |
| 671 | * |
| 672 | * @param expand whether the system wants this notification to be expanded. |
| 673 | */ |
| 674 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 675 | if (expand != mIsSystemExpanded) { |
| 676 | final boolean wasExpanded = isExpanded(); |
| 677 | mIsSystemExpanded = expand; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 678 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 679 | logExpansionEvent(false, wasExpanded); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 680 | if (mChildrenContainer != null) { |
| 681 | mChildrenContainer.updateGroupOverflow(); |
| 682 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 683 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 687 | * @param onKeyguard whether to prevent notification expansion |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 688 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 689 | public void setOnKeyguard(boolean onKeyguard) { |
| 690 | if (onKeyguard != mOnKeyguard) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 691 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 692 | mOnKeyguard = onKeyguard; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 693 | logExpansionEvent(false, wasExpanded); |
| 694 | if (wasExpanded != isExpanded()) { |
Selim Cinek | 2108fe0 | 2015-12-10 12:56:13 -0800 | [diff] [blame] | 695 | if (mIsSummaryWithChildren) { |
| 696 | mChildrenContainer.updateGroupOverflow(); |
| 697 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 698 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 699 | } |
| 700 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /** |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 704 | * @return Can the underlying notification be cleared? |
| 705 | */ |
| 706 | public boolean isClearable() { |
Selim Cinek | a37774f | 2014-11-11 19:16:18 +0100 | [diff] [blame] | 707 | return mStatusBarNotification != null && mStatusBarNotification.isClearable(); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /** |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 711 | * Apply an expansion state to the layout. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 712 | */ |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 713 | public void applyExpansionToLayout() { |
| 714 | boolean expand = isExpanded(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 715 | if (expand && mExpandable) { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 716 | setActualHeight(mMaxExpandHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 717 | } else { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 718 | setActualHeight(mRowMinHeight); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 719 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 720 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 721 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 722 | @Override |
| 723 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 724 | if (isUserLocked()) { |
| 725 | return getActualHeight(); |
| 726 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 727 | boolean inExpansionState = isExpanded(); |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 728 | if (mSensitive && mHideSensitiveForIntrinsicHeight) { |
| 729 | return mRowMinHeight; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 730 | } else if (mIsSummaryWithChildren && !mOnKeyguard) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 731 | return mChildrenContainer.getIntrinsicHeight(); |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 732 | } else if (mIsHeadsUp) { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 733 | if (inExpansionState) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 734 | return Math.max(mMaxExpandHeight, mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 735 | } else { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 736 | return Math.max(mRowMinHeight, mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 737 | } |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 738 | } else if (!inExpansionState || (isChildInGroup() && !isGroupExpanded())) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 739 | return getMinHeight(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 740 | } else { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 741 | return getMaxExpandHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 742 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 743 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 744 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 745 | private boolean isGroupExpanded() { |
| 746 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 747 | } |
| 748 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 749 | /** |
| 750 | * @return whether this view has a header on the top of the content |
| 751 | */ |
| 752 | private boolean hasNotificationHeader() { |
| 753 | return mIsSummaryWithChildren; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 754 | } |
| 755 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 756 | private void onChildrenCountChanged() { |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 757 | mIsSummaryWithChildren = BaseStatusBar.ENABLE_CHILD_NOTIFICATIONS |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 758 | && mGroupManager.hasGroupChildren(mStatusBarNotification); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 759 | if (mIsSummaryWithChildren) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 760 | if (mChildrenContainer == null) { |
| 761 | mChildrenContainerStub.inflate(); |
| 762 | } |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 763 | if (mNotificationHeader == null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 764 | recreateNotificationHeader(); |
| 765 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 766 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 767 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 768 | updateChildrenHeaderAppearance(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 769 | updateHeaderChildCount(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 770 | updateChildrenVisibility(); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 771 | } |
| 772 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 773 | /** |
| 774 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 775 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 776 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 777 | * view can differ from this state, if layout params are modified from outside. |
| 778 | * |
| 779 | * @return whether the view state is currently expanded. |
| 780 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 781 | public boolean isExpanded() { |
| 782 | return !mOnKeyguard |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 783 | && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) |
| 784 | || isUserExpanded()); |
| 785 | } |
| 786 | |
| 787 | private boolean isSystemChildExpanded() { |
| 788 | return mIsSystemChildExpanded; |
| 789 | } |
| 790 | |
| 791 | public void setSystemChildExpanded(boolean expanded) { |
| 792 | mIsSystemChildExpanded = expanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | @Override |
| 796 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 797 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 798 | boolean updateExpandHeight = mMaxExpandHeight == 0 && !mWasReset; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 799 | updateMaxHeights(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 800 | if (updateExpandHeight) { |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 801 | applyExpansionToLayout(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 802 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 803 | mWasReset = false; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 806 | private void updateMaxHeights() { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 807 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 808 | View expandedChild = mPrivateLayout.getExpandedChild(); |
| 809 | if (expandedChild == null) { |
| 810 | expandedChild = mPrivateLayout.getContractedChild(); |
| 811 | } |
| 812 | mMaxExpandHeight = expandedChild.getHeight(); |
| 813 | View headsUpChild = mPrivateLayout.getHeadsUpChild(); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 814 | if (headsUpChild == null) { |
| 815 | headsUpChild = mPrivateLayout.getContractedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 816 | } |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 817 | mHeadsUpHeight = headsUpChild.getHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 818 | if (intrinsicBefore != getIntrinsicHeight()) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 819 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 820 | } |
| 821 | } |
| 822 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 823 | public void setSensitive(boolean sensitive) { |
| 824 | mSensitive = sensitive; |
| 825 | } |
| 826 | |
| 827 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 828 | mHideSensitiveForIntrinsicHeight = hideSensitive; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 829 | } |
| 830 | |
| 831 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 832 | long duration) { |
| 833 | boolean oldShowingPublic = mShowingPublic; |
| 834 | mShowingPublic = mSensitive && hideSensitive; |
| 835 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 836 | return; |
| 837 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 838 | |
| 839 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 840 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 841 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 842 | if (!animated) { |
| 843 | mPublicLayout.animate().cancel(); |
| 844 | mPrivateLayout.animate().cancel(); |
| 845 | mPublicLayout.setAlpha(1f); |
| 846 | mPrivateLayout.setAlpha(1f); |
| 847 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 848 | mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? View.VISIBLE |
| 849 | : View.INVISIBLE); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 850 | } else { |
| 851 | animateShowingPublic(delay, duration); |
| 852 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 853 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 854 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 855 | updateVetoButton(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 856 | mShowingPublicInitialized = true; |
| 857 | } |
| 858 | |
| 859 | private void animateShowingPublic(long delay, long duration) { |
| 860 | final View source = mShowingPublic ? mPrivateLayout : mPublicLayout; |
| 861 | View target = mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 862 | source.setVisibility(View.VISIBLE); |
| 863 | target.setVisibility(View.VISIBLE); |
| 864 | target.setAlpha(0f); |
| 865 | source.animate().cancel(); |
| 866 | target.animate().cancel(); |
| 867 | source.animate() |
| 868 | .alpha(0f) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 869 | .setStartDelay(delay) |
| 870 | .setDuration(duration) |
| 871 | .withEndAction(new Runnable() { |
| 872 | @Override |
| 873 | public void run() { |
| 874 | source.setVisibility(View.INVISIBLE); |
| 875 | } |
| 876 | }); |
| 877 | target.animate() |
| 878 | .alpha(1f) |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 879 | .setStartDelay(delay) |
| 880 | .setDuration(duration); |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | private void updateVetoButton() { |
| 884 | // public versions cannot be dismissed |
| 885 | mVetoButton.setVisibility(isClearable() && !mShowingPublic ? View.VISIBLE : View.GONE); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 886 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 887 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 888 | public void setChildrenExpanded(boolean expanded, boolean animate) { |
| 889 | mChildrenExpanded = expanded; |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 890 | if (mNotificationHeader != null) { |
| 891 | mNotificationHeader.setExpanded(expanded); |
| 892 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 893 | if (mChildrenContainer != null) { |
| 894 | mChildrenContainer.setChildrenExpanded(expanded); |
| 895 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 896 | } |
| 897 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 898 | public void updateHeaderChildCount() { |
| 899 | if (mIsSummaryWithChildren) { |
| 900 | mNotificationHeader.setChildCount( |
| 901 | mChildrenContainer.getNotificationChildren().size()); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 902 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | public static void applyTint(View v, int color) { |
| 906 | int alpha; |
| 907 | if (color != 0) { |
| 908 | alpha = COLORED_DIVIDER_ALPHA; |
| 909 | } else { |
| 910 | color = 0xff000000; |
| 911 | alpha = DEFAULT_DIVIDER_ALPHA; |
| 912 | } |
| 913 | if (v.getBackground() instanceof ColorDrawable) { |
| 914 | ColorDrawable background = (ColorDrawable) v.getBackground(); |
| 915 | background.mutate(); |
| 916 | background.setColor(color); |
| 917 | background.setAlpha(alpha); |
| 918 | } |
| 919 | } |
| 920 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 921 | public int getMaxExpandHeight() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 922 | return mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 923 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 924 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 925 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 926 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 927 | NotificationContentView showingLayout = getShowingLayout(); |
| 928 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | @Override |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 932 | protected View getContentView() { |
| 933 | return getShowingLayout(); |
| 934 | } |
| 935 | |
| 936 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 937 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 938 | super.setActualHeight(height, notifyListeners); |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 939 | int contentHeight = Math.max(getMinHeight(), height); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 940 | mPrivateLayout.setContentHeight(contentHeight); |
| 941 | mPublicLayout.setContentHeight(contentHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 942 | if (mGuts != null) { |
| 943 | mGuts.setActualHeight(height); |
| 944 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 945 | invalidate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 949 | public int getMaxContentHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 950 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 951 | return mChildrenContainer.getMaxContentHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 952 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 953 | NotificationContentView showingLayout = getShowingLayout(); |
| 954 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 955 | } |
| 956 | |
| 957 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 958 | public int getMinHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 959 | NotificationContentView showingLayout = getShowingLayout(); |
| 960 | return showingLayout.getMinHeight(); |
| 961 | } |
| 962 | |
| 963 | @Override |
| 964 | public int getMinExpandHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 965 | if (mIsSummaryWithChildren && !mOnKeyguard) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 966 | return mChildrenContainer.getMinHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 967 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 968 | return getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 969 | } |
| 970 | |
| 971 | @Override |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 972 | protected boolean shouldLimitViewHeight() { |
| 973 | return !mIsSummaryWithChildren; |
| 974 | } |
| 975 | |
| 976 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 977 | public void setClipTopAmount(int clipTopAmount) { |
| 978 | super.setClipTopAmount(clipTopAmount); |
| 979 | mPrivateLayout.setClipTopAmount(clipTopAmount); |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 980 | mPublicLayout.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 981 | if (mGuts != null) { |
| 982 | mGuts.setClipTopAmount(clipTopAmount); |
| 983 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 984 | } |
| 985 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 986 | private void recreateNotificationHeader() { |
| 987 | final Notification.Builder builder = Notification.Builder.recoverBuilder(getContext(), |
| 988 | getStatusBarNotification().getNotification()); |
| 989 | final RemoteViews header = builder.makeNotificationHeader(); |
| 990 | if (mNotificationHeader == null) { |
| 991 | mNotificationHeader = (NotificationHeaderView) header.apply(getContext(), this); |
| 992 | final View expandButton = mNotificationHeader.findViewById( |
| 993 | com.android.internal.R.id.expand_button); |
| 994 | expandButton.setVisibility(VISIBLE); |
| 995 | mNotificationHeader.setOnClickListener(mExpandClickListener); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 996 | mNotificationHeaderWrapper = NotificationViewWrapper.wrap(getContext(), |
| 997 | mNotificationHeader); |
Selim Cinek | b5a8361 | 2015-12-11 14:14:39 -0800 | [diff] [blame] | 998 | addView(mNotificationHeader, indexOfChild(mChildrenContainer) + 1); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 999 | } else { |
| 1000 | header.reapply(getContext(), mNotificationHeader); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1001 | mNotificationHeaderWrapper.notifyContentUpdated(); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1002 | } |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 1003 | updateHeaderExpandButton(); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1004 | updateChildrenHeaderAppearance(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1005 | updateHeaderChildCount(); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 1006 | } |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 1007 | |
Selim Cinek | 7b83639 | 2015-12-04 20:02:59 -0800 | [diff] [blame] | 1008 | private void updateHeaderExpandButton() { |
| 1009 | if (mIsSummaryWithChildren) { |
| 1010 | mNotificationHeader.setIsGroupHeader(true /* isGroupHeader*/); |
| 1011 | } |
| 1012 | } |
| 1013 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1014 | public void updateChildrenHeaderAppearance() { |
| 1015 | if (mIsSummaryWithChildren) { |
| 1016 | mHeaderUtil.updateChildrenHeaderAppearance(); |
| 1017 | } |
| 1018 | } |
| 1019 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1020 | public boolean isMaxExpandHeightInitialized() { |
| 1021 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 1022 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1023 | |
| 1024 | private NotificationContentView getShowingLayout() { |
| 1025 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 1026 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1027 | |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1028 | @Override |
| 1029 | public void setShowingLegacyBackground(boolean showing) { |
| 1030 | super.setShowingLegacyBackground(showing); |
| 1031 | mPrivateLayout.setShowingLegacyBackground(showing); |
| 1032 | mPublicLayout.setShowingLegacyBackground(showing); |
| 1033 | } |
| 1034 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1035 | @Override |
| 1036 | protected void updateBackgroundTint() { |
| 1037 | super.updateBackgroundTint(); |
| 1038 | updateNoBackgroundState(); |
| 1039 | if (mIsSummaryWithChildren) { |
| 1040 | List<ExpandableNotificationRow> notificationChildren = |
| 1041 | mChildrenContainer.getNotificationChildren(); |
| 1042 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 1043 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 1044 | child.updateNoBackgroundState(); |
| 1045 | } |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | private void updateNoBackgroundState() { |
| 1050 | mShowNoBackground = isChildInGroup() && hasSameBgColor(mNotificationParent); |
| 1051 | updateBackground(); |
| 1052 | } |
| 1053 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1054 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 1055 | mLogger = logger; |
| 1056 | mLoggingKey = key; |
| 1057 | } |
| 1058 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1059 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
| 1060 | final boolean nowExpanded = isExpanded(); |
| 1061 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 1062 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 1063 | } |
| 1064 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1065 | |
| 1066 | public interface OnExpandClickListener { |
| 1067 | void onExpandClicked(View clickedView, boolean nowExpanded); |
| 1068 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1069 | } |