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