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