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