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