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