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