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