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