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