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