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