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