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