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