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; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 21 | import android.animation.ObjectAnimator; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 22 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 23 | import android.annotation.Nullable; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 24 | import android.content.Context; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 25 | import android.content.res.ColorStateList; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 26 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 27 | import android.graphics.drawable.AnimationDrawable; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 28 | import android.graphics.drawable.ColorDrawable; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 29 | import android.graphics.drawable.Drawable; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 30 | import android.os.Build; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 31 | import android.os.Bundle; |
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; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 34 | import android.util.FloatProperty; |
| 35 | import android.util.Property; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 36 | import android.view.LayoutInflater; |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 37 | import android.view.MotionEvent; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 38 | import android.view.NotificationHeaderView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 39 | import android.view.View; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 40 | import android.view.ViewGroup; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 41 | import android.view.ViewStub; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 42 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 43 | import android.view.accessibility.AccessibilityNodeInfo; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 44 | import android.widget.Chronometer; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 45 | import android.widget.ImageView; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 46 | |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 47 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 48 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 49 | import com.android.internal.util.NotificationColorUtil; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 50 | import com.android.internal.widget.CachingIconView; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 51 | import com.android.systemui.Interpolators; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 52 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 53 | import com.android.systemui.classifier.FalsingManager; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 54 | import com.android.systemui.plugins.statusbar.NotificationMenuRowProvider.MenuItem; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 55 | import com.android.systemui.statusbar.notification.HybridNotificationView; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 56 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 57 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 58 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.phone.StatusBar; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 60 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 61 | import com.android.systemui.statusbar.stack.AnimationProperties; |
| 62 | import com.android.systemui.statusbar.stack.ExpandableViewState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 63 | import com.android.systemui.statusbar.stack.NotificationChildrenContainer; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 64 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 65 | import com.android.systemui.statusbar.stack.StackScrollState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 66 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 67 | import java.util.ArrayList; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 68 | import java.util.List; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 69 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 70 | public class ExpandableNotificationRow extends ActivatableNotificationView { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 71 | |
| 72 | private static final int DEFAULT_DIVIDER_ALPHA = 0x29; |
| 73 | private static final int COLORED_DIVIDER_ALPHA = 0x7B; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 74 | private int mIconTransformContentShift; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 75 | private int mIconTransformContentShiftNoIcon; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 76 | private int mNotificationMinHeightLegacy; |
| 77 | private int mMaxHeadsUpHeightLegacy; |
| 78 | private int mMaxHeadsUpHeight; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 79 | private int mMaxHeadsUpHeightIncreased; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 80 | private int mNotificationMinHeight; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 81 | private int mNotificationMinHeightLarge; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 82 | private int mNotificationMaxHeight; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 83 | private int mNotificationAmbientHeight; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 84 | private int mIncreasedPaddingBetweenElements; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 85 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 86 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 87 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 88 | /** Has the user actively changed the expansion state of this row */ |
| 89 | private boolean mHasUserChangedExpansion; |
| 90 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 91 | private boolean mUserExpanded; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 92 | |
| 93 | /** |
| 94 | * Has this notification been expanded while it was pinned |
| 95 | */ |
| 96 | private boolean mExpandedWhenPinned; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 97 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 98 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 99 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 100 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 101 | private boolean mSensitive; |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 102 | private boolean mSensitiveHiddenInGeneral; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 103 | private boolean mShowingPublicInitialized; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 104 | private boolean mHideSensitiveForIntrinsicHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 105 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 106 | /** |
| 107 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 108 | * user expansion. |
| 109 | */ |
| 110 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 111 | |
| 112 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 113 | * Whether the notification is on the keyguard and the expansion is disabled. |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 114 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 115 | private boolean mOnKeyguard; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 116 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 117 | private Animator mTranslateAnim; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 118 | private ArrayList<View> mTranslateableViews; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 119 | private NotificationContentView mPublicLayout; |
| 120 | private NotificationContentView mPrivateLayout; |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 121 | private NotificationContentView[] mLayouts; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 122 | private int mMaxExpandHeight; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 123 | private int mHeadsUpHeight; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 124 | private int mNotificationColor; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 125 | private ExpansionLogger mLogger; |
| 126 | private String mLoggingKey; |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 127 | private NotificationMenuRow mMenuRow; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 128 | private NotificationGuts mGuts; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 129 | private NotificationData.Entry mEntry; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 130 | private StatusBarNotification mStatusBarNotification; |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 131 | private String mAppName; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 132 | private boolean mIsHeadsUp; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 133 | private boolean mLastChronometerRunning = true; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 134 | private ViewStub mChildrenContainerStub; |
| 135 | private NotificationGroupManager mGroupManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 136 | private boolean mChildrenExpanded; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 137 | private boolean mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 138 | private NotificationChildrenContainer mChildrenContainer; |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 139 | private ViewStub mMenuRowStub; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 140 | private ViewStub mGutsStub; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 141 | private boolean mIsSystemChildExpanded; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 142 | private boolean mIsPinned; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 143 | private FalsingManager mFalsingManager; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 144 | private HeadsUpManager mHeadsUpManager; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 145 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 146 | private boolean mJustClicked; |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 147 | private boolean mIconAnimationRunning; |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 148 | private boolean mShowNoBackground; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 149 | private ExpandableNotificationRow mNotificationParent; |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 150 | private OnExpandClickListener mOnExpandClickListener; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 151 | private boolean mGroupExpansionChanging; |
| 152 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 153 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 154 | @Override |
| 155 | public void onClick(View v) { |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 156 | if (!mShowingPublic && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) { |
Mady Mellor | 1a5d8ea | 2016-06-09 10:42:42 -0700 | [diff] [blame] | 157 | mGroupExpansionChanging = true; |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 158 | final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
| 159 | boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification); |
| 160 | mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 161 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER, |
| 162 | nowExpanded); |
| 163 | logExpansionEvent(true /* userAction */, wasExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 164 | } else { |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 165 | if (v.isAccessibilityFocused()) { |
| 166 | mPrivateLayout.setFocusOnVisibilityChange(); |
| 167 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 168 | boolean nowExpanded; |
| 169 | if (isPinned()) { |
| 170 | nowExpanded = !mExpandedWhenPinned; |
| 171 | mExpandedWhenPinned = nowExpanded; |
| 172 | } else { |
| 173 | nowExpanded = !isExpanded(); |
| 174 | setUserExpanded(nowExpanded); |
| 175 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 176 | notifyHeightChanged(true); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 177 | mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 178 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER, |
| 179 | nowExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | }; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 183 | private boolean mForceUnlocked; |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 184 | private boolean mDismissed; |
| 185 | private boolean mKeepInParent; |
| 186 | private boolean mRemoved; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 187 | private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT = |
| 188 | new FloatProperty<ExpandableNotificationRow>("translate") { |
| 189 | @Override |
| 190 | public void setValue(ExpandableNotificationRow object, float value) { |
| 191 | object.setTranslation(value); |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public Float get(ExpandableNotificationRow object) { |
| 196 | return object.getTranslation(); |
| 197 | } |
| 198 | }; |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 199 | private OnClickListener mOnClickListener; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 200 | private boolean mHeadsupDisappearRunning; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 201 | private View mChildAfterViewWhenDismissed; |
| 202 | private View mGroupParentWhenDismissed; |
| 203 | private boolean mRefocusOnDismiss; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 204 | private float mContentTransformationAmount; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 205 | private boolean mIconsVisible = true; |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 206 | private boolean mAboveShelf; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 207 | private boolean mShowAmbient; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 208 | private boolean mIsLastChild; |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 209 | private Runnable mOnDismissRunnable; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 210 | private boolean mIsLowPriority; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 211 | private boolean mIsColorized; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 212 | private boolean mUseIncreasedCollapsedHeight; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 213 | private boolean mUseIncreasedHeadsUpHeight; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 214 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 215 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 216 | public boolean isGroupExpansionChanging() { |
| 217 | if (isChildInGroup()) { |
| 218 | return mNotificationParent.isGroupExpansionChanging(); |
| 219 | } |
| 220 | return mGroupExpansionChanging; |
| 221 | } |
| 222 | |
| 223 | public void setGroupExpansionChanging(boolean changing) { |
| 224 | mGroupExpansionChanging = changing; |
| 225 | } |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 226 | |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 227 | @Override |
| 228 | public void setActualHeightAnimating(boolean animating) { |
| 229 | if (mPrivateLayout != null) { |
| 230 | mPrivateLayout.setContentHeightAnimating(animating); |
| 231 | } |
| 232 | } |
| 233 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 234 | public NotificationContentView getPrivateLayout() { |
| 235 | return mPrivateLayout; |
| 236 | } |
| 237 | |
| 238 | public NotificationContentView getPublicLayout() { |
| 239 | return mPublicLayout; |
| 240 | } |
| 241 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 242 | public void setIconAnimationRunning(boolean running) { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 243 | for (NotificationContentView l : mLayouts) { |
| 244 | setIconAnimationRunning(running, l); |
| 245 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 246 | if (mIsSummaryWithChildren) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 247 | setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView()); |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 248 | List<ExpandableNotificationRow> notificationChildren = |
| 249 | mChildrenContainer.getNotificationChildren(); |
| 250 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 251 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 252 | child.setIconAnimationRunning(running); |
| 253 | } |
| 254 | } |
| 255 | mIconAnimationRunning = running; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 259 | if (layout != null) { |
| 260 | View contractedChild = layout.getContractedChild(); |
| 261 | View expandedChild = layout.getExpandedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 262 | View headsUpChild = layout.getHeadsUpChild(); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 263 | setIconAnimationRunningForChild(running, contractedChild); |
| 264 | setIconAnimationRunningForChild(running, expandedChild); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 265 | setIconAnimationRunningForChild(running, headsUpChild); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 270 | if (child != null) { |
| 271 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 272 | setIconRunning(icon, running); |
| 273 | ImageView rightIcon = (ImageView) child.findViewById( |
| 274 | com.android.internal.R.id.right_icon); |
| 275 | setIconRunning(rightIcon, running); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | private void setIconRunning(ImageView imageView, boolean running) { |
| 280 | if (imageView != null) { |
| 281 | Drawable drawable = imageView.getDrawable(); |
| 282 | if (drawable instanceof AnimationDrawable) { |
| 283 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 284 | if (running) { |
| 285 | animationDrawable.start(); |
| 286 | } else { |
| 287 | animationDrawable.stop(); |
| 288 | } |
| 289 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 290 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 291 | if (running) { |
| 292 | animationDrawable.start(); |
| 293 | } else { |
| 294 | animationDrawable.stop(); |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | } |
| 299 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 300 | public void onNotificationUpdated(NotificationData.Entry entry) { |
| 301 | mEntry = entry; |
| 302 | mStatusBarNotification = entry.notification; |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 303 | for (NotificationContentView l : mLayouts) { |
| 304 | l.onNotificationUpdated(entry); |
| 305 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 306 | mIsColorized = mStatusBarNotification.getNotification().isColorized(); |
Selim Cinek | 757d879 | 2016-01-28 16:21:08 -0800 | [diff] [blame] | 307 | mShowingPublicInitialized = false; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 308 | updateNotificationColor(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 309 | if (mIsSummaryWithChildren) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 310 | mChildrenContainer.recreateNotificationHeader(mExpandClickListener, mEntry.notification); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 311 | mChildrenContainer.onNotificationUpdated(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 312 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 313 | if (mIconAnimationRunning) { |
| 314 | setIconAnimationRunning(true); |
| 315 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 316 | if (mNotificationParent != null) { |
| 317 | mNotificationParent.updateChildrenHeaderAppearance(); |
| 318 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 319 | onChildrenCountChanged(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 320 | // The public layouts expand button is always visible |
| 321 | mPublicLayout.updateExpandButtons(true); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 322 | updateLimits(); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 323 | updateIconVisibilities(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 324 | updateShelfIconColor(); |
| 325 | } |
| 326 | |
| 327 | private void updateShelfIconColor() { |
| 328 | StatusBarIconView expandedIcon = mEntry.expandedIcon; |
| 329 | boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L)); |
| 330 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon, |
| 331 | NotificationColorUtil.getInstance(mContext)); |
| 332 | if (colorize) { |
| 333 | int color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded()); |
| 334 | expandedIcon.setImageTintList(ColorStateList.valueOf(color)); |
| 335 | } |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | private void updateLimits() { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 339 | for (NotificationContentView l : mLayouts) { |
| 340 | updateLimitsForView(l); |
| 341 | } |
Selim Cinek | a174487 | 2016-03-11 15:36:06 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | private void updateLimitsForView(NotificationContentView layout) { |
| 345 | boolean customView = layout.getContractedChild().getId() |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 346 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 347 | boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 348 | int minHeight; |
| 349 | if (customView && beforeN && !mIsSummaryWithChildren) { |
| 350 | minHeight = mNotificationMinHeightLegacy; |
| 351 | } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) { |
| 352 | minHeight = mNotificationMinHeightLarge; |
| 353 | } else { |
| 354 | minHeight = mNotificationMinHeight; |
| 355 | } |
Selim Cinek | a174487 | 2016-03-11 15:36:06 -0800 | [diff] [blame] | 356 | boolean headsUpCustom = layout.getHeadsUpChild() != null && |
| 357 | layout.getHeadsUpChild().getId() |
| 358 | != com.android.internal.R.id.status_bar_latest_event_content; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 359 | int headsUpheight; |
| 360 | if (headsUpCustom && beforeN) { |
| 361 | headsUpheight = mMaxHeadsUpHeightLegacy; |
| 362 | } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) { |
| 363 | headsUpheight = mMaxHeadsUpHeightIncreased; |
| 364 | } else { |
| 365 | headsUpheight = mMaxHeadsUpHeight; |
| 366 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 367 | layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight, |
| 368 | mNotificationAmbientHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | public StatusBarNotification getStatusBarNotification() { |
| 372 | return mStatusBarNotification; |
| 373 | } |
| 374 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 375 | public NotificationData.Entry getEntry() { |
| 376 | return mEntry; |
| 377 | } |
| 378 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 379 | public boolean isHeadsUp() { |
| 380 | return mIsHeadsUp; |
| 381 | } |
| 382 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 383 | public void setHeadsUp(boolean isHeadsUp) { |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 384 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 385 | mIsHeadsUp = isHeadsUp; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 386 | mPrivateLayout.setHeadsUp(isHeadsUp); |
Selim Cinek | b41b2f6 | 2016-04-26 14:03:29 -0700 | [diff] [blame] | 387 | if (mIsSummaryWithChildren) { |
| 388 | // The overflow might change since we allow more lines as HUN. |
| 389 | mChildrenContainer.updateGroupOverflow(); |
| 390 | } |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 391 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 392 | notifyHeightChanged(false /* needsAnimation */); |
| 393 | } |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 394 | if (isHeadsUp) { |
| 395 | setAboveShelf(true); |
| 396 | } |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 397 | } |
| 398 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 399 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 400 | mGroupManager = groupManager; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 401 | mPrivateLayout.setGroupManager(groupManager); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 402 | } |
| 403 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 404 | public void setRemoteInputController(RemoteInputController r) { |
| 405 | mPrivateLayout.setRemoteInputController(r); |
| 406 | } |
| 407 | |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 408 | public void setAppName(String appName) { |
| 409 | mAppName = appName; |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 410 | if (mMenuRow != null) { |
| 411 | mMenuRow.setAppName(mAppName); |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 412 | } |
| 413 | } |
| 414 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 415 | public void addChildNotification(ExpandableNotificationRow row) { |
| 416 | addChildNotification(row, -1); |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Add a child notification to this view. |
| 421 | * |
| 422 | * @param row the row to add |
| 423 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 424 | */ |
| 425 | public void addChildNotification(ExpandableNotificationRow row, int childIndex) { |
| 426 | if (mChildrenContainer == null) { |
| 427 | mChildrenContainerStub.inflate(); |
| 428 | } |
| 429 | mChildrenContainer.addNotification(row, childIndex); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 430 | onChildrenCountChanged(); |
| 431 | row.setIsChildInGroup(true, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | public void removeChildNotification(ExpandableNotificationRow row) { |
| 435 | if (mChildrenContainer != null) { |
| 436 | mChildrenContainer.removeNotification(row); |
| 437 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 438 | onChildrenCountChanged(); |
| 439 | row.setIsChildInGroup(false, null); |
| 440 | } |
| 441 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 442 | @Override |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 443 | public boolean isChildInGroup() { |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 444 | return mNotificationParent != null; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 447 | public ExpandableNotificationRow getNotificationParent() { |
| 448 | return mNotificationParent; |
| 449 | } |
| 450 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 451 | /** |
| 452 | * @param isChildInGroup Is this notification now in a group |
| 453 | * @param parent the new parent notification |
| 454 | */ |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 455 | public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) {; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 456 | boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup; |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 457 | mNotificationParent = childInGroup ? parent : null; |
| 458 | mPrivateLayout.setIsChildInGroup(childInGroup); |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 459 | resetBackgroundAlpha(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 460 | updateBackgroundForGroupState(); |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 461 | updateClickAndFocus(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 462 | if (mNotificationParent != null) { |
| 463 | mNotificationParent.updateBackgroundForGroupState(); |
| 464 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 465 | updateIconVisibilities(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | @Override |
Selim Cinek | 7210947 | 2016-01-15 16:33:22 -0800 | [diff] [blame] | 469 | public boolean onTouchEvent(MotionEvent event) { |
| 470 | if (event.getActionMasked() != MotionEvent.ACTION_DOWN |
| 471 | || !isChildInGroup() || isGroupExpanded()) { |
| 472 | return super.onTouchEvent(event); |
| 473 | } else { |
| 474 | return false; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | @Override |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 479 | protected boolean handleSlideBack() { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 480 | if (mMenuRow != null && mMenuRow.isVisible()) { |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 481 | animateTranslateNotification(0 /* targetLeft */); |
| 482 | return true; |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | |
| 487 | @Override |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 488 | protected boolean shouldHideBackground() { |
| 489 | return super.shouldHideBackground() || mShowNoBackground; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | @Override |
| 493 | public boolean isSummaryWithChildren() { |
| 494 | return mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 495 | } |
| 496 | |
| 497 | @Override |
| 498 | public boolean areChildrenExpanded() { |
| 499 | return mChildrenExpanded; |
| 500 | } |
| 501 | |
| 502 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 503 | return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren(); |
| 504 | } |
| 505 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 506 | public int getNumberOfNotificationChildren() { |
| 507 | if (mChildrenContainer == null) { |
| 508 | return 0; |
| 509 | } |
| 510 | return mChildrenContainer.getNotificationChildren().size(); |
| 511 | } |
| 512 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 513 | /** |
| 514 | * Apply the order given in the list to the children. |
| 515 | * |
| 516 | * @param childOrder the new list order |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 517 | * @param visualStabilityManager |
| 518 | * @param callback the callback to invoked in case it is not allowed |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 519 | * @return whether the list order has changed |
| 520 | */ |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 521 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder, |
| 522 | VisualStabilityManager visualStabilityManager, |
| 523 | VisualStabilityManager.Callback callback) { |
| 524 | return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder, |
| 525 | visualStabilityManager, callback); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | public void getChildrenStates(StackScrollState resultState) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 529 | if (mIsSummaryWithChildren) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 530 | ExpandableViewState parentState = resultState.getViewStateForView(this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 531 | mChildrenContainer.getState(resultState, parentState); |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | public void applyChildrenState(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 536 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 537 | mChildrenContainer.applyState(state); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | public void prepareExpansionChanged(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 542 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 543 | mChildrenContainer.prepareExpansionChanged(state); |
| 544 | } |
| 545 | } |
| 546 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 547 | public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 548 | if (mIsSummaryWithChildren) { |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 549 | mChildrenContainer.startAnimationToState(finalState, properties); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | |
| 553 | public ExpandableNotificationRow getViewAtPosition(float y) { |
Selim Cinek | 43d30f0 | 2016-03-04 10:51:32 -0800 | [diff] [blame] | 554 | if (!mIsSummaryWithChildren || !mChildrenExpanded) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 555 | return this; |
| 556 | } else { |
| 557 | ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y); |
| 558 | return view == null ? this : view; |
| 559 | } |
| 560 | } |
| 561 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 562 | public NotificationGuts getGuts() { |
| 563 | return mGuts; |
| 564 | } |
| 565 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 566 | /** |
| 567 | * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this |
| 568 | * the notification will be rendered on top of the screen. |
| 569 | * |
| 570 | * @param pinned whether it is pinned |
| 571 | */ |
| 572 | public void setPinned(boolean pinned) { |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 573 | int intrinsicHeight = getIntrinsicHeight(); |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 574 | mIsPinned = pinned; |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 575 | if (intrinsicHeight != getIntrinsicHeight()) { |
Selim Cinek | bb42b7d | 2016-08-10 13:02:38 -0700 | [diff] [blame] | 576 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 577 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 578 | if (pinned) { |
| 579 | setIconAnimationRunning(true); |
| 580 | mExpandedWhenPinned = false; |
| 581 | } else if (mExpandedWhenPinned) { |
| 582 | setUserExpanded(true); |
| 583 | } |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 584 | setChronometerRunning(mLastChronometerRunning); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 587 | public boolean isPinned() { |
| 588 | return mIsPinned; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 589 | } |
| 590 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 591 | @Override |
| 592 | public int getPinnedHeadsUpHeight() { |
| 593 | return getPinnedHeadsUpHeight(true /* atLeastMinHeight */); |
| 594 | } |
| 595 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 596 | /** |
| 597 | * @param atLeastMinHeight should the value returned be at least the minimum height. |
| 598 | * Used to avoid cyclic calls |
| 599 | * @return the height of the heads up notification when pinned |
| 600 | */ |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 601 | private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) { |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 602 | if (mIsSummaryWithChildren) { |
| 603 | return mChildrenContainer.getIntrinsicHeight(); |
| 604 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 605 | if(mExpandedWhenPinned) { |
| 606 | return Math.max(getMaxExpandHeight(), mHeadsUpHeight); |
| 607 | } else if (atLeastMinHeight) { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 608 | return Math.max(getCollapsedHeight(), mHeadsUpHeight); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 609 | } else { |
| 610 | return mHeadsUpHeight; |
| 611 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 612 | } |
| 613 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 614 | /** |
| 615 | * Mark whether this notification was just clicked, i.e. the user has just clicked this |
| 616 | * notification in this frame. |
| 617 | */ |
| 618 | public void setJustClicked(boolean justClicked) { |
| 619 | mJustClicked = justClicked; |
| 620 | } |
| 621 | |
| 622 | /** |
| 623 | * @return true if this notification has been clicked in this frame, false otherwise |
| 624 | */ |
| 625 | public boolean wasJustClicked() { |
| 626 | return mJustClicked; |
| 627 | } |
| 628 | |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 629 | public void setChronometerRunning(boolean running) { |
| 630 | mLastChronometerRunning = running; |
| 631 | setChronometerRunning(running, mPrivateLayout); |
| 632 | setChronometerRunning(running, mPublicLayout); |
| 633 | if (mChildrenContainer != null) { |
| 634 | List<ExpandableNotificationRow> notificationChildren = |
| 635 | mChildrenContainer.getNotificationChildren(); |
| 636 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 637 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 638 | child.setChronometerRunning(running); |
| 639 | } |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | private void setChronometerRunning(boolean running, NotificationContentView layout) { |
| 644 | if (layout != null) { |
| 645 | running = running || isPinned(); |
| 646 | View contractedChild = layout.getContractedChild(); |
| 647 | View expandedChild = layout.getExpandedChild(); |
| 648 | View headsUpChild = layout.getHeadsUpChild(); |
| 649 | setChronometerRunningForChild(running, contractedChild); |
| 650 | setChronometerRunningForChild(running, expandedChild); |
| 651 | setChronometerRunningForChild(running, headsUpChild); |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | private void setChronometerRunningForChild(boolean running, View child) { |
| 656 | if (child != null) { |
| 657 | View chronometer = child.findViewById(com.android.internal.R.id.chronometer); |
| 658 | if (chronometer instanceof Chronometer) { |
| 659 | ((Chronometer) chronometer).setStarted(running); |
| 660 | } |
| 661 | } |
| 662 | } |
| 663 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 664 | public NotificationHeaderView getNotificationHeader() { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 665 | if (mIsSummaryWithChildren) { |
| 666 | return mChildrenContainer.getHeaderView(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 667 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 668 | return mPrivateLayout.getNotificationHeader(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 671 | private NotificationHeaderView getVisibleNotificationHeader() { |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 672 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 673 | return mChildrenContainer.getHeaderView(); |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 674 | } |
| 675 | return getShowingLayout().getVisibleNotificationHeader(); |
| 676 | } |
| 677 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 678 | public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) { |
| 679 | mOnExpandClickListener = onExpandClickListener; |
| 680 | } |
| 681 | |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 682 | @Override |
| 683 | public void setOnClickListener(@Nullable OnClickListener l) { |
| 684 | super.setOnClickListener(l); |
| 685 | mOnClickListener = l; |
| 686 | updateClickAndFocus(); |
| 687 | } |
| 688 | |
| 689 | private void updateClickAndFocus() { |
| 690 | boolean normalChild = !isChildInGroup() || isGroupExpanded(); |
| 691 | boolean clickable = mOnClickListener != null && normalChild; |
| 692 | if (isFocusable() != normalChild) { |
| 693 | setFocusable(normalChild); |
| 694 | } |
| 695 | if (isClickable() != clickable) { |
| 696 | setClickable(clickable); |
| 697 | } |
| 698 | } |
| 699 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 700 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 701 | mHeadsUpManager = headsUpManager; |
| 702 | } |
| 703 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 704 | public void setGutsView(MenuItem item) { |
| 705 | if (mGuts != null) { |
| 706 | item.gutsContent.setInteractionListener(mGuts); |
| 707 | mGuts.setGutsContent(item.gutsContent); |
| 708 | } |
| 709 | } |
| 710 | |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 711 | public void reInflateViews() { |
| 712 | initDimens(); |
| 713 | if (mIsSummaryWithChildren) { |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 714 | if (mChildrenContainer != null) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 715 | mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 716 | } |
| 717 | } |
| 718 | if (mGuts != null) { |
| 719 | View oldGuts = mGuts; |
| 720 | int index = indexOfChild(oldGuts); |
| 721 | removeView(oldGuts); |
| 722 | mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate( |
| 723 | R.layout.notification_guts, this, false); |
| 724 | mGuts.setVisibility(oldGuts.getVisibility()); |
| 725 | addView(mGuts, index); |
| 726 | } |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 727 | if (mMenuRow != null) { |
| 728 | View oldMenu = mMenuRow; |
| 729 | int menuIndex = indexOfChild(oldMenu); |
| 730 | removeView(oldMenu); |
| 731 | mMenuRow = (NotificationMenuRow) LayoutInflater.from(mContext).inflate( |
| 732 | R.layout.notification_menu_row, this, false); |
| 733 | mMenuRow.setNotificationRowParent(ExpandableNotificationRow.this); |
| 734 | mMenuRow.setAppName(mAppName); |
| 735 | mMenuRow.setVisibility(oldMenu.getVisibility()); |
| 736 | addView(mMenuRow, menuIndex); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 737 | |
| 738 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 739 | for (NotificationContentView l : mLayouts) { |
| 740 | l.reInflateViews(); |
| 741 | } |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 744 | public void setContentBackground(int customBackgroundColor, boolean animate, |
| 745 | NotificationContentView notificationContentView) { |
| 746 | if (getShowingLayout() == notificationContentView) { |
| 747 | setTintColor(customBackgroundColor, animate); |
| 748 | } |
| 749 | } |
| 750 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 751 | public void closeRemoteInput() { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 752 | for (NotificationContentView l : mLayouts) { |
| 753 | l.closeRemoteInput(); |
| 754 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 755 | } |
| 756 | |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 757 | /** |
| 758 | * Set by how much the single line view should be indented. |
| 759 | */ |
| 760 | public void setSingleLineWidthIndention(int indention) { |
| 761 | mPrivateLayout.setSingleLineWidthIndention(indention); |
| 762 | } |
| 763 | |
| 764 | public int getNotificationColor() { |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 765 | return mNotificationColor; |
| 766 | } |
| 767 | |
| 768 | private void updateNotificationColor() { |
| 769 | mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext, |
| 770 | getStatusBarNotification().getNotification().color); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 771 | } |
| 772 | |
| 773 | public HybridNotificationView getSingleLineView() { |
| 774 | return mPrivateLayout.getSingleLineView(); |
| 775 | } |
| 776 | |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 777 | public boolean isOnKeyguard() { |
| 778 | return mOnKeyguard; |
| 779 | } |
| 780 | |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 781 | public void removeAllChildren() { |
| 782 | List<ExpandableNotificationRow> notificationChildren |
| 783 | = mChildrenContainer.getNotificationChildren(); |
| 784 | ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren); |
| 785 | for (int i = 0; i < clonedList.size(); i++) { |
| 786 | ExpandableNotificationRow row = clonedList.get(i); |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 787 | if (row.keepInParent()) { |
| 788 | continue; |
| 789 | } |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 790 | mChildrenContainer.removeNotification(row); |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 791 | row.setIsChildInGroup(false, null); |
| 792 | } |
| 793 | onChildrenCountChanged(); |
| 794 | } |
| 795 | |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 796 | public void setForceUnlocked(boolean forceUnlocked) { |
| 797 | mForceUnlocked = forceUnlocked; |
| 798 | if (mIsSummaryWithChildren) { |
| 799 | List<ExpandableNotificationRow> notificationChildren = getNotificationChildren(); |
| 800 | for (ExpandableNotificationRow child : notificationChildren) { |
| 801 | child.setForceUnlocked(forceUnlocked); |
| 802 | } |
| 803 | } |
| 804 | } |
| 805 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 806 | public void setDismissed(boolean dismissed, boolean fromAccessibility) { |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 807 | mDismissed = dismissed; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 808 | mGroupParentWhenDismissed = mNotificationParent; |
| 809 | mRefocusOnDismiss = fromAccessibility; |
| 810 | mChildAfterViewWhenDismissed = null; |
| 811 | if (isChildInGroup()) { |
| 812 | List<ExpandableNotificationRow> notificationChildren = |
| 813 | mNotificationParent.getNotificationChildren(); |
| 814 | int i = notificationChildren.indexOf(this); |
| 815 | if (i != -1 && i < notificationChildren.size() - 1) { |
| 816 | mChildAfterViewWhenDismissed = notificationChildren.get(i + 1); |
| 817 | } |
| 818 | } |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | public boolean isDismissed() { |
| 822 | return mDismissed; |
| 823 | } |
| 824 | |
| 825 | public boolean keepInParent() { |
| 826 | return mKeepInParent; |
| 827 | } |
| 828 | |
| 829 | public void setKeepInParent(boolean keepInParent) { |
| 830 | mKeepInParent = keepInParent; |
| 831 | } |
| 832 | |
| 833 | public boolean isRemoved() { |
| 834 | return mRemoved; |
| 835 | } |
| 836 | |
Adrian Roos | d009ab1 | 2016-05-20 17:58:53 -0700 | [diff] [blame] | 837 | public void setRemoved() { |
| 838 | mRemoved = true; |
| 839 | |
| 840 | mPrivateLayout.setRemoved(); |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 841 | } |
| 842 | |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 843 | public NotificationChildrenContainer getChildrenContainer() { |
| 844 | return mChildrenContainer; |
| 845 | } |
| 846 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 847 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 848 | mHeadsupDisappearRunning = headsUpAnimatingAway; |
| 849 | mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * @return if the view was just heads upped and is now animating away. During such a time the |
| 854 | * layout needs to be kept consistent |
| 855 | */ |
| 856 | public boolean isHeadsUpAnimatingAway() { |
| 857 | return mHeadsupDisappearRunning; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 858 | } |
| 859 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 860 | public View getChildAfterViewWhenDismissed() { |
| 861 | return mChildAfterViewWhenDismissed; |
| 862 | } |
| 863 | |
| 864 | public View getGroupParentWhenDismissed() { |
| 865 | return mGroupParentWhenDismissed; |
| 866 | } |
| 867 | |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 868 | public void performDismiss() { |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 869 | if (mOnDismissRunnable != null) { |
| 870 | mOnDismissRunnable.run(); |
| 871 | } |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 874 | public void setOnDismissRunnable(Runnable onDismissRunnable) { |
| 875 | mOnDismissRunnable = onDismissRunnable; |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 878 | public View getNotificationIcon() { |
| 879 | NotificationHeaderView notificationHeader = getNotificationHeader(); |
| 880 | if (notificationHeader != null) { |
| 881 | return notificationHeader.getIcon(); |
| 882 | } |
| 883 | return null; |
| 884 | } |
| 885 | |
| 886 | /** |
| 887 | * @return whether the notification is currently showing a view with an icon. |
| 888 | */ |
| 889 | public boolean isShowingIcon() { |
| 890 | if (mIsSummaryWithChildren) { |
| 891 | return true; |
| 892 | } |
| 893 | NotificationContentView showingLayout = getShowingLayout(); |
| 894 | NotificationHeaderView notificationHeader = showingLayout.getVisibleNotificationHeader(); |
| 895 | return notificationHeader != null; |
| 896 | } |
| 897 | |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 898 | /** |
| 899 | * Set how much this notification is transformed into an icon. |
| 900 | * |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 901 | * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed |
| 902 | * to the content away |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 903 | * @param isLastChild is this the last child in the list. If true, then the transformation is |
| 904 | * different since it's content fades out. |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 905 | */ |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 906 | public void setContentTransformationAmount(float contentTransformationAmount, |
| 907 | boolean isLastChild) { |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 908 | boolean changeTransformation = isLastChild != mIsLastChild; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 909 | changeTransformation |= mContentTransformationAmount != contentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 910 | mIsLastChild = isLastChild; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 911 | mContentTransformationAmount = contentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 912 | if (changeTransformation) { |
| 913 | updateContentTransformation(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 914 | } |
| 915 | } |
| 916 | |
| 917 | /** |
| 918 | * Set the icons to be visible of this notification. |
| 919 | */ |
| 920 | public void setIconsVisible(boolean iconsVisible) { |
| 921 | if (iconsVisible != mIconsVisible) { |
| 922 | mIconsVisible = iconsVisible; |
| 923 | updateIconVisibilities(); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 924 | } |
| 925 | } |
| 926 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 927 | @Override |
| 928 | protected void onBelowSpeedBumpChanged() { |
| 929 | updateIconVisibilities(); |
| 930 | } |
| 931 | |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 932 | private void updateContentTransformation() { |
| 933 | float contentAlpha; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 934 | float translationY = -mContentTransformationAmount * mIconTransformContentShift; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 935 | if (mIsLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 936 | contentAlpha = 1.0f - mContentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 937 | contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 938 | contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha); |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 939 | translationY *= 0.4f; |
| 940 | } else { |
| 941 | contentAlpha = 1.0f; |
| 942 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 943 | for (NotificationContentView l : mLayouts) { |
| 944 | l.setAlpha(contentAlpha); |
| 945 | l.setTranslationY(translationY); |
| 946 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 947 | if (mChildrenContainer != null) { |
| 948 | mChildrenContainer.setAlpha(contentAlpha); |
| 949 | mChildrenContainer.setTranslationY(translationY); |
| 950 | // TODO: handle children fade out better |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 951 | } |
| 952 | } |
| 953 | |
| 954 | private void updateIconVisibilities() { |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 955 | boolean visible = isChildInGroup() |
| 956 | || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS) |
| 957 | || mIconsVisible; |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 958 | for (NotificationContentView l : mLayouts) { |
| 959 | l.setIconsVisible(visible); |
| 960 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 961 | if (mChildrenContainer != null) { |
| 962 | mChildrenContainer.setIconsVisible(visible); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 963 | } |
| 964 | } |
| 965 | |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 966 | /** |
| 967 | * Get the relative top padding of a view relative to this view. This recursively walks up the |
| 968 | * hierarchy and does the corresponding measuring. |
| 969 | * |
| 970 | * @param view the view to the the padding for. The requested view has to be a child of this |
| 971 | * notification. |
| 972 | * @return the toppadding |
| 973 | */ |
| 974 | public int getRelativeTopPadding(View view) { |
| 975 | int topPadding = 0; |
| 976 | while (view.getParent() instanceof ViewGroup) { |
| 977 | topPadding += view.getTop(); |
| 978 | view = (View) view.getParent(); |
| 979 | if (view instanceof ExpandableNotificationRow) { |
| 980 | return topPadding; |
| 981 | } |
| 982 | } |
| 983 | return topPadding; |
| 984 | } |
| 985 | |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 986 | public float getContentTranslation() { |
| 987 | return mPrivateLayout.getTranslationY(); |
| 988 | } |
| 989 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 990 | public void setIsLowPriority(boolean isLowPriority) { |
| 991 | mIsLowPriority = isLowPriority; |
| 992 | mPrivateLayout.setIsLowPriority(isLowPriority); |
| 993 | if (mChildrenContainer != null) { |
| 994 | mChildrenContainer.setIsLowPriority(isLowPriority); |
| 995 | } |
| 996 | } |
| 997 | |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 998 | public void setUseIncreasedCollapsedHeight(boolean use) { |
| 999 | mUseIncreasedCollapsedHeight = use; |
| 1000 | } |
| 1001 | |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 1002 | public void setUseIncreasedHeadsUpHeight(boolean use) { |
| 1003 | mUseIncreasedHeadsUpHeight = use; |
| 1004 | } |
| 1005 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1006 | public interface ExpansionLogger { |
| 1007 | public void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
| 1008 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1009 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1010 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 1011 | super(context, attrs); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1012 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1013 | initDimens(); |
| 1014 | } |
| 1015 | |
| 1016 | private void initDimens() { |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1017 | mNotificationMinHeightLegacy = getFontScaledHeight(R.dimen.notification_min_height_legacy); |
| 1018 | mNotificationMinHeight = getFontScaledHeight(R.dimen.notification_min_height); |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 1019 | mNotificationMinHeightLarge = getFontScaledHeight( |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 1020 | R.dimen.notification_min_height_increased); |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1021 | mNotificationMaxHeight = getFontScaledHeight(R.dimen.notification_max_height); |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1022 | mNotificationAmbientHeight = getFontScaledHeight(R.dimen.notification_ambient_height); |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1023 | mMaxHeadsUpHeightLegacy = getFontScaledHeight( |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 1024 | R.dimen.notification_max_heads_up_height_legacy); |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1025 | mMaxHeadsUpHeight = getFontScaledHeight(R.dimen.notification_max_heads_up_height); |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame^] | 1026 | mMaxHeadsUpHeightIncreased = getFontScaledHeight( |
| 1027 | R.dimen.notification_max_heads_up_height_increased); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1028 | mIncreasedPaddingBetweenElements = getResources() |
| 1029 | .getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1030 | mIconTransformContentShiftNoIcon = getResources().getDimensionPixelSize( |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1031 | R.dimen.notification_icon_transform_content_shift); |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1032 | } |
| 1033 | |
| 1034 | /** |
| 1035 | * @param dimenId the dimen to look up |
| 1036 | * @return the font scaled dimen as if it were in sp but doesn't shrink sizes below dp |
| 1037 | */ |
| 1038 | private int getFontScaledHeight(int dimenId) { |
| 1039 | int dimensionPixelSize = getResources().getDimensionPixelSize(dimenId); |
| 1040 | float factor = Math.max(1.0f, getResources().getDisplayMetrics().scaledDensity / |
| 1041 | getResources().getDisplayMetrics().density); |
| 1042 | return (int) (dimensionPixelSize * factor); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1043 | } |
| 1044 | |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1045 | /** |
| 1046 | * Resets this view so it can be re-used for an updated notification. |
| 1047 | */ |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 1048 | @Override |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1049 | public void reset() { |
Christoph Studer | 22f2ee5 | 2014-07-29 22:57:21 +0200 | [diff] [blame] | 1050 | super.reset(); |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1051 | final boolean wasExpanded = isExpanded(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1052 | mExpandable = false; |
| 1053 | mHasUserChangedExpansion = false; |
| 1054 | mUserLocked = false; |
| 1055 | mShowingPublic = false; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1056 | mSensitive = false; |
| 1057 | mShowingPublicInitialized = false; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1058 | mIsSystemExpanded = false; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1059 | mOnKeyguard = false; |
Selim Cinek | 51d9491 | 2016-03-02 15:34:28 -0800 | [diff] [blame] | 1060 | mPublicLayout.reset(); |
| 1061 | mPrivateLayout.reset(); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1062 | resetHeight(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1063 | resetTranslation(); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1064 | logExpansionEvent(false, wasExpanded); |
| 1065 | } |
| 1066 | |
| 1067 | public void resetHeight() { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1068 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame] | 1069 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1070 | } |
| 1071 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 1072 | @Override |
| 1073 | protected void onFinishInflate() { |
| 1074 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1075 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 1076 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1077 | mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout}; |
| 1078 | |
| 1079 | for (NotificationContentView l : mLayouts) { |
| 1080 | l.setExpandClickListener(mExpandClickListener); |
| 1081 | l.setContainingNotification(this); |
| 1082 | } |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1083 | mMenuRowStub = (ViewStub) findViewById(R.id.menu_row_stub); |
| 1084 | mMenuRowStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1085 | @Override |
| 1086 | public void onInflate(ViewStub stub, View inflated) { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1087 | mMenuRow = (NotificationMenuRow) inflated; |
| 1088 | mMenuRow.setNotificationRowParent(ExpandableNotificationRow.this); |
| 1089 | mMenuRow.setAppName(mAppName); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1090 | } |
| 1091 | }); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1092 | mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub); |
| 1093 | mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1094 | @Override |
| 1095 | public void onInflate(ViewStub stub, View inflated) { |
| 1096 | mGuts = (NotificationGuts) inflated; |
| 1097 | mGuts.setClipTopAmount(getClipTopAmount()); |
| 1098 | mGuts.setActualHeight(getActualHeight()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1099 | mGutsStub = null; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1100 | } |
| 1101 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1102 | mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub); |
| 1103 | mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 1104 | |
| 1105 | @Override |
| 1106 | public void onInflate(ViewStub stub, View inflated) { |
| 1107 | mChildrenContainer = (NotificationChildrenContainer) inflated; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1108 | mChildrenContainer.setIsLowPriority(mIsLowPriority); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1109 | mChildrenContainer.setNotificationParent(ExpandableNotificationRow.this); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1110 | mChildrenContainer.onNotificationUpdated(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1111 | mTranslateableViews.add(mChildrenContainer); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1112 | } |
| 1113 | }); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1114 | |
| 1115 | // Add the views that we translate to reveal the gear |
| 1116 | mTranslateableViews = new ArrayList<View>(); |
| 1117 | for (int i = 0; i < getChildCount(); i++) { |
| 1118 | mTranslateableViews.add(getChildAt(i)); |
| 1119 | } |
| 1120 | // Remove views that don't translate |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1121 | mTranslateableViews.remove(mMenuRowStub); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1122 | mTranslateableViews.remove(mChildrenContainerStub); |
| 1123 | mTranslateableViews.remove(mGutsStub); |
| 1124 | } |
| 1125 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1126 | public void resetTranslation() { |
Mady Mellor | 32c638a | 2016-09-14 08:58:25 -0700 | [diff] [blame] | 1127 | if (mTranslateAnim != null) { |
| 1128 | mTranslateAnim.cancel(); |
| 1129 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1130 | if (mTranslateableViews != null) { |
| 1131 | for (int i = 0; i < mTranslateableViews.size(); i++) { |
| 1132 | mTranslateableViews.get(i).setTranslationX(0); |
| 1133 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1134 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1135 | invalidateOutline(); |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1136 | if (mMenuRow != null) { |
| 1137 | mMenuRow.resetState(true /* notify */); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | public void animateTranslateNotification(final float leftTarget) { |
| 1142 | if (mTranslateAnim != null) { |
| 1143 | mTranslateAnim.cancel(); |
| 1144 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1145 | mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1146 | if (mTranslateAnim != null) { |
| 1147 | mTranslateAnim.start(); |
| 1148 | } |
| 1149 | } |
| 1150 | |
| 1151 | @Override |
| 1152 | public void setTranslation(float translationX) { |
| 1153 | if (areGutsExposed()) { |
| 1154 | // Don't translate if guts are showing. |
| 1155 | return; |
| 1156 | } |
| 1157 | // Translate the group of views |
| 1158 | for (int i = 0; i < mTranslateableViews.size(); i++) { |
| 1159 | if (mTranslateableViews.get(i) != null) { |
| 1160 | mTranslateableViews.get(i).setTranslationX(translationX); |
| 1161 | } |
| 1162 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1163 | invalidateOutline(); |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1164 | if (mMenuRow != null) { |
| 1165 | mMenuRow.updateMenuAlpha(translationX, getMeasuredWidth()); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1166 | } |
| 1167 | } |
| 1168 | |
| 1169 | @Override |
| 1170 | public float getTranslation() { |
| 1171 | if (mTranslateableViews != null && mTranslateableViews.size() > 0) { |
| 1172 | // All of the views in the list should have same translation, just use first one. |
| 1173 | return mTranslateableViews.get(0).getTranslationX(); |
| 1174 | } |
| 1175 | return 0; |
| 1176 | } |
| 1177 | |
| 1178 | public Animator getTranslateViewAnimator(final float leftTarget, |
| 1179 | AnimatorUpdateListener listener) { |
Mady Mellor | 723f1f9 | 2016-03-13 15:54:06 -0700 | [diff] [blame] | 1180 | if (mTranslateAnim != null) { |
| 1181 | mTranslateAnim.cancel(); |
| 1182 | } |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1183 | if (areGutsExposed()) { |
| 1184 | // No translation if guts are exposed. |
| 1185 | return null; |
| 1186 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1187 | final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT, |
| 1188 | leftTarget); |
| 1189 | if (listener != null) { |
| 1190 | translateAnim.addUpdateListener(listener); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1191 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1192 | translateAnim.addListener(new AnimatorListenerAdapter() { |
| 1193 | boolean cancelled = false; |
| 1194 | |
| 1195 | @Override |
| 1196 | public void onAnimationCancel(Animator anim) { |
| 1197 | cancelled = true; |
| 1198 | } |
| 1199 | |
| 1200 | @Override |
| 1201 | public void onAnimationEnd(Animator anim) { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1202 | if (!cancelled && mMenuRow != null && leftTarget == 0) { |
| 1203 | mMenuRow.resetState(true /* notify */); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1204 | mTranslateAnim = null; |
| 1205 | } |
| 1206 | } |
| 1207 | }); |
| 1208 | mTranslateAnim = translateAnim; |
| 1209 | return translateAnim; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | public float getSpaceForGear() { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1213 | if (mMenuRow != null) { |
| 1214 | return mMenuRow.getSpaceForMenu(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1215 | } |
| 1216 | return 0; |
| 1217 | } |
| 1218 | |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1219 | public NotificationMenuRow getSettingsRow() { |
| 1220 | if (mMenuRow == null) { |
| 1221 | mMenuRowStub.inflate(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1222 | } |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1223 | return mMenuRow; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1224 | } |
| 1225 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1226 | public void inflateGuts() { |
| 1227 | if (mGuts == null) { |
| 1228 | mGutsStub.inflate(); |
| 1229 | } |
| 1230 | } |
| 1231 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1232 | private void updateChildrenVisibility() { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1233 | mPrivateLayout.setVisibility(!mShowingPublic && !mIsSummaryWithChildren ? VISIBLE |
| 1234 | : INVISIBLE); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1235 | if (mChildrenContainer != null) { |
| 1236 | mChildrenContainer.setVisibility(!mShowingPublic && mIsSummaryWithChildren ? VISIBLE |
| 1237 | : INVISIBLE); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1238 | mChildrenContainer.updateHeaderVisibility(!mShowingPublic && mIsSummaryWithChildren |
| 1239 | ? VISIBLE |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1240 | : INVISIBLE); |
| 1241 | } |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1242 | // The limits might have changed if the view suddenly became a group or vice versa |
| 1243 | updateLimits(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1244 | } |
| 1245 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1246 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 1247 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 1248 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1249 | // Add a record for the entire layout since its content is somehow small. |
| 1250 | // The event comes from a leaf view that is interacted with. |
| 1251 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 1252 | onInitializeAccessibilityEvent(record); |
| 1253 | dispatchPopulateAccessibilityEvent(record); |
| 1254 | event.appendRecord(record); |
| 1255 | return true; |
| 1256 | } |
| 1257 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1258 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1259 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1260 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1261 | public void setDark(boolean dark, boolean fade, long delay) { |
| 1262 | super.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1263 | final NotificationContentView showing = getShowingLayout(); |
| 1264 | if (showing != null) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1265 | showing.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1266 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1267 | if (mIsSummaryWithChildren) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1268 | mChildrenContainer.setDark(dark, fade, delay); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1269 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1270 | } |
| 1271 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1272 | public boolean isExpandable() { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1273 | if (mIsSummaryWithChildren && !mShowingPublic) { |
| 1274 | return !mChildrenExpanded; |
| 1275 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1276 | return mExpandable; |
| 1277 | } |
| 1278 | |
| 1279 | public void setExpandable(boolean expandable) { |
| 1280 | mExpandable = expandable; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1281 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1282 | } |
| 1283 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1284 | @Override |
| 1285 | public void setClipToActualHeight(boolean clipToActualHeight) { |
Selim Cinek | 084c16b | 2016-01-22 17:48:22 -0800 | [diff] [blame] | 1286 | super.setClipToActualHeight(clipToActualHeight || isUserLocked()); |
| 1287 | getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked()); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1288 | } |
| 1289 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1290 | /** |
| 1291 | * @return whether the user has changed the expansion state |
| 1292 | */ |
| 1293 | public boolean hasUserChangedExpansion() { |
| 1294 | return mHasUserChangedExpansion; |
| 1295 | } |
| 1296 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1297 | public boolean isUserExpanded() { |
| 1298 | return mUserExpanded; |
| 1299 | } |
| 1300 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1301 | /** |
| 1302 | * Set this notification to be expanded by the user |
| 1303 | * |
| 1304 | * @param userExpanded whether the user wants this notification to be expanded |
| 1305 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1306 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1307 | setUserExpanded(userExpanded, false /* allowChildExpansion */); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1308 | updateShelfIconColor(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | /** |
| 1312 | * Set this notification to be expanded by the user |
| 1313 | * |
| 1314 | * @param userExpanded whether the user wants this notification to be expanded |
| 1315 | * @param allowChildExpansion whether a call to this method allows expanding children |
| 1316 | */ |
| 1317 | public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1318 | mFalsingManager.setNotificationExpanded(); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1319 | if (mIsSummaryWithChildren && !mShowingPublic && allowChildExpansion) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 1320 | final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1321 | mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 1322 | logExpansionEvent(true /* userAction */, wasExpanded); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1323 | return; |
| 1324 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1325 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1326 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1327 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1328 | mUserExpanded = userExpanded; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1329 | logExpansionEvent(true, wasExpanded); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1330 | } |
| 1331 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 1332 | public void resetUserExpansion() { |
| 1333 | mHasUserChangedExpansion = false; |
| 1334 | mUserExpanded = false; |
| 1335 | } |
| 1336 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1337 | public boolean isUserLocked() { |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1338 | return mUserLocked && !mForceUnlocked; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | public void setUserLocked(boolean userLocked) { |
| 1342 | mUserLocked = userLocked; |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1343 | mPrivateLayout.setUserExpanding(userLocked); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1344 | if (mIsSummaryWithChildren) { |
| 1345 | mChildrenContainer.setUserLocked(userLocked); |
Selim Cinek | 7baaa9e | 2016-07-21 17:21:09 -0700 | [diff] [blame] | 1346 | if (userLocked || !isGroupExpanded()) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1347 | updateBackgroundForGroupState(); |
| 1348 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1349 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1350 | } |
| 1351 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1352 | /** |
| 1353 | * @return has the system set this notification to be expanded |
| 1354 | */ |
| 1355 | public boolean isSystemExpanded() { |
| 1356 | return mIsSystemExpanded; |
| 1357 | } |
| 1358 | |
| 1359 | /** |
| 1360 | * Set this notification to be expanded by the system. |
| 1361 | * |
| 1362 | * @param expand whether the system wants this notification to be expanded. |
| 1363 | */ |
| 1364 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1365 | if (expand != mIsSystemExpanded) { |
| 1366 | final boolean wasExpanded = isExpanded(); |
| 1367 | mIsSystemExpanded = expand; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1368 | updateShelfIconColor(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1369 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1370 | logExpansionEvent(false, wasExpanded); |
Selim Cinek | ed6913b | 2016-06-01 12:01:17 -0700 | [diff] [blame] | 1371 | if (mIsSummaryWithChildren) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1372 | mChildrenContainer.updateGroupOverflow(); |
| 1373 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1374 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1378 | * @param onKeyguard whether to prevent notification expansion |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 1379 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1380 | public void setOnKeyguard(boolean onKeyguard) { |
| 1381 | if (onKeyguard != mOnKeyguard) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1382 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1383 | mOnKeyguard = onKeyguard; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1384 | logExpansionEvent(false, wasExpanded); |
| 1385 | if (wasExpanded != isExpanded()) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1386 | if (mIsSummaryWithChildren) { |
| 1387 | mChildrenContainer.updateGroupOverflow(); |
| 1388 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1389 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1390 | } |
| 1391 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | /** |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 1395 | * @return Can the underlying notification be cleared? This can be different from whether the |
| 1396 | * notification can be dismissed in case notifications are sensitive on the lockscreen. |
| 1397 | * @see #canViewBeDismissed() |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 1398 | */ |
| 1399 | public boolean isClearable() { |
Selim Cinek | 506deb6 | 2016-07-20 15:43:59 -0700 | [diff] [blame] | 1400 | if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) { |
| 1401 | return false; |
| 1402 | } |
| 1403 | if (mIsSummaryWithChildren) { |
| 1404 | List<ExpandableNotificationRow> notificationChildren = |
| 1405 | mChildrenContainer.getNotificationChildren(); |
| 1406 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 1407 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 1408 | if (!child.isClearable()) { |
| 1409 | return false; |
| 1410 | } |
| 1411 | } |
| 1412 | } |
| 1413 | return true; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 1414 | } |
| 1415 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 1416 | @Override |
| 1417 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1418 | if (isUserLocked()) { |
| 1419 | return getActualHeight(); |
| 1420 | } |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1421 | if (mGuts != null && mGuts.isExposed()) { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1422 | return mGuts.getHeight(); |
| 1423 | } else if ((isChildInGroup() && !isGroupExpanded())) { |
| 1424 | return mPrivateLayout.getMinHeight(); |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1425 | } else if (mShowAmbient) { |
| 1426 | return getAmbientHeight(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1427 | } else if (mSensitive && mHideSensitiveForIntrinsicHeight) { |
| 1428 | return getMinHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1429 | } else if (mIsSummaryWithChildren && !mOnKeyguard) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1430 | return mChildrenContainer.getIntrinsicHeight(); |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 1431 | } else if (!mOnKeyguard && (mIsHeadsUp || mHeadsupDisappearRunning)) { |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 1432 | if (isPinned() || mHeadsupDisappearRunning) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1433 | return getPinnedHeadsUpHeight(true /* atLeastMinHeight */); |
| 1434 | } else if (isExpanded()) { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1435 | return Math.max(getMaxExpandHeight(), mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1436 | } else { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1437 | return Math.max(getCollapsedHeight(), mHeadsUpHeight); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1438 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1439 | } else if (isExpanded()) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1440 | return getMaxExpandHeight(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1441 | } else { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1442 | return getCollapsedHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1443 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1444 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1445 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 1446 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1447 | public boolean isGroupExpanded() { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 1448 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1449 | } |
| 1450 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 1451 | private void onChildrenCountChanged() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 1452 | mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1453 | && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0; |
| 1454 | if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) { |
| 1455 | mChildrenContainer.recreateNotificationHeader(mExpandClickListener, |
| 1456 | mEntry.notification); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 1457 | } |
Mady Mellor | 6baed9e | 2016-05-25 16:05:09 -0700 | [diff] [blame] | 1458 | getShowingLayout().updateBackgroundColor(false /* animate */); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1459 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1460 | updateChildrenHeaderAppearance(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1461 | updateChildrenVisibility(); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 1462 | } |
| 1463 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1464 | public void updateChildrenHeaderAppearance() { |
Selim Cinek | ed6913b | 2016-06-01 12:01:17 -0700 | [diff] [blame] | 1465 | if (mIsSummaryWithChildren) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1466 | mChildrenContainer.updateChildrenHeaderAppearance(); |
| 1467 | } |
| 1468 | } |
| 1469 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1470 | /** |
| 1471 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 1472 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 1473 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 1474 | * view can differ from this state, if layout params are modified from outside. |
| 1475 | * |
| 1476 | * @return whether the view state is currently expanded. |
| 1477 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1478 | public boolean isExpanded() { |
Selim Cinek | e81b82b | 2016-03-04 11:22:28 -0800 | [diff] [blame] | 1479 | return isExpanded(false /* allowOnKeyguard */); |
| 1480 | } |
| 1481 | |
| 1482 | public boolean isExpanded(boolean allowOnKeyguard) { |
| 1483 | return (!mOnKeyguard || allowOnKeyguard) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1484 | && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) |
| 1485 | || isUserExpanded()); |
| 1486 | } |
| 1487 | |
| 1488 | private boolean isSystemChildExpanded() { |
| 1489 | return mIsSystemChildExpanded; |
| 1490 | } |
| 1491 | |
| 1492 | public void setSystemChildExpanded(boolean expanded) { |
| 1493 | mIsSystemChildExpanded = expanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1494 | } |
| 1495 | |
| 1496 | @Override |
| 1497 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 1498 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1499 | updateMaxHeights(); |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1500 | if (mMenuRow != null) { |
| 1501 | mMenuRow.updateVerticalLocation(); |
Mady Mellor | a6edc87 | 2016-04-26 11:01:03 -0700 | [diff] [blame] | 1502 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1503 | updateContentShiftHeight(); |
| 1504 | } |
| 1505 | |
| 1506 | /** |
| 1507 | * Updates the content shift height such that the header is completely hidden when coming from |
| 1508 | * the top. |
| 1509 | */ |
| 1510 | private void updateContentShiftHeight() { |
| 1511 | NotificationHeaderView notificationHeader = getNotificationHeader(); |
| 1512 | if (notificationHeader != null) { |
| 1513 | CachingIconView icon = notificationHeader.getIcon(); |
| 1514 | mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight(); |
| 1515 | } else { |
| 1516 | mIconTransformContentShift = mIconTransformContentShiftNoIcon; |
| 1517 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1520 | private void updateMaxHeights() { |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 1521 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1522 | View expandedChild = mPrivateLayout.getExpandedChild(); |
| 1523 | if (expandedChild == null) { |
| 1524 | expandedChild = mPrivateLayout.getContractedChild(); |
| 1525 | } |
| 1526 | mMaxExpandHeight = expandedChild.getHeight(); |
| 1527 | View headsUpChild = mPrivateLayout.getHeadsUpChild(); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 1528 | if (headsUpChild == null) { |
| 1529 | headsUpChild = mPrivateLayout.getContractedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1530 | } |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 1531 | mHeadsUpHeight = headsUpChild.getHeight(); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 1532 | if (intrinsicBefore != getIntrinsicHeight()) { |
Selim Cinek | bb42b7d | 2016-08-10 13:02:38 -0700 | [diff] [blame] | 1533 | notifyHeightChanged(true /* needsAnimation */); |
Selim Cinek | d2319fb | 2014-09-01 19:41:54 +0200 | [diff] [blame] | 1534 | } |
| 1535 | } |
| 1536 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 1537 | @Override |
| 1538 | public void notifyHeightChanged(boolean needsAnimation) { |
| 1539 | super.notifyHeightChanged(needsAnimation); |
| 1540 | getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked()); |
| 1541 | } |
| 1542 | |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 1543 | public void setSensitive(boolean sensitive, boolean hideSensitive) { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1544 | mSensitive = sensitive; |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 1545 | mSensitiveHiddenInGeneral = hideSensitive; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1546 | } |
| 1547 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 1548 | @Override |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1549 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 1550 | mHideSensitiveForIntrinsicHeight = hideSensitive; |
Selim Cinek | a52f6a1 | 2016-02-29 15:35:58 -0800 | [diff] [blame] | 1551 | if (mIsSummaryWithChildren) { |
| 1552 | List<ExpandableNotificationRow> notificationChildren = |
| 1553 | mChildrenContainer.getNotificationChildren(); |
| 1554 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 1555 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 1556 | child.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 1557 | } |
| 1558 | } |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1559 | } |
| 1560 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 1561 | @Override |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1562 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 1563 | long duration) { |
| 1564 | boolean oldShowingPublic = mShowingPublic; |
| 1565 | mShowingPublic = mSensitive && hideSensitive; |
| 1566 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 1567 | return; |
| 1568 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1569 | |
| 1570 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1571 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1572 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1573 | if (!animated) { |
| 1574 | mPublicLayout.animate().cancel(); |
| 1575 | mPrivateLayout.animate().cancel(); |
Selim Cinek | a554c70 | 2016-06-17 18:02:12 -0700 | [diff] [blame] | 1576 | if (mChildrenContainer != null) { |
| 1577 | mChildrenContainer.animate().cancel(); |
| 1578 | mChildrenContainer.setAlpha(1f); |
| 1579 | } |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1580 | mPublicLayout.setAlpha(1f); |
| 1581 | mPrivateLayout.setAlpha(1f); |
| 1582 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1583 | updateChildrenVisibility(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1584 | } else { |
| 1585 | animateShowingPublic(delay, duration); |
| 1586 | } |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1587 | NotificationContentView showingLayout = getShowingLayout(); |
| 1588 | showingLayout.updateBackgroundColor(animated); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1589 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Adrian Roos | e5726a2 | 2016-12-19 14:26:51 -0800 | [diff] [blame] | 1590 | showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1591 | mShowingPublicInitialized = true; |
| 1592 | } |
| 1593 | |
| 1594 | private void animateShowingPublic(long delay, long duration) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1595 | View[] privateViews = mIsSummaryWithChildren |
| 1596 | ? new View[] {mChildrenContainer} |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1597 | : new View[] {mPrivateLayout}; |
| 1598 | View[] publicViews = new View[] {mPublicLayout}; |
| 1599 | View[] hiddenChildren = mShowingPublic ? privateViews : publicViews; |
| 1600 | View[] shownChildren = mShowingPublic ? publicViews : privateViews; |
| 1601 | for (final View hiddenView : hiddenChildren) { |
| 1602 | hiddenView.setVisibility(View.VISIBLE); |
| 1603 | hiddenView.animate().cancel(); |
| 1604 | hiddenView.animate() |
| 1605 | .alpha(0f) |
| 1606 | .setStartDelay(delay) |
| 1607 | .setDuration(duration) |
| 1608 | .withEndAction(new Runnable() { |
| 1609 | @Override |
| 1610 | public void run() { |
| 1611 | hiddenView.setVisibility(View.INVISIBLE); |
| 1612 | } |
| 1613 | }); |
| 1614 | } |
| 1615 | for (View showView : shownChildren) { |
| 1616 | showView.setVisibility(View.VISIBLE); |
| 1617 | showView.setAlpha(0f); |
| 1618 | showView.animate().cancel(); |
| 1619 | showView.animate() |
| 1620 | .alpha(1f) |
| 1621 | .setStartDelay(delay) |
| 1622 | .setDuration(duration); |
| 1623 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 1624 | } |
| 1625 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 1626 | @Override |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 1627 | public boolean mustStayOnScreen() { |
| 1628 | return mIsHeadsUp; |
| 1629 | } |
| 1630 | |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 1631 | /** |
| 1632 | * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as |
| 1633 | * otherwise some state might not be updated. To request about the general clearability |
| 1634 | * see {@link #isClearable()}. |
| 1635 | */ |
| 1636 | public boolean canViewBeDismissed() { |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1637 | return isClearable() && (!mShowingPublic || !mSensitiveHiddenInGeneral); |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 1638 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 1639 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1640 | public void makeActionsVisibile() { |
| 1641 | setUserExpanded(true, true); |
| 1642 | if (isChildInGroup()) { |
| 1643 | mGroupManager.setGroupExpanded(mStatusBarNotification, true); |
| 1644 | } |
Selim Cinek | bb42b7d | 2016-08-10 13:02:38 -0700 | [diff] [blame] | 1645 | notifyHeightChanged(false /* needsAnimation */); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 1646 | } |
| 1647 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1648 | public void setChildrenExpanded(boolean expanded, boolean animate) { |
| 1649 | mChildrenExpanded = expanded; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1650 | if (mChildrenContainer != null) { |
| 1651 | mChildrenContainer.setChildrenExpanded(expanded); |
| 1652 | } |
Mady Mellor | 1a5d8ea | 2016-06-09 10:42:42 -0700 | [diff] [blame] | 1653 | updateBackgroundForGroupState(); |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 1654 | updateClickAndFocus(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1655 | } |
| 1656 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1657 | public static void applyTint(View v, int color) { |
| 1658 | int alpha; |
| 1659 | if (color != 0) { |
| 1660 | alpha = COLORED_DIVIDER_ALPHA; |
| 1661 | } else { |
| 1662 | color = 0xff000000; |
| 1663 | alpha = DEFAULT_DIVIDER_ALPHA; |
| 1664 | } |
| 1665 | if (v.getBackground() instanceof ColorDrawable) { |
| 1666 | ColorDrawable background = (ColorDrawable) v.getBackground(); |
| 1667 | background.mutate(); |
| 1668 | background.setColor(color); |
| 1669 | background.setAlpha(alpha); |
| 1670 | } |
| 1671 | } |
| 1672 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1673 | public int getMaxExpandHeight() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1674 | return mMaxExpandHeight; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1675 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 1676 | |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1677 | public boolean areGutsExposed() { |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1678 | return (mGuts != null && mGuts.isExposed()); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1679 | } |
| 1680 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1681 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1682 | public boolean isContentExpandable() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1683 | NotificationContentView showingLayout = getShowingLayout(); |
| 1684 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | @Override |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 1688 | protected View getContentView() { |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 1689 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 1690 | return mChildrenContainer; |
| 1691 | } |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 1692 | return getShowingLayout(); |
| 1693 | } |
| 1694 | |
| 1695 | @Override |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 1696 | protected void onAppearAnimationFinished(boolean wasAppearing) { |
| 1697 | super.onAppearAnimationFinished(wasAppearing); |
| 1698 | if (wasAppearing) { |
| 1699 | // During the animation the visible view might have changed, so let's make sure all |
| 1700 | // alphas are reset |
| 1701 | if (mChildrenContainer != null) { |
| 1702 | mChildrenContainer.setAlpha(1.0f); |
| 1703 | mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null); |
| 1704 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1705 | for (NotificationContentView l : mLayouts) { |
| 1706 | l.setAlpha(1.0f); |
| 1707 | l.setLayerType(LAYER_TYPE_NONE, null); |
| 1708 | } |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1713 | public int getExtraBottomPadding() { |
| 1714 | if (mIsSummaryWithChildren && isGroupExpanded()) { |
| 1715 | return mIncreasedPaddingBetweenElements; |
| 1716 | } |
| 1717 | return 0; |
| 1718 | } |
| 1719 | |
| 1720 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1721 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1722 | super.setActualHeight(height, notifyListeners); |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 1723 | if (mGuts != null && mGuts.isExposed()) { |
Mady Mellor | b53bc27 | 2016-02-11 18:28:23 -0800 | [diff] [blame] | 1724 | mGuts.setActualHeight(height); |
| 1725 | return; |
| 1726 | } |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 1727 | int contentHeight = Math.max(getMinHeight(), height); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1728 | for (NotificationContentView l : mLayouts) { |
| 1729 | l.setContentHeight(contentHeight); |
| 1730 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1731 | if (mIsSummaryWithChildren) { |
| 1732 | mChildrenContainer.setActualHeight(height); |
| 1733 | } |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1734 | if (mGuts != null) { |
| 1735 | mGuts.setActualHeight(height); |
| 1736 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1737 | } |
| 1738 | |
| 1739 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1740 | public int getMaxContentHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1741 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1742 | return mChildrenContainer.getMaxContentHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1743 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1744 | NotificationContentView showingLayout = getShowingLayout(); |
| 1745 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1749 | public int getMinHeight() { |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 1750 | if (!mOnKeyguard && mIsHeadsUp && mHeadsUpManager.isTrackingHeadsUp()) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1751 | return getPinnedHeadsUpHeight(false /* atLeastMinHeight */); |
| 1752 | } else if (mIsSummaryWithChildren && !isGroupExpanded() && !mShowingPublic) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1753 | return mChildrenContainer.getMinHeight(); |
Selim Cinek | 01ee2cd5 | 2016-12-21 18:23:11 +0100 | [diff] [blame] | 1754 | } else if (!mOnKeyguard && mIsHeadsUp) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1755 | return mHeadsUpHeight; |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 1756 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1757 | NotificationContentView showingLayout = getShowingLayout(); |
| 1758 | return showingLayout.getMinHeight(); |
| 1759 | } |
| 1760 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1761 | private int getAmbientHeight() { |
| 1762 | NotificationContentView showingLayout = getShowingLayout(); |
| 1763 | return showingLayout.getAmbientChild() != null |
| 1764 | ? showingLayout.getAmbientChild().getHeight() |
| 1765 | : getCollapsedHeight(); |
| 1766 | } |
| 1767 | |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1768 | @Override |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1769 | public int getCollapsedHeight() { |
Selim Cinek | 2c58461 | 2016-02-29 16:14:25 -0800 | [diff] [blame] | 1770 | if (mIsSummaryWithChildren && !mShowingPublic) { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 1771 | return mChildrenContainer.getCollapsedHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1772 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 1773 | return getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1777 | public void setClipTopAmount(int clipTopAmount) { |
| 1778 | super.setClipTopAmount(clipTopAmount); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1779 | for (NotificationContentView l : mLayouts) { |
| 1780 | l.setClipTopAmount(clipTopAmount); |
| 1781 | } |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1782 | if (mGuts != null) { |
| 1783 | mGuts.setClipTopAmount(clipTopAmount); |
| 1784 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1785 | } |
| 1786 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1787 | @Override |
| 1788 | public void setClipBottomAmount(int clipBottomAmount) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 1789 | if (clipBottomAmount != mClipBottomAmount) { |
| 1790 | super.setClipBottomAmount(clipBottomAmount); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1791 | for (NotificationContentView l : mLayouts) { |
| 1792 | l.setClipBottomAmount(clipBottomAmount); |
| 1793 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 1794 | if (mGuts != null) { |
| 1795 | mGuts.setClipBottomAmount(clipBottomAmount); |
| 1796 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1797 | } |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 1798 | if (mChildrenContainer != null) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 1799 | // We have to update this even if it hasn't changed, since the children locations can |
| 1800 | // have changed |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 1801 | mChildrenContainer.setClipBottomAmount(clipBottomAmount); |
| 1802 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 1803 | } |
| 1804 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1805 | public boolean isMaxExpandHeightInitialized() { |
| 1806 | return mMaxExpandHeight != 0; |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 1807 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1808 | |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1809 | public NotificationContentView getShowingLayout() { |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 1810 | return mShowingPublic ? mPublicLayout : mPrivateLayout; |
| 1811 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1812 | |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1813 | public void setShowingLegacyBackground(boolean showing) { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1814 | for (NotificationContentView l : mLayouts) { |
| 1815 | l.setShowingLegacyBackground(showing); |
| 1816 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1817 | } |
| 1818 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1819 | @Override |
| 1820 | protected void updateBackgroundTint() { |
| 1821 | super.updateBackgroundTint(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1822 | updateBackgroundForGroupState(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1823 | if (mIsSummaryWithChildren) { |
| 1824 | List<ExpandableNotificationRow> notificationChildren = |
| 1825 | mChildrenContainer.getNotificationChildren(); |
| 1826 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 1827 | ExpandableNotificationRow child = notificationChildren.get(i); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1828 | child.updateBackgroundForGroupState(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1829 | } |
| 1830 | } |
| 1831 | } |
| 1832 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1833 | /** |
| 1834 | * Called when a group has finished animating from collapsed or expanded state. |
| 1835 | */ |
| 1836 | public void onFinishedExpansionChange() { |
| 1837 | mGroupExpansionChanging = false; |
| 1838 | updateBackgroundForGroupState(); |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Updates the parent and children backgrounds in a group based on the expansion state. |
| 1843 | */ |
| 1844 | public void updateBackgroundForGroupState() { |
| 1845 | if (mIsSummaryWithChildren) { |
| 1846 | // Only when the group has finished expanding do we hide its background. |
| 1847 | mShowNoBackground = isGroupExpanded() && !isGroupExpansionChanging() && !isUserLocked(); |
| 1848 | mChildrenContainer.updateHeaderForExpansion(mShowNoBackground); |
| 1849 | List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren(); |
| 1850 | for (int i = 0; i < children.size(); i++) { |
| 1851 | children.get(i).updateBackgroundForGroupState(); |
| 1852 | } |
| 1853 | } else if (isChildInGroup()) { |
| 1854 | final int childColor = getShowingLayout().getBackgroundColorForExpansionState(); |
| 1855 | // Only show a background if the group is expanded OR if it is expanding / collapsing |
| 1856 | // and has a custom background color |
| 1857 | final boolean showBackground = isGroupExpanded() |
| 1858 | || ((mNotificationParent.isGroupExpansionChanging() |
| 1859 | || mNotificationParent.isUserLocked()) && childColor != 0); |
| 1860 | mShowNoBackground = !showBackground; |
| 1861 | } else { |
| 1862 | // Only children or parents ever need no background. |
| 1863 | mShowNoBackground = false; |
| 1864 | } |
| 1865 | updateOutline(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 1866 | updateBackground(); |
| 1867 | } |
| 1868 | |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 1869 | public int getPositionOfChild(ExpandableNotificationRow childRow) { |
| 1870 | if (mIsSummaryWithChildren) { |
| 1871 | return mChildrenContainer.getPositionInLinearLayout(childRow); |
| 1872 | } |
| 1873 | return 0; |
| 1874 | } |
| 1875 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1876 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 1877 | mLogger = logger; |
| 1878 | mLoggingKey = key; |
| 1879 | } |
| 1880 | |
Chris Wren | 6abeeb9 | 2016-05-26 14:44:38 -0400 | [diff] [blame] | 1881 | public void onExpandedByGesture(boolean userExpanded) { |
| 1882 | int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER; |
| 1883 | if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) { |
| 1884 | event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER; |
| 1885 | } |
| 1886 | MetricsLogger.action(mContext, event, userExpanded); |
| 1887 | } |
| 1888 | |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 1889 | @Override |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1890 | public float getIncreasedPaddingAmount() { |
| 1891 | if (mIsSummaryWithChildren) { |
| 1892 | if (isGroupExpanded()) { |
| 1893 | return 1.0f; |
| 1894 | } else if (isUserLocked()) { |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1895 | return mChildrenContainer.getGroupExpandFraction(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1896 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 1897 | } else if (isColorized() && (!mIsLowPriority || isExpanded())) { |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 1898 | return -1.0f; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1899 | } |
| 1900 | return 0.0f; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1901 | } |
| 1902 | |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 1903 | private boolean isColorized() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 1904 | return mIsColorized && mBgTint != NO_COLOR; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 1905 | } |
| 1906 | |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 1907 | @Override |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 1908 | protected boolean disallowSingleClick(MotionEvent event) { |
| 1909 | float x = event.getX(); |
| 1910 | float y = event.getY(); |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 1911 | NotificationHeaderView header = getVisibleNotificationHeader(); |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 1912 | if (header != null) { |
Mady Mellor | a883351 | 2016-03-09 09:50:18 -0800 | [diff] [blame] | 1913 | return header.isInTouchRect(x - getTranslation(), y); |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 1914 | } |
| 1915 | return super.disallowSingleClick(event); |
| 1916 | } |
| 1917 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1918 | private void logExpansionEvent(boolean userAction, boolean wasExpanded) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 1919 | boolean nowExpanded = isExpanded(); |
| 1920 | if (mIsSummaryWithChildren) { |
| 1921 | nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
| 1922 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1923 | if (wasExpanded != nowExpanded && mLogger != null) { |
| 1924 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded) ; |
| 1925 | } |
| 1926 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1927 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1928 | @Override |
| 1929 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 1930 | super.onInitializeAccessibilityNodeInfoInternal(info); |
| 1931 | if (canViewBeDismissed()) { |
| 1932 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS); |
| 1933 | } |
| 1934 | } |
| 1935 | |
| 1936 | @Override |
| 1937 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 1938 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 1939 | return true; |
| 1940 | } |
| 1941 | switch (action) { |
| 1942 | case AccessibilityNodeInfo.ACTION_DISMISS: |
| 1943 | NotificationStackScrollLayout.performDismiss(this, mGroupManager, |
| 1944 | true /* fromAccessibility */); |
| 1945 | return true; |
| 1946 | } |
| 1947 | return false; |
| 1948 | } |
| 1949 | |
| 1950 | public boolean shouldRefocusOnDismiss() { |
| 1951 | return mRefocusOnDismiss || isAccessibilityFocused(); |
| 1952 | } |
| 1953 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1954 | public interface OnExpandClickListener { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 1955 | void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 1956 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 1957 | |
| 1958 | @Override |
| 1959 | public ExpandableViewState createNewViewState(StackScrollState stackScrollState) { |
| 1960 | return new NotificationViewState(stackScrollState); |
| 1961 | } |
| 1962 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1963 | @Override |
| 1964 | public boolean isAboveShelf() { |
| 1965 | return mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf); |
| 1966 | } |
| 1967 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1968 | public void setShowAmbient(boolean showAmbient) { |
| 1969 | if (showAmbient != mShowAmbient) { |
| 1970 | mShowAmbient = showAmbient; |
| 1971 | notifyHeightChanged(false /* needsAnimation */); |
| 1972 | } |
| 1973 | } |
| 1974 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 1975 | public void setAboveShelf(boolean aboveShelf) { |
| 1976 | mAboveShelf = aboveShelf; |
| 1977 | } |
| 1978 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 1979 | public class NotificationViewState extends ExpandableViewState { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 1980 | |
| 1981 | private final StackScrollState mOverallState; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1982 | |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 1983 | |
| 1984 | private NotificationViewState(StackScrollState stackScrollState) { |
| 1985 | mOverallState = stackScrollState; |
| 1986 | } |
| 1987 | |
| 1988 | @Override |
| 1989 | public void applyToView(View view) { |
| 1990 | super.applyToView(view); |
| 1991 | if (view instanceof ExpandableNotificationRow) { |
| 1992 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 1993 | row.applyChildrenState(mOverallState); |
| 1994 | } |
| 1995 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 1996 | |
| 1997 | @Override |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1998 | protected void onYTranslationAnimationFinished(View view) { |
| 1999 | super.onYTranslationAnimationFinished(view); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2000 | if (mHeadsupDisappearRunning) { |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 2001 | setHeadsUpAnimatingAway(false); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2002 | } |
| 2003 | } |
| 2004 | |
| 2005 | @Override |
| 2006 | public void animateTo(View child, AnimationProperties properties) { |
| 2007 | super.animateTo(child, properties); |
| 2008 | if (child instanceof ExpandableNotificationRow) { |
| 2009 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 2010 | row.startChildAnimation(mOverallState, properties); |
| 2011 | } |
| 2012 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2013 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2014 | } |