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