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