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