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