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