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