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