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 | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 19 | import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator.ExpandAnimationParameters; |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 20 | import static com.android.systemui.statusbar.notification.NotificationInflater.InflationCallback; |
Selim Cinek | c478f90 | 2017-02-22 20:55:44 -0800 | [diff] [blame] | 21 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 22 | import android.animation.Animator; |
| 23 | import android.animation.AnimatorListenerAdapter; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 24 | import android.animation.ObjectAnimator; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 25 | import android.animation.ValueAnimator.AnimatorUpdateListener; |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 27 | import android.app.NotificationChannel; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 28 | import android.content.Context; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 29 | import android.content.pm.PackageInfo; |
| 30 | import android.content.pm.PackageManager; |
Mady Mellor | 9d03a52 | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 32 | import android.content.res.Resources; |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 33 | import android.graphics.Path; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 34 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 35 | import android.graphics.drawable.AnimationDrawable; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 36 | import android.graphics.drawable.ColorDrawable; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 37 | import android.graphics.drawable.Drawable; |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 38 | import android.os.AsyncTask; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 39 | import android.os.Build; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 40 | import android.os.Bundle; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 41 | import android.service.notification.StatusBarNotification; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 42 | import android.util.ArraySet; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 43 | import android.util.AttributeSet; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 44 | import android.util.FloatProperty; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 45 | import android.util.Log; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 46 | import android.util.MathUtils; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 47 | import android.util.Property; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 48 | import android.view.KeyEvent; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 49 | import android.view.LayoutInflater; |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 50 | import android.view.MotionEvent; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 51 | import android.view.NotificationHeaderView; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 52 | import android.view.View; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 53 | import android.view.ViewGroup; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 54 | import android.view.ViewStub; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 55 | import android.view.accessibility.AccessibilityEvent; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 56 | import android.view.accessibility.AccessibilityNodeInfo; |
Mady Mellor | b3a6aed | 2018-05-11 13:24:07 -0700 | [diff] [blame] | 57 | import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 58 | import android.widget.Chronometer; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 59 | import android.widget.FrameLayout; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 60 | import android.widget.ImageView; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 61 | import android.widget.RemoteViews; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 62 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 63 | import com.android.internal.annotations.VisibleForTesting; |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 64 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 65 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 66 | import com.android.internal.util.NotificationColorUtil; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 67 | import com.android.internal.widget.CachingIconView; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 68 | import com.android.systemui.Dependency; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 69 | import com.android.systemui.Interpolators; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 70 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 71 | import com.android.systemui.classifier.FalsingManager; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 72 | import com.android.systemui.plugins.PluginListener; |
| 73 | import com.android.systemui.plugins.PluginManager; |
| 74 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin; |
| 75 | import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin.MenuItem; |
| 76 | import com.android.systemui.statusbar.NotificationGuts.GutsContent; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 77 | import com.android.systemui.statusbar.notification.AboveShelfChangedListener; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 78 | import com.android.systemui.statusbar.notification.ActivityLaunchAnimator; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 79 | import com.android.systemui.statusbar.notification.HybridNotificationView; |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 80 | import com.android.systemui.statusbar.notification.NotificationCounters; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 81 | import com.android.systemui.statusbar.notification.NotificationInflater; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 82 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 83 | import com.android.systemui.statusbar.notification.NotificationViewWrapper; |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 84 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 85 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 86 | import com.android.systemui.statusbar.phone.StatusBar; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 87 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 88 | import com.android.systemui.statusbar.stack.AmbientState; |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 89 | import com.android.systemui.statusbar.stack.AnimationProperties; |
| 90 | import com.android.systemui.statusbar.stack.ExpandableViewState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 91 | import com.android.systemui.statusbar.stack.NotificationChildrenContainer; |
| 92 | import com.android.systemui.statusbar.stack.StackScrollState; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 93 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 94 | import java.util.ArrayList; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 95 | import java.util.List; |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 96 | import java.util.function.BooleanSupplier; |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 97 | import java.util.function.Consumer; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 98 | |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 99 | /** |
| 100 | * View representing a notification item - this can be either the individual child notification or |
| 101 | * the group summary (which contains 1 or more child notifications). |
| 102 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 103 | public class ExpandableNotificationRow extends ActivatableNotificationView |
| 104 | implements PluginListener<NotificationMenuRowPlugin> { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 105 | |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 106 | private static final boolean DEBUG = false; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 107 | private static final int DEFAULT_DIVIDER_ALPHA = 0x29; |
| 108 | private static final int COLORED_DIVIDER_ALPHA = 0x7B; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 109 | private static final int MENU_VIEW_INDEX = 0; |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 110 | private static final String TAG = "ExpandableNotifRow"; |
felkachang | 0857955 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 111 | public static final float DEFAULT_HEADER_VISIBLE_AMOUNT = 1.0f; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 112 | |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 113 | /** |
| 114 | * Listener for when {@link ExpandableNotificationRow} is laid out. |
| 115 | */ |
Mady Mellor | 035badd | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 116 | public interface LayoutListener { |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 117 | void onLayout(); |
Mady Mellor | 035badd | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | private LayoutListener mLayoutListener; |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 121 | private boolean mDark; |
Selim Cinek | 55a3e73 | 2017-05-25 18:30:10 -0700 | [diff] [blame] | 122 | private boolean mLowPriorityStateUpdated; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 123 | private final NotificationInflater mNotificationInflater; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 124 | private int mIconTransformContentShift; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 125 | private int mIconTransformContentShiftNoIcon; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 126 | private int mNotificationMinHeightLegacy; |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 127 | private int mNotificationMinHeightBeforeP; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 128 | private int mMaxHeadsUpHeightLegacy; |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 129 | private int mMaxHeadsUpHeightBeforeP; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 130 | private int mMaxHeadsUpHeight; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 131 | private int mMaxHeadsUpHeightIncreased; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 132 | private int mNotificationMinHeight; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 133 | private int mNotificationMinHeightLarge; |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 134 | private int mNotificationMaxHeight; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 135 | private int mNotificationAmbientHeight; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 136 | private int mIncreasedPaddingBetweenElements; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 137 | private int mNotificationLaunchHeight; |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 138 | private boolean mMustStayOnScreen; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 139 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 140 | /** Does this row contain layouts that can adapt to row expansion */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 141 | private boolean mExpandable; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 142 | /** Has the user actively changed the expansion state of this row */ |
| 143 | private boolean mHasUserChangedExpansion; |
| 144 | /** If {@link #mHasUserChangedExpansion}, has the user expanded this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 145 | private boolean mUserExpanded; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 146 | /** Whether the blocking helper is showing on this notification (even if dismissed) */ |
| 147 | private boolean mIsBlockingHelperShowing; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 148 | |
| 149 | /** |
| 150 | * Has this notification been expanded while it was pinned |
| 151 | */ |
| 152 | private boolean mExpandedWhenPinned; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 153 | /** Is the user touching this row */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 154 | private boolean mUserLocked; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 155 | /** Are we showing the "public" version */ |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 156 | private boolean mShowingPublic; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 157 | private boolean mSensitive; |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 158 | private boolean mSensitiveHiddenInGeneral; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 159 | private boolean mShowingPublicInitialized; |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 160 | private boolean mHideSensitiveForIntrinsicHeight; |
felkachang | 0857955 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 161 | private float mHeaderVisibleAmount = DEFAULT_HEADER_VISIBLE_AMOUNT; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 162 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 163 | /** |
| 164 | * Is this notification expanded by the system. The expansion state can be overridden by the |
| 165 | * user expansion. |
| 166 | */ |
| 167 | private boolean mIsSystemExpanded; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 168 | |
| 169 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 170 | * Whether the notification is on the keyguard and the expansion is disabled. |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 171 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 172 | private boolean mOnKeyguard; |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 173 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 174 | private Animator mTranslateAnim; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 175 | private ArrayList<View> mTranslateableViews; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 176 | private NotificationContentView mPublicLayout; |
| 177 | private NotificationContentView mPrivateLayout; |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 178 | private NotificationContentView[] mLayouts; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 179 | private int mNotificationColor; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 180 | private ExpansionLogger mLogger; |
| 181 | private String mLoggingKey; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 182 | private NotificationGuts mGuts; |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 183 | private NotificationData.Entry mEntry; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 184 | private StatusBarNotification mStatusBarNotification; |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 185 | private String mAppName; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 186 | private boolean mIsHeadsUp; |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 187 | private boolean mLastChronometerRunning = true; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 188 | private ViewStub mChildrenContainerStub; |
| 189 | private NotificationGroupManager mGroupManager; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 190 | private boolean mChildrenExpanded; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 191 | private boolean mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 192 | private NotificationChildrenContainer mChildrenContainer; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 193 | private NotificationMenuRowPlugin mMenuRow; |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 194 | private ViewStub mGutsStub; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 195 | private boolean mIsSystemChildExpanded; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 196 | private boolean mIsPinned; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 197 | private FalsingManager mFalsingManager; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 198 | private boolean mExpandAnimationRunning; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 199 | private AboveShelfChangedListener mAboveShelfChangedListener; |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 200 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 201 | private Consumer<Boolean> mHeadsUpAnimatingAwayListener; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 202 | private boolean mChildIsExpanding; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 203 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 204 | private boolean mJustClicked; |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 205 | private boolean mIconAnimationRunning; |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 206 | private boolean mShowNoBackground; |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 207 | private ExpandableNotificationRow mNotificationParent; |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 208 | private OnExpandClickListener mOnExpandClickListener; |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 209 | private View.OnClickListener mOnAppOpsClickListener; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 210 | |
| 211 | // Listener will be called when receiving a long click event. |
| 212 | // Use #setLongPressPosition to optionally assign positional data with the long press. |
| 213 | private LongPressListener mLongPressListener; |
| 214 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 215 | private boolean mGroupExpansionChanging; |
| 216 | |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 217 | /** |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 218 | * A supplier that returns true if keyguard is secure. |
| 219 | */ |
| 220 | private BooleanSupplier mSecureStateProvider; |
| 221 | |
| 222 | /** |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 223 | * Whether or not a notification that is not part of a group of notifications can be manually |
| 224 | * expanded by the user. |
| 225 | */ |
| 226 | private boolean mEnableNonGroupedNotificationExpand; |
| 227 | |
| 228 | /** |
| 229 | * Whether or not to update the background of the header of the notification when its expanded. |
| 230 | * If {@code true}, the header background will disappear when expanded. |
| 231 | */ |
| 232 | private boolean mShowGroupBackgroundWhenExpanded; |
| 233 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 234 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 235 | @Override |
| 236 | public void onClick(View v) { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 237 | if (!shouldShowPublic() && (!mIsLowPriority || isExpanded()) |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 238 | && mGroupManager.isSummaryOfGroup(mStatusBarNotification)) { |
Mady Mellor | 1a5d8ea | 2016-06-09 10:42:42 -0700 | [diff] [blame] | 239 | mGroupExpansionChanging = true; |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 240 | final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
| 241 | boolean nowExpanded = mGroupManager.toggleGroupExpansion(mStatusBarNotification); |
| 242 | mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 243 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_GROUP_EXPANDER, |
| 244 | nowExpanded); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 245 | onExpansionChanged(true /* userAction */, wasExpanded); |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 246 | } else if (mEnableNonGroupedNotificationExpand) { |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 247 | if (v.isAccessibilityFocused()) { |
| 248 | mPrivateLayout.setFocusOnVisibilityChange(); |
| 249 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 250 | boolean nowExpanded; |
| 251 | if (isPinned()) { |
| 252 | nowExpanded = !mExpandedWhenPinned; |
| 253 | mExpandedWhenPinned = nowExpanded; |
| 254 | } else { |
| 255 | nowExpanded = !isExpanded(); |
| 256 | setUserExpanded(nowExpanded); |
| 257 | } |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 258 | notifyHeightChanged(true); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 259 | mOnExpandClickListener.onExpandClicked(mEntry, nowExpanded); |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 260 | MetricsLogger.action(mContext, MetricsEvent.ACTION_NOTIFICATION_EXPANDER, |
| 261 | nowExpanded); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 262 | } |
| 263 | } |
| 264 | }; |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 265 | private boolean mForceUnlocked; |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 266 | private boolean mDismissed; |
| 267 | private boolean mKeepInParent; |
| 268 | private boolean mRemoved; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 269 | private static final Property<ExpandableNotificationRow, Float> TRANSLATE_CONTENT = |
| 270 | new FloatProperty<ExpandableNotificationRow>("translate") { |
| 271 | @Override |
| 272 | public void setValue(ExpandableNotificationRow object, float value) { |
| 273 | object.setTranslation(value); |
| 274 | } |
| 275 | |
| 276 | @Override |
| 277 | public Float get(ExpandableNotificationRow object) { |
| 278 | return object.getTranslation(); |
| 279 | } |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 280 | }; |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 281 | private OnClickListener mOnClickListener; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 282 | private boolean mHeadsupDisappearRunning; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 283 | private View mChildAfterViewWhenDismissed; |
| 284 | private View mGroupParentWhenDismissed; |
| 285 | private boolean mRefocusOnDismiss; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 286 | private float mContentTransformationAmount; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 287 | private boolean mIconsVisible = true; |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 288 | private boolean mAboveShelf; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 289 | private boolean mShowAmbient; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 290 | private boolean mIsLastChild; |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 291 | private Runnable mOnDismissRunnable; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 292 | private boolean mIsLowPriority; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 293 | private boolean mIsColorized; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 294 | private boolean mUseIncreasedCollapsedHeight; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 295 | private boolean mUseIncreasedHeadsUpHeight; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 296 | private float mTranslationWhenRemoved; |
| 297 | private boolean mWasChildInGroupWhenRemoved; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 298 | private int mNotificationColorAmbient; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 299 | private NotificationViewState mNotificationViewState; |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 300 | |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 301 | private SystemNotificationAsyncTask mSystemNotificationAsyncTask = |
| 302 | new SystemNotificationAsyncTask(); |
| 303 | |
| 304 | /** |
| 305 | * Returns whether the given {@code statusBarNotification} is a system notification. |
| 306 | * <b>Note</b>, this should be run in the background thread if possible as it makes multiple IPC |
| 307 | * calls. |
| 308 | */ |
| 309 | private static Boolean isSystemNotification( |
| 310 | Context context, StatusBarNotification statusBarNotification) { |
| 311 | PackageManager packageManager = StatusBar.getPackageManagerForUser( |
| 312 | context, statusBarNotification.getUser().getIdentifier()); |
| 313 | Boolean isSystemNotification = null; |
| 314 | |
| 315 | try { |
| 316 | PackageInfo packageInfo = packageManager.getPackageInfo( |
| 317 | statusBarNotification.getPackageName(), PackageManager.GET_SIGNATURES); |
| 318 | |
| 319 | isSystemNotification = |
| 320 | com.android.settingslib.Utils.isSystemPackage( |
| 321 | context.getResources(), packageManager, packageInfo); |
| 322 | } catch (PackageManager.NameNotFoundException e) { |
| 323 | Log.e(TAG, "cacheIsSystemNotification: Could not find package info"); |
| 324 | } |
| 325 | return isSystemNotification; |
| 326 | } |
| 327 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 328 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 329 | public boolean isGroupExpansionChanging() { |
| 330 | if (isChildInGroup()) { |
| 331 | return mNotificationParent.isGroupExpansionChanging(); |
| 332 | } |
| 333 | return mGroupExpansionChanging; |
| 334 | } |
| 335 | |
| 336 | public void setGroupExpansionChanging(boolean changing) { |
| 337 | mGroupExpansionChanging = changing; |
| 338 | } |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 339 | |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 340 | @Override |
| 341 | public void setActualHeightAnimating(boolean animating) { |
| 342 | if (mPrivateLayout != null) { |
| 343 | mPrivateLayout.setContentHeightAnimating(animating); |
| 344 | } |
| 345 | } |
| 346 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 347 | public NotificationContentView getPrivateLayout() { |
| 348 | return mPrivateLayout; |
| 349 | } |
| 350 | |
| 351 | public NotificationContentView getPublicLayout() { |
| 352 | return mPublicLayout; |
| 353 | } |
| 354 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 355 | public void setIconAnimationRunning(boolean running) { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 356 | for (NotificationContentView l : mLayouts) { |
| 357 | setIconAnimationRunning(running, l); |
| 358 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 359 | if (mIsSummaryWithChildren) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 360 | setIconAnimationRunningForChild(running, mChildrenContainer.getHeaderView()); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 361 | setIconAnimationRunningForChild(running, mChildrenContainer.getLowPriorityHeaderView()); |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 362 | List<ExpandableNotificationRow> notificationChildren = |
| 363 | mChildrenContainer.getNotificationChildren(); |
| 364 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 365 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 366 | child.setIconAnimationRunning(running); |
| 367 | } |
| 368 | } |
| 369 | mIconAnimationRunning = running; |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | private void setIconAnimationRunning(boolean running, NotificationContentView layout) { |
| 373 | if (layout != null) { |
| 374 | View contractedChild = layout.getContractedChild(); |
| 375 | View expandedChild = layout.getExpandedChild(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 376 | View headsUpChild = layout.getHeadsUpChild(); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 377 | setIconAnimationRunningForChild(running, contractedChild); |
| 378 | setIconAnimationRunningForChild(running, expandedChild); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 379 | setIconAnimationRunningForChild(running, headsUpChild); |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 380 | } |
| 381 | } |
| 382 | |
| 383 | private void setIconAnimationRunningForChild(boolean running, View child) { |
| 384 | if (child != null) { |
| 385 | ImageView icon = (ImageView) child.findViewById(com.android.internal.R.id.icon); |
| 386 | setIconRunning(icon, running); |
| 387 | ImageView rightIcon = (ImageView) child.findViewById( |
| 388 | com.android.internal.R.id.right_icon); |
| 389 | setIconRunning(rightIcon, running); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | private void setIconRunning(ImageView imageView, boolean running) { |
| 394 | if (imageView != null) { |
| 395 | Drawable drawable = imageView.getDrawable(); |
| 396 | if (drawable instanceof AnimationDrawable) { |
| 397 | AnimationDrawable animationDrawable = (AnimationDrawable) drawable; |
| 398 | if (running) { |
| 399 | animationDrawable.start(); |
| 400 | } else { |
| 401 | animationDrawable.stop(); |
| 402 | } |
| 403 | } else if (drawable instanceof AnimatedVectorDrawable) { |
| 404 | AnimatedVectorDrawable animationDrawable = (AnimatedVectorDrawable) drawable; |
| 405 | if (running) { |
| 406 | animationDrawable.start(); |
| 407 | } else { |
| 408 | animationDrawable.stop(); |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | } |
| 413 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 414 | public void updateNotification(NotificationData.Entry entry) { |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 415 | mEntry = entry; |
| 416 | mStatusBarNotification = entry.notification; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 417 | mNotificationInflater.inflateNotificationViews(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 418 | |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 419 | cacheIsSystemNotification(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /** |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 423 | * Caches whether or not this row contains a system notification. Note, this is only cached |
| 424 | * once per notification as the packageInfo can't technically change for a notification row. |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 425 | */ |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 426 | private void cacheIsSystemNotification() { |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 427 | if (mEntry != null && mEntry.mIsSystemNotification == null) { |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 428 | if (mSystemNotificationAsyncTask.getStatus() == AsyncTask.Status.PENDING) { |
| 429 | // Run async task once, only if it hasn't already been executed. Note this is |
| 430 | // executed in serial - no need to parallelize this small task. |
| 431 | mSystemNotificationAsyncTask.execute(); |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /** |
Rohan Shah | ca0447e | 2018-03-30 15:18:27 -0700 | [diff] [blame] | 437 | * Returns whether this row is considered non-blockable (i.e. it's a non-blockable system notif |
| 438 | * or is in a whitelist). |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 439 | */ |
| 440 | public boolean getIsNonblockable() { |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 441 | boolean isNonblockable = Dependency.get(NotificationBlockingHelperManager.class) |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 442 | .isNonblockablePackage(mStatusBarNotification.getPackageName()); |
| 443 | |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 444 | // If the SystemNotifAsyncTask hasn't finished running or retrieved a value, we'll try once |
| 445 | // again, but in-place on the main thread this time. This should rarely ever get called. |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 446 | if (mEntry != null && mEntry.mIsSystemNotification == null) { |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 447 | if (DEBUG) { |
| 448 | Log.d(TAG, "Retrieving isSystemNotification on main thread"); |
| 449 | } |
| 450 | mSystemNotificationAsyncTask.cancel(true /* mayInterruptIfRunning */); |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 451 | mEntry.mIsSystemNotification = isSystemNotification(mContext, mStatusBarNotification); |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 454 | if (!isNonblockable && mEntry != null && mEntry.mIsSystemNotification != null) { |
| 455 | if (mEntry.mIsSystemNotification) { |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 456 | if (mEntry.channel != null |
| 457 | && !mEntry.channel.isBlockableSystem()) { |
| 458 | isNonblockable = true; |
| 459 | } |
| 460 | } |
| 461 | } |
| 462 | return isNonblockable; |
Selim Cinek | c478f90 | 2017-02-22 20:55:44 -0800 | [diff] [blame] | 463 | } |
| 464 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 465 | public void onNotificationUpdated() { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 466 | for (NotificationContentView l : mLayouts) { |
Selim Cinek | c478f90 | 2017-02-22 20:55:44 -0800 | [diff] [blame] | 467 | l.onNotificationUpdated(mEntry); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 468 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 469 | mIsColorized = mStatusBarNotification.getNotification().isColorized(); |
Selim Cinek | 757d879 | 2016-01-28 16:21:08 -0800 | [diff] [blame] | 470 | mShowingPublicInitialized = false; |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 471 | updateNotificationColor(); |
Mady Mellor | 4c19760 | 2017-04-10 17:57:52 -0700 | [diff] [blame] | 472 | if (mMenuRow != null) { |
Mady Mellor | 4ab2820 | 2017-06-06 11:42:50 -0700 | [diff] [blame] | 473 | mMenuRow.onNotificationUpdated(mStatusBarNotification); |
Beverly | 3f56f05 | 2018-05-08 14:56:03 -0400 | [diff] [blame] | 474 | mMenuRow.setAppName(mAppName); |
Mady Mellor | 4c19760 | 2017-04-10 17:57:52 -0700 | [diff] [blame] | 475 | } |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 476 | if (mIsSummaryWithChildren) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 477 | mChildrenContainer.recreateNotificationHeader(mExpandClickListener); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 478 | mChildrenContainer.onNotificationUpdated(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 479 | } |
Selim Cinek | 5a175d9 | 2015-11-23 18:01:33 -0800 | [diff] [blame] | 480 | if (mIconAnimationRunning) { |
| 481 | setIconAnimationRunning(true); |
| 482 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 483 | if (mNotificationParent != null) { |
| 484 | mNotificationParent.updateChildrenHeaderAppearance(); |
| 485 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 486 | onChildrenCountChanged(); |
Selim Cinek | 624c02db | 2015-12-14 21:00:02 -0800 | [diff] [blame] | 487 | // The public layouts expand button is always visible |
| 488 | mPublicLayout.updateExpandButtons(true); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 489 | updateLimits(); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 490 | updateIconVisibilities(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 491 | updateShelfIconColor(); |
Selim Cinek | fe24fb7 | 2018-02-13 14:34:55 -0800 | [diff] [blame] | 492 | updateRippleAllowed(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 495 | @VisibleForTesting |
| 496 | void updateShelfIconColor() { |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 497 | StatusBarIconView expandedIcon = mEntry.expandedIcon; |
| 498 | boolean isPreL = Boolean.TRUE.equals(expandedIcon.getTag(R.id.icon_is_pre_L)); |
| 499 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(expandedIcon, |
| 500 | NotificationColorUtil.getInstance(mContext)); |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 501 | int color = StatusBarIconView.NO_COLOR; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 502 | if (colorize) { |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 503 | NotificationHeaderView header = getVisibleNotificationHeader(); |
| 504 | if (header != null) { |
| 505 | color = header.getOriginalIconColor(); |
| 506 | } else { |
| 507 | color = mEntry.getContrastedColor(mContext, mIsLowPriority && !isExpanded(), |
| 508 | getBackgroundColorWithoutTint()); |
| 509 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 510 | } |
Selim Cinek | 875ba9b | 2017-02-13 16:20:17 -0800 | [diff] [blame] | 511 | expandedIcon.setStaticDrawableColor(color); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 512 | } |
| 513 | |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 514 | public void setAboveShelfChangedListener(AboveShelfChangedListener aboveShelfChangedListener) { |
| 515 | mAboveShelfChangedListener = aboveShelfChangedListener; |
| 516 | } |
| 517 | |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 518 | /** |
| 519 | * Sets a supplier that can determine whether the keyguard is secure or not. |
| 520 | * @param secureStateProvider A function that returns true if keyguard is secure. |
| 521 | */ |
| 522 | public void setSecureStateProvider(BooleanSupplier secureStateProvider) { |
| 523 | mSecureStateProvider = secureStateProvider; |
| 524 | } |
| 525 | |
Selim Cinek | 4705f29 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 526 | @Override |
| 527 | public boolean isDimmable() { |
| 528 | if (!getShowingLayout().isDimmable()) { |
| 529 | return false; |
| 530 | } |
| 531 | return super.isDimmable(); |
| 532 | } |
| 533 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 534 | private void updateLimits() { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 535 | for (NotificationContentView l : mLayouts) { |
| 536 | updateLimitsForView(l); |
| 537 | } |
Selim Cinek | a174487 | 2016-03-11 15:36:06 -0800 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | private void updateLimitsForView(NotificationContentView layout) { |
| 541 | boolean customView = layout.getContractedChild().getId() |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 542 | != com.android.internal.R.id.status_bar_latest_event_content; |
| 543 | boolean beforeN = mEntry.targetSdk < Build.VERSION_CODES.N; |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 544 | boolean beforeP = mEntry.targetSdk < Build.VERSION_CODES.P; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 545 | int minHeight; |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 546 | if (customView && beforeP && !mIsSummaryWithChildren) { |
| 547 | minHeight = beforeN ? mNotificationMinHeightLegacy : mNotificationMinHeightBeforeP; |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 548 | } else if (mUseIncreasedCollapsedHeight && layout == mPrivateLayout) { |
| 549 | minHeight = mNotificationMinHeightLarge; |
| 550 | } else { |
| 551 | minHeight = mNotificationMinHeight; |
| 552 | } |
Selim Cinek | a174487 | 2016-03-11 15:36:06 -0800 | [diff] [blame] | 553 | boolean headsUpCustom = layout.getHeadsUpChild() != null && |
| 554 | layout.getHeadsUpChild().getId() |
| 555 | != com.android.internal.R.id.status_bar_latest_event_content; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 556 | int headsUpheight; |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 557 | if (headsUpCustom && beforeP) { |
| 558 | headsUpheight = beforeN ? mMaxHeadsUpHeightLegacy : mMaxHeadsUpHeightBeforeP; |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 559 | } else if (mUseIncreasedHeadsUpHeight && layout == mPrivateLayout) { |
| 560 | headsUpheight = mMaxHeadsUpHeightIncreased; |
| 561 | } else { |
| 562 | headsUpheight = mMaxHeadsUpHeight; |
| 563 | } |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 564 | NotificationViewWrapper headsUpWrapper = layout.getVisibleWrapper( |
| 565 | NotificationContentView.VISIBLE_TYPE_HEADSUP); |
| 566 | if (headsUpWrapper != null) { |
| 567 | headsUpheight = Math.max(headsUpheight, headsUpWrapper.getMinLayoutHeight()); |
| 568 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 569 | layout.setHeights(minHeight, headsUpheight, mNotificationMaxHeight, |
| 570 | mNotificationAmbientHeight); |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | public StatusBarNotification getStatusBarNotification() { |
| 574 | return mStatusBarNotification; |
| 575 | } |
| 576 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 577 | public NotificationData.Entry getEntry() { |
| 578 | return mEntry; |
| 579 | } |
| 580 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 581 | public boolean isHeadsUp() { |
| 582 | return mIsHeadsUp; |
| 583 | } |
| 584 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 585 | public void setHeadsUp(boolean isHeadsUp) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 586 | boolean wasAboveShelf = isAboveShelf(); |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 587 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 588 | mIsHeadsUp = isHeadsUp; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 589 | mPrivateLayout.setHeadsUp(isHeadsUp); |
Selim Cinek | b41b2f6 | 2016-04-26 14:03:29 -0700 | [diff] [blame] | 590 | if (mIsSummaryWithChildren) { |
| 591 | // The overflow might change since we allow more lines as HUN. |
| 592 | mChildrenContainer.updateGroupOverflow(); |
| 593 | } |
Selim Cinek | c80fdb1 | 2015-04-13 15:09:08 -0700 | [diff] [blame] | 594 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 595 | notifyHeightChanged(false /* needsAnimation */); |
| 596 | } |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 597 | if (isHeadsUp) { |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 598 | mMustStayOnScreen = true; |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 599 | setAboveShelf(true); |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 600 | } else if (isAboveShelf() != wasAboveShelf) { |
| 601 | mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 602 | } |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 603 | } |
| 604 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 605 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 606 | mGroupManager = groupManager; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 607 | mPrivateLayout.setGroupManager(groupManager); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 608 | } |
| 609 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 610 | public void setRemoteInputController(RemoteInputController r) { |
| 611 | mPrivateLayout.setRemoteInputController(r); |
| 612 | } |
| 613 | |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 614 | public void setAppName(String appName) { |
| 615 | mAppName = appName; |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 616 | if (mMenuRow != null && mMenuRow.getMenuView() != null) { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 617 | mMenuRow.setAppName(mAppName); |
Mady Mellor | 3fd273e | 2016-03-15 21:08:14 -0700 | [diff] [blame] | 618 | } |
| 619 | } |
| 620 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 621 | public void addChildNotification(ExpandableNotificationRow row) { |
| 622 | addChildNotification(row, -1); |
| 623 | } |
| 624 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 625 | /** |
| 626 | * Set the how much the header should be visible. A value of 0 will make the header fully gone |
| 627 | * and a value of 1 will make the notification look just like normal. |
| 628 | * This is being used for heads up notifications, when they are pinned to the top of the screen |
| 629 | * and the header content is extracted to the statusbar. |
| 630 | * |
| 631 | * @param headerVisibleAmount the amount the header should be visible. |
| 632 | */ |
| 633 | public void setHeaderVisibleAmount(float headerVisibleAmount) { |
| 634 | if (mHeaderVisibleAmount != headerVisibleAmount) { |
| 635 | mHeaderVisibleAmount = headerVisibleAmount; |
| 636 | mPrivateLayout.setHeaderVisibleAmount(headerVisibleAmount); |
| 637 | if (mChildrenContainer != null) { |
| 638 | mChildrenContainer.setHeaderVisibleAmount(headerVisibleAmount); |
| 639 | } |
| 640 | notifyHeightChanged(false /* needsAnimation */); |
| 641 | } |
| 642 | } |
| 643 | |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 644 | @Override |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 645 | public float getHeaderVisibleAmount() { |
| 646 | return mHeaderVisibleAmount; |
| 647 | } |
| 648 | |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 649 | @Override |
| 650 | public void setHeadsUpIsVisible() { |
| 651 | super.setHeadsUpIsVisible(); |
| 652 | mMustStayOnScreen = false; |
| 653 | } |
| 654 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 655 | /** |
| 656 | * Add a child notification to this view. |
| 657 | * |
| 658 | * @param row the row to add |
| 659 | * @param childIndex the index to add it at, if -1 it will be added at the end |
| 660 | */ |
| 661 | public void addChildNotification(ExpandableNotificationRow row, int childIndex) { |
| 662 | if (mChildrenContainer == null) { |
| 663 | mChildrenContainerStub.inflate(); |
| 664 | } |
| 665 | mChildrenContainer.addNotification(row, childIndex); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 666 | onChildrenCountChanged(); |
| 667 | row.setIsChildInGroup(true, this); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 668 | } |
| 669 | |
| 670 | public void removeChildNotification(ExpandableNotificationRow row) { |
| 671 | if (mChildrenContainer != null) { |
| 672 | mChildrenContainer.removeNotification(row); |
| 673 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 674 | onChildrenCountChanged(); |
| 675 | row.setIsChildInGroup(false, null); |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 676 | row.setBottomRoundness(0.0f, false /* animate */); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 679 | @Override |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 680 | public boolean isChildInGroup() { |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 681 | return mNotificationParent != null; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 684 | /** |
| 685 | * @return whether this notification is the only child in the group summary |
| 686 | */ |
| 687 | public boolean isOnlyChildInGroup() { |
| 688 | return mGroupManager.isOnlyChildInGroup(getStatusBarNotification()); |
| 689 | } |
| 690 | |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 691 | public ExpandableNotificationRow getNotificationParent() { |
| 692 | return mNotificationParent; |
| 693 | } |
| 694 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 695 | /** |
| 696 | * @param isChildInGroup Is this notification now in a group |
| 697 | * @param parent the new parent notification |
| 698 | */ |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 699 | public void setIsChildInGroup(boolean isChildInGroup, ExpandableNotificationRow parent) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 700 | boolean childInGroup = StatusBar.ENABLE_CHILD_NOTIFICATIONS && isChildInGroup; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 701 | if (mExpandAnimationRunning && !isChildInGroup && mNotificationParent != null) { |
| 702 | mNotificationParent.setChildIsExpanding(false); |
| 703 | mNotificationParent.setExtraWidthForClipping(0.0f); |
| 704 | mNotificationParent.setMinimumHeightForClipping(0); |
| 705 | } |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 706 | mNotificationParent = childInGroup ? parent : null; |
| 707 | mPrivateLayout.setIsChildInGroup(childInGroup); |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 708 | mNotificationInflater.setIsChildInGroup(childInGroup); |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 709 | resetBackgroundAlpha(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 710 | updateBackgroundForGroupState(); |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 711 | updateClickAndFocus(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 712 | if (mNotificationParent != null) { |
Selim Cinek | 9ce3285 | 2017-02-15 16:21:10 -0800 | [diff] [blame] | 713 | setOverrideTintColor(NO_COLOR, 0.0f); |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 714 | // Let's reset the distance to top roundness, as this isn't applied to group children |
| 715 | setDistanceToTopRoundness(NO_ROUNDNESS); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 716 | mNotificationParent.updateBackgroundForGroupState(); |
| 717 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 718 | updateIconVisibilities(); |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 719 | updateBackgroundClipping(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | @Override |
Selim Cinek | 7210947 | 2016-01-15 16:33:22 -0800 | [diff] [blame] | 723 | public boolean onTouchEvent(MotionEvent event) { |
| 724 | if (event.getActionMasked() != MotionEvent.ACTION_DOWN |
| 725 | || !isChildInGroup() || isGroupExpanded()) { |
| 726 | return super.onTouchEvent(event); |
| 727 | } else { |
| 728 | return false; |
| 729 | } |
| 730 | } |
| 731 | |
| 732 | @Override |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 733 | protected boolean handleSlideBack() { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 734 | if (mMenuRow != null && mMenuRow.isMenuVisible()) { |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 735 | animateTranslateNotification(0 /* targetLeft */); |
| 736 | return true; |
| 737 | } |
| 738 | return false; |
| 739 | } |
| 740 | |
| 741 | @Override |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 742 | protected boolean shouldHideBackground() { |
| 743 | return super.shouldHideBackground() || mShowNoBackground; |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 744 | } |
| 745 | |
| 746 | @Override |
| 747 | public boolean isSummaryWithChildren() { |
| 748 | return mIsSummaryWithChildren; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | @Override |
| 752 | public boolean areChildrenExpanded() { |
| 753 | return mChildrenExpanded; |
| 754 | } |
| 755 | |
| 756 | public List<ExpandableNotificationRow> getNotificationChildren() { |
| 757 | return mChildrenContainer == null ? null : mChildrenContainer.getNotificationChildren(); |
| 758 | } |
| 759 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 760 | public int getNumberOfNotificationChildren() { |
| 761 | if (mChildrenContainer == null) { |
| 762 | return 0; |
| 763 | } |
| 764 | return mChildrenContainer.getNotificationChildren().size(); |
| 765 | } |
| 766 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 767 | /** |
| 768 | * Apply the order given in the list to the children. |
| 769 | * |
| 770 | * @param childOrder the new list order |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 771 | * @param visualStabilityManager |
| 772 | * @param callback the callback to invoked in case it is not allowed |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 773 | * @return whether the list order has changed |
| 774 | */ |
Selim Cinek | a7d4f82 | 2016-12-06 14:34:47 -0800 | [diff] [blame] | 775 | public boolean applyChildOrder(List<ExpandableNotificationRow> childOrder, |
| 776 | VisualStabilityManager visualStabilityManager, |
| 777 | VisualStabilityManager.Callback callback) { |
| 778 | return mChildrenContainer != null && mChildrenContainer.applyChildOrder(childOrder, |
| 779 | visualStabilityManager, callback); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 780 | } |
| 781 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 782 | public void getChildrenStates(StackScrollState resultState, |
| 783 | AmbientState ambientState) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 784 | if (mIsSummaryWithChildren) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 785 | ExpandableViewState parentState = resultState.getViewStateForView(this); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 786 | mChildrenContainer.getState(resultState, parentState, ambientState); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 787 | } |
| 788 | } |
| 789 | |
| 790 | public void applyChildrenState(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 791 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 792 | mChildrenContainer.applyState(state); |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | public void prepareExpansionChanged(StackScrollState state) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 797 | if (mIsSummaryWithChildren) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 798 | mChildrenContainer.prepareExpansionChanged(state); |
| 799 | } |
| 800 | } |
| 801 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 802 | public void startChildAnimation(StackScrollState finalState, AnimationProperties properties) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 803 | if (mIsSummaryWithChildren) { |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 804 | mChildrenContainer.startAnimationToState(finalState, properties); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | |
| 808 | public ExpandableNotificationRow getViewAtPosition(float y) { |
Selim Cinek | 43d30f0 | 2016-03-04 10:51:32 -0800 | [diff] [blame] | 809 | if (!mIsSummaryWithChildren || !mChildrenExpanded) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 810 | return this; |
| 811 | } else { |
| 812 | ExpandableNotificationRow view = mChildrenContainer.getViewAtPosition(y); |
| 813 | return view == null ? this : view; |
| 814 | } |
| 815 | } |
| 816 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 817 | public NotificationGuts getGuts() { |
| 818 | return mGuts; |
| 819 | } |
| 820 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 821 | /** |
| 822 | * Set this notification to be pinned to the top if {@link #isHeadsUp()} is true. By doing this |
| 823 | * the notification will be rendered on top of the screen. |
| 824 | * |
| 825 | * @param pinned whether it is pinned |
| 826 | */ |
| 827 | public void setPinned(boolean pinned) { |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 828 | int intrinsicHeight = getIntrinsicHeight(); |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 829 | boolean wasAboveShelf = isAboveShelf(); |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 830 | mIsPinned = pinned; |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 831 | if (intrinsicHeight != getIntrinsicHeight()) { |
Selim Cinek | bb42b7d | 2016-08-10 13:02:38 -0700 | [diff] [blame] | 832 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | def35a8 | 2016-05-03 15:52:51 -0700 | [diff] [blame] | 833 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 834 | if (pinned) { |
| 835 | setIconAnimationRunning(true); |
| 836 | mExpandedWhenPinned = false; |
| 837 | } else if (mExpandedWhenPinned) { |
| 838 | setUserExpanded(true); |
| 839 | } |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 840 | setChronometerRunning(mLastChronometerRunning); |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 841 | if (isAboveShelf() != wasAboveShelf) { |
| 842 | mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf); |
| 843 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 846 | @Override |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 847 | public boolean isPinned() { |
| 848 | return mIsPinned; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 849 | } |
| 850 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 851 | @Override |
| 852 | public int getPinnedHeadsUpHeight() { |
| 853 | return getPinnedHeadsUpHeight(true /* atLeastMinHeight */); |
| 854 | } |
| 855 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 856 | /** |
| 857 | * @param atLeastMinHeight should the value returned be at least the minimum height. |
| 858 | * Used to avoid cyclic calls |
| 859 | * @return the height of the heads up notification when pinned |
| 860 | */ |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 861 | private int getPinnedHeadsUpHeight(boolean atLeastMinHeight) { |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 862 | if (mIsSummaryWithChildren) { |
| 863 | return mChildrenContainer.getIntrinsicHeight(); |
| 864 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 865 | if(mExpandedWhenPinned) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 866 | return Math.max(getMaxExpandHeight(), getHeadsUpHeight()); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 867 | } else if (atLeastMinHeight) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 868 | return Math.max(getCollapsedHeight(), getHeadsUpHeight()); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 869 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 870 | return getHeadsUpHeight(); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 871 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 872 | } |
| 873 | |
Jorim Jaggi | 5eb67c2 | 2015-08-19 19:50:49 -0700 | [diff] [blame] | 874 | /** |
| 875 | * Mark whether this notification was just clicked, i.e. the user has just clicked this |
| 876 | * notification in this frame. |
| 877 | */ |
| 878 | public void setJustClicked(boolean justClicked) { |
| 879 | mJustClicked = justClicked; |
| 880 | } |
| 881 | |
| 882 | /** |
| 883 | * @return true if this notification has been clicked in this frame, false otherwise |
| 884 | */ |
| 885 | public boolean wasJustClicked() { |
| 886 | return mJustClicked; |
| 887 | } |
| 888 | |
Selim Cinek | 98713a4 | 2015-09-21 15:47:20 +0200 | [diff] [blame] | 889 | public void setChronometerRunning(boolean running) { |
| 890 | mLastChronometerRunning = running; |
| 891 | setChronometerRunning(running, mPrivateLayout); |
| 892 | setChronometerRunning(running, mPublicLayout); |
| 893 | if (mChildrenContainer != null) { |
| 894 | List<ExpandableNotificationRow> notificationChildren = |
| 895 | mChildrenContainer.getNotificationChildren(); |
| 896 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 897 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 898 | child.setChronometerRunning(running); |
| 899 | } |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | private void setChronometerRunning(boolean running, NotificationContentView layout) { |
| 904 | if (layout != null) { |
| 905 | running = running || isPinned(); |
| 906 | View contractedChild = layout.getContractedChild(); |
| 907 | View expandedChild = layout.getExpandedChild(); |
| 908 | View headsUpChild = layout.getHeadsUpChild(); |
| 909 | setChronometerRunningForChild(running, contractedChild); |
| 910 | setChronometerRunningForChild(running, expandedChild); |
| 911 | setChronometerRunningForChild(running, headsUpChild); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | private void setChronometerRunningForChild(boolean running, View child) { |
| 916 | if (child != null) { |
| 917 | View chronometer = child.findViewById(com.android.internal.R.id.chronometer); |
| 918 | if (chronometer instanceof Chronometer) { |
| 919 | ((Chronometer) chronometer).setStarted(running); |
| 920 | } |
| 921 | } |
| 922 | } |
| 923 | |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 924 | public NotificationHeaderView getNotificationHeader() { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 925 | if (mIsSummaryWithChildren) { |
| 926 | return mChildrenContainer.getHeaderView(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 927 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 928 | return mPrivateLayout.getNotificationHeader(); |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 931 | /** |
| 932 | * @return the currently visible notification header. This can be different from |
| 933 | * {@link #getNotificationHeader()} in case it is a low-priority group. |
| 934 | */ |
| 935 | public NotificationHeaderView getVisibleNotificationHeader() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 936 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 937 | return mChildrenContainer.getVisibleHeader(); |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 938 | } |
| 939 | return getShowingLayout().getVisibleNotificationHeader(); |
| 940 | } |
| 941 | |
Selim Cinek | b26afa3 | 2017-06-29 10:28:17 +0200 | [diff] [blame] | 942 | |
| 943 | /** |
| 944 | * @return the contracted notification header. This can be different from |
| 945 | * {@link #getNotificationHeader()} and also {@link #getVisibleNotificationHeader()} and only |
| 946 | * returns the contracted version. |
| 947 | */ |
| 948 | public NotificationHeaderView getContractedNotificationHeader() { |
| 949 | if (mIsSummaryWithChildren) { |
| 950 | return mChildrenContainer.getHeaderView(); |
| 951 | } |
| 952 | return mPrivateLayout.getContractedNotificationHeader(); |
| 953 | } |
| 954 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 955 | public void setOnExpandClickListener(OnExpandClickListener onExpandClickListener) { |
| 956 | mOnExpandClickListener = onExpandClickListener; |
| 957 | } |
| 958 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 959 | public void setLongPressListener(LongPressListener longPressListener) { |
| 960 | mLongPressListener = longPressListener; |
| 961 | } |
| 962 | |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 963 | @Override |
| 964 | public void setOnClickListener(@Nullable OnClickListener l) { |
| 965 | super.setOnClickListener(l); |
| 966 | mOnClickListener = l; |
| 967 | updateClickAndFocus(); |
| 968 | } |
| 969 | |
| 970 | private void updateClickAndFocus() { |
| 971 | boolean normalChild = !isChildInGroup() || isGroupExpanded(); |
| 972 | boolean clickable = mOnClickListener != null && normalChild; |
| 973 | if (isFocusable() != normalChild) { |
| 974 | setFocusable(normalChild); |
| 975 | } |
| 976 | if (isClickable() != clickable) { |
| 977 | setClickable(clickable); |
| 978 | } |
| 979 | } |
| 980 | |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 981 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 982 | mHeadsUpManager = headsUpManager; |
| 983 | } |
| 984 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 985 | public void setGutsView(MenuItem item) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 986 | if (mGuts != null && item.getGutsView() instanceof GutsContent) { |
| 987 | ((GutsContent) item.getGutsView()).setGutsParent(mGuts); |
| 988 | mGuts.setGutsContent((GutsContent) item.getGutsView()); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 989 | } |
| 990 | } |
| 991 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 992 | @Override |
| 993 | protected void onAttachedToWindow() { |
| 994 | super.onAttachedToWindow(); |
| 995 | Dependency.get(PluginManager.class).addPluginListener(this, |
| 996 | NotificationMenuRowPlugin.class, false /* Allow multiple */); |
| 997 | } |
| 998 | |
| 999 | @Override |
| 1000 | protected void onDetachedFromWindow() { |
| 1001 | super.onDetachedFromWindow(); |
| 1002 | Dependency.get(PluginManager.class).removePluginListener(this); |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
| 1006 | public void onPluginConnected(NotificationMenuRowPlugin plugin, Context pluginContext) { |
| 1007 | boolean existed = mMenuRow.getMenuView() != null; |
| 1008 | if (existed) { |
| 1009 | removeView(mMenuRow.getMenuView()); |
| 1010 | } |
| 1011 | mMenuRow = plugin; |
| 1012 | if (mMenuRow.useDefaultMenuItems()) { |
Mady Mellor | 4c19760 | 2017-04-10 17:57:52 -0700 | [diff] [blame] | 1013 | ArrayList<MenuItem> items = new ArrayList<>(); |
| 1014 | items.add(NotificationMenuRow.createInfoItem(mContext)); |
| 1015 | items.add(NotificationMenuRow.createSnoozeItem(mContext)); |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 1016 | items.add(NotificationMenuRow.createAppOpsItem(mContext)); |
Mady Mellor | 4c19760 | 2017-04-10 17:57:52 -0700 | [diff] [blame] | 1017 | mMenuRow.setMenuItems(items); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1018 | } |
| 1019 | if (existed) { |
| 1020 | createMenu(); |
| 1021 | } |
| 1022 | } |
| 1023 | |
| 1024 | @Override |
| 1025 | public void onPluginDisconnected(NotificationMenuRowPlugin plugin) { |
| 1026 | boolean existed = mMenuRow.getMenuView() != null; |
| 1027 | mMenuRow = new NotificationMenuRow(mContext); // Back to default |
| 1028 | if (existed) { |
| 1029 | createMenu(); |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | public NotificationMenuRowPlugin createMenu() { |
| 1034 | if (mMenuRow.getMenuView() == null) { |
Mady Mellor | 4ab2820 | 2017-06-06 11:42:50 -0700 | [diff] [blame] | 1035 | mMenuRow.createMenu(this, mStatusBarNotification); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1036 | mMenuRow.setAppName(mAppName); |
| 1037 | FrameLayout.LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, |
| 1038 | LayoutParams.MATCH_PARENT); |
| 1039 | addView(mMenuRow.getMenuView(), MENU_VIEW_INDEX, lp); |
| 1040 | } |
| 1041 | return mMenuRow; |
| 1042 | } |
| 1043 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1044 | public NotificationMenuRowPlugin getProvider() { |
| 1045 | return mMenuRow; |
| 1046 | } |
| 1047 | |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 1048 | @Override |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1049 | public void onDensityOrFontScaleChanged() { |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 1050 | super.onDensityOrFontScaleChanged(); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1051 | initDimens(); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 1052 | initBackground(); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 1053 | // Let's update our childrencontainer. This is intentionally not guarded with |
| 1054 | // mIsSummaryWithChildren since we might have had children but not anymore. |
| 1055 | if (mChildrenContainer != null) { |
| 1056 | mChildrenContainer.reInflateViews(mExpandClickListener, mEntry.notification); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1057 | } |
| 1058 | if (mGuts != null) { |
| 1059 | View oldGuts = mGuts; |
| 1060 | int index = indexOfChild(oldGuts); |
| 1061 | removeView(oldGuts); |
| 1062 | mGuts = (NotificationGuts) LayoutInflater.from(mContext).inflate( |
| 1063 | R.layout.notification_guts, this, false); |
| 1064 | mGuts.setVisibility(oldGuts.getVisibility()); |
| 1065 | addView(mGuts, index); |
| 1066 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1067 | View oldMenu = mMenuRow.getMenuView(); |
| 1068 | if (oldMenu != null) { |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1069 | int menuIndex = indexOfChild(oldMenu); |
| 1070 | removeView(oldMenu); |
Mady Mellor | 4ab2820 | 2017-06-06 11:42:50 -0700 | [diff] [blame] | 1071 | mMenuRow.createMenu(ExpandableNotificationRow.this, mStatusBarNotification); |
Mady Mellor | 761cde1 | 2017-01-10 11:36:39 -0800 | [diff] [blame] | 1072 | mMenuRow.setAppName(mAppName); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1073 | addView(mMenuRow.getMenuView(), menuIndex); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1074 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1075 | for (NotificationContentView l : mLayouts) { |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 1076 | l.initView(); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1077 | l.reInflateViews(); |
| 1078 | } |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1079 | mNotificationInflater.onDensityOrFontScaleChanged(); |
| 1080 | onNotificationUpdated(); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
Mady Mellor | 9d03a52 | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 1083 | @Override |
| 1084 | public void onConfigurationChanged(Configuration newConfig) { |
| 1085 | if (mMenuRow.getMenuView() != null) { |
| 1086 | mMenuRow.onConfigurationChanged(); |
| 1087 | } |
| 1088 | } |
| 1089 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1090 | public void setContentBackground(int customBackgroundColor, boolean animate, |
| 1091 | NotificationContentView notificationContentView) { |
| 1092 | if (getShowingLayout() == notificationContentView) { |
| 1093 | setTintColor(customBackgroundColor, animate); |
| 1094 | } |
| 1095 | } |
| 1096 | |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 1097 | @Override |
| 1098 | protected void setBackgroundTintColor(int color) { |
| 1099 | super.setBackgroundTintColor(color); |
| 1100 | NotificationContentView view = getShowingLayout(); |
| 1101 | if (view != null) { |
| 1102 | view.setBackgroundTintColor(color); |
| 1103 | } |
| 1104 | } |
| 1105 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1106 | public void closeRemoteInput() { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1107 | for (NotificationContentView l : mLayouts) { |
| 1108 | l.closeRemoteInput(); |
| 1109 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1112 | /** |
| 1113 | * Set by how much the single line view should be indented. |
| 1114 | */ |
| 1115 | public void setSingleLineWidthIndention(int indention) { |
| 1116 | mPrivateLayout.setSingleLineWidthIndention(indention); |
| 1117 | } |
| 1118 | |
| 1119 | public int getNotificationColor() { |
Selim Cinek | 4bb5934 | 2016-04-08 19:29:35 -0700 | [diff] [blame] | 1120 | return mNotificationColor; |
| 1121 | } |
| 1122 | |
| 1123 | private void updateNotificationColor() { |
| 1124 | mNotificationColor = NotificationColorUtil.resolveContrastColor(mContext, |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 1125 | getStatusBarNotification().getNotification().color, |
| 1126 | getBackgroundColorWithoutTint()); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1127 | mNotificationColorAmbient = NotificationColorUtil.resolveAmbientColor(mContext, |
| 1128 | getStatusBarNotification().getNotification().color); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
| 1131 | public HybridNotificationView getSingleLineView() { |
| 1132 | return mPrivateLayout.getSingleLineView(); |
| 1133 | } |
| 1134 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1135 | public HybridNotificationView getAmbientSingleLineView() { |
| 1136 | return getShowingLayout().getAmbientSingleLineChild(); |
| 1137 | } |
| 1138 | |
Selim Cinek | f07d062 | 2016-03-21 19:52:52 -0700 | [diff] [blame] | 1139 | public boolean isOnKeyguard() { |
| 1140 | return mOnKeyguard; |
| 1141 | } |
| 1142 | |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 1143 | public void removeAllChildren() { |
| 1144 | List<ExpandableNotificationRow> notificationChildren |
| 1145 | = mChildrenContainer.getNotificationChildren(); |
| 1146 | ArrayList<ExpandableNotificationRow> clonedList = new ArrayList<>(notificationChildren); |
| 1147 | for (int i = 0; i < clonedList.size(); i++) { |
| 1148 | ExpandableNotificationRow row = clonedList.get(i); |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 1149 | if (row.keepInParent()) { |
| 1150 | continue; |
| 1151 | } |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 1152 | mChildrenContainer.removeNotification(row); |
Selim Cinek | c1e389d | 2016-04-07 11:02:57 -0700 | [diff] [blame] | 1153 | row.setIsChildInGroup(false, null); |
| 1154 | } |
| 1155 | onChildrenCountChanged(); |
| 1156 | } |
| 1157 | |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 1158 | public void setForceUnlocked(boolean forceUnlocked) { |
| 1159 | mForceUnlocked = forceUnlocked; |
| 1160 | if (mIsSummaryWithChildren) { |
| 1161 | List<ExpandableNotificationRow> notificationChildren = getNotificationChildren(); |
| 1162 | for (ExpandableNotificationRow child : notificationChildren) { |
| 1163 | child.setForceUnlocked(forceUnlocked); |
| 1164 | } |
| 1165 | } |
| 1166 | } |
| 1167 | |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 1168 | public void setDismissed(boolean fromAccessibility) { |
Rohan Shah | c6990a0 | 2018-03-23 17:24:17 -0700 | [diff] [blame] | 1169 | setLongPressListener(null); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 1170 | mDismissed = true; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1171 | mGroupParentWhenDismissed = mNotificationParent; |
| 1172 | mRefocusOnDismiss = fromAccessibility; |
| 1173 | mChildAfterViewWhenDismissed = null; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 1174 | mEntry.icon.setDismissed(); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1175 | if (isChildInGroup()) { |
| 1176 | List<ExpandableNotificationRow> notificationChildren = |
| 1177 | mNotificationParent.getNotificationChildren(); |
| 1178 | int i = notificationChildren.indexOf(this); |
| 1179 | if (i != -1 && i < notificationChildren.size() - 1) { |
| 1180 | mChildAfterViewWhenDismissed = notificationChildren.get(i + 1); |
| 1181 | } |
| 1182 | } |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | public boolean isDismissed() { |
| 1186 | return mDismissed; |
| 1187 | } |
| 1188 | |
| 1189 | public boolean keepInParent() { |
| 1190 | return mKeepInParent; |
| 1191 | } |
| 1192 | |
| 1193 | public void setKeepInParent(boolean keepInParent) { |
| 1194 | mKeepInParent = keepInParent; |
| 1195 | } |
| 1196 | |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 1197 | @Override |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 1198 | public boolean isRemoved() { |
| 1199 | return mRemoved; |
| 1200 | } |
| 1201 | |
Adrian Roos | d009ab1 | 2016-05-20 17:58:53 -0700 | [diff] [blame] | 1202 | public void setRemoved() { |
| 1203 | mRemoved = true; |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 1204 | mTranslationWhenRemoved = getTranslationY(); |
| 1205 | mWasChildInGroupWhenRemoved = isChildInGroup(); |
| 1206 | if (isChildInGroup()) { |
| 1207 | mTranslationWhenRemoved += getNotificationParent().getTranslationY(); |
| 1208 | } |
Adrian Roos | d009ab1 | 2016-05-20 17:58:53 -0700 | [diff] [blame] | 1209 | mPrivateLayout.setRemoved(); |
Selim Cinek | 3f19f60 | 2016-05-02 18:01:56 -0700 | [diff] [blame] | 1210 | } |
| 1211 | |
Selim Cinek | ef8c225 | 2017-02-10 14:52:18 -0800 | [diff] [blame] | 1212 | public boolean wasChildInGroupWhenRemoved() { |
| 1213 | return mWasChildInGroupWhenRemoved; |
| 1214 | } |
| 1215 | |
| 1216 | public float getTranslationWhenRemoved() { |
| 1217 | return mTranslationWhenRemoved; |
| 1218 | } |
| 1219 | |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 1220 | public NotificationChildrenContainer getChildrenContainer() { |
| 1221 | return mChildrenContainer; |
| 1222 | } |
| 1223 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1224 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 1225 | boolean wasAboveShelf = isAboveShelf(); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 1226 | boolean changed = headsUpAnimatingAway != mHeadsupDisappearRunning; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1227 | mHeadsupDisappearRunning = headsUpAnimatingAway; |
| 1228 | mPrivateLayout.setHeadsUpAnimatingAway(headsUpAnimatingAway); |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 1229 | if (changed && mHeadsUpAnimatingAwayListener != null) { |
| 1230 | mHeadsUpAnimatingAwayListener.accept(headsUpAnimatingAway); |
| 1231 | } |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 1232 | if (isAboveShelf() != wasAboveShelf) { |
| 1233 | mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf); |
| 1234 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
Selim Cinek | 8875de1 | 2018-03-22 10:14:32 -0700 | [diff] [blame] | 1237 | public void setHeadsUpAnimatingAwayListener(Consumer<Boolean> listener) { |
| 1238 | mHeadsUpAnimatingAwayListener = listener; |
| 1239 | } |
| 1240 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1241 | /** |
| 1242 | * @return if the view was just heads upped and is now animating away. During such a time the |
| 1243 | * layout needs to be kept consistent |
| 1244 | */ |
Selim Cinek | 29aab96 | 2018-02-27 17:05:45 -0800 | [diff] [blame] | 1245 | @Override |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1246 | public boolean isHeadsUpAnimatingAway() { |
| 1247 | return mHeadsupDisappearRunning; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 1248 | } |
| 1249 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1250 | public View getChildAfterViewWhenDismissed() { |
| 1251 | return mChildAfterViewWhenDismissed; |
| 1252 | } |
| 1253 | |
| 1254 | public View getGroupParentWhenDismissed() { |
| 1255 | return mGroupParentWhenDismissed; |
| 1256 | } |
| 1257 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1258 | /** |
| 1259 | * Dismisses the notification with the option of showing the blocking helper in-place if we have |
| 1260 | * a negative user sentiment. |
| 1261 | * |
| 1262 | * @param fromAccessibility whether this dismiss is coming from an accessibility action |
| 1263 | * @return whether a blocking helper is shown in this row |
| 1264 | */ |
| 1265 | public boolean performDismissWithBlockingHelper(boolean fromAccessibility) { |
| 1266 | NotificationBlockingHelperManager manager = |
| 1267 | Dependency.get(NotificationBlockingHelperManager.class); |
| 1268 | boolean isBlockingHelperShown = manager.perhapsShowBlockingHelper(this, mMenuRow); |
| 1269 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 1270 | Dependency.get(MetricsLogger.class).count(NotificationCounters.NOTIFICATION_DISMISSED, 1); |
| 1271 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1272 | // Continue with dismiss since we don't want the blocking helper to be directly associated |
| 1273 | // with a certain notification. |
| 1274 | performDismiss(fromAccessibility); |
| 1275 | return isBlockingHelperShown; |
| 1276 | } |
| 1277 | |
yoshiki iguchi | 85ccbbc | 2018-01-22 12:33:21 +0900 | [diff] [blame] | 1278 | public void performDismiss(boolean fromAccessibility) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1279 | if (isOnlyChildInGroup()) { |
yoshiki iguchi | 85ccbbc | 2018-01-22 12:33:21 +0900 | [diff] [blame] | 1280 | ExpandableNotificationRow groupSummary = |
| 1281 | mGroupManager.getLogicalGroupSummary(getStatusBarNotification()); |
| 1282 | if (groupSummary.isClearable()) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1283 | // If this is the only child in the group, dismiss the group, but don't try to show |
| 1284 | // the blocking helper affordance! |
yoshiki iguchi | 85ccbbc | 2018-01-22 12:33:21 +0900 | [diff] [blame] | 1285 | groupSummary.performDismiss(fromAccessibility); |
| 1286 | } |
| 1287 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 1288 | setDismissed(fromAccessibility); |
yoshiki iguchi | 85ccbbc | 2018-01-22 12:33:21 +0900 | [diff] [blame] | 1289 | if (isClearable()) { |
| 1290 | if (mOnDismissRunnable != null) { |
| 1291 | mOnDismissRunnable.run(); |
| 1292 | } |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 1293 | } |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 1296 | public void setBlockingHelperShowing(boolean isBlockingHelperShowing) { |
| 1297 | mIsBlockingHelperShowing = isBlockingHelperShowing; |
| 1298 | } |
| 1299 | |
| 1300 | public boolean isBlockingHelperShowing() { |
| 1301 | return mIsBlockingHelperShowing; |
| 1302 | } |
| 1303 | |
Selim Cinek | e907911 | 2016-12-14 14:41:01 -0800 | [diff] [blame] | 1304 | public void setOnDismissRunnable(Runnable onDismissRunnable) { |
| 1305 | mOnDismissRunnable = onDismissRunnable; |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1308 | public View getNotificationIcon() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1309 | NotificationHeaderView notificationHeader = getVisibleNotificationHeader(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1310 | if (notificationHeader != null) { |
| 1311 | return notificationHeader.getIcon(); |
| 1312 | } |
| 1313 | return null; |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * @return whether the notification is currently showing a view with an icon. |
| 1318 | */ |
| 1319 | public boolean isShowingIcon() { |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 1320 | if (areGutsExposed()) { |
| 1321 | return false; |
| 1322 | } |
Selim Cinek | 2ffa02f | 2017-03-06 15:56:37 -0800 | [diff] [blame] | 1323 | return getVisibleNotificationHeader() != null; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1326 | /** |
| 1327 | * Set how much this notification is transformed into an icon. |
| 1328 | * |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1329 | * @param contentTransformationAmount A value from 0 to 1 indicating how much we are transformed |
| 1330 | * to the content away |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1331 | * @param isLastChild is this the last child in the list. If true, then the transformation is |
| 1332 | * different since it's content fades out. |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1333 | */ |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1334 | public void setContentTransformationAmount(float contentTransformationAmount, |
| 1335 | boolean isLastChild) { |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1336 | boolean changeTransformation = isLastChild != mIsLastChild; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1337 | changeTransformation |= mContentTransformationAmount != contentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1338 | mIsLastChild = isLastChild; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1339 | mContentTransformationAmount = contentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1340 | if (changeTransformation) { |
| 1341 | updateContentTransformation(); |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1342 | } |
| 1343 | } |
| 1344 | |
| 1345 | /** |
| 1346 | * Set the icons to be visible of this notification. |
| 1347 | */ |
| 1348 | public void setIconsVisible(boolean iconsVisible) { |
| 1349 | if (iconsVisible != mIconsVisible) { |
| 1350 | mIconsVisible = iconsVisible; |
| 1351 | updateIconVisibilities(); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1352 | } |
| 1353 | } |
| 1354 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1355 | @Override |
| 1356 | protected void onBelowSpeedBumpChanged() { |
| 1357 | updateIconVisibilities(); |
| 1358 | } |
| 1359 | |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1360 | private void updateContentTransformation() { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1361 | if (mExpandAnimationRunning) { |
| 1362 | return; |
| 1363 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1364 | float contentAlpha; |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1365 | float translationY = -mContentTransformationAmount * mIconTransformContentShift; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1366 | if (mIsLastChild) { |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 1367 | contentAlpha = 1.0f - mContentTransformationAmount; |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1368 | contentAlpha = Math.min(contentAlpha / 0.5f, 1.0f); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1369 | contentAlpha = Interpolators.ALPHA_OUT.getInterpolation(contentAlpha); |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1370 | translationY *= 0.4f; |
| 1371 | } else { |
| 1372 | contentAlpha = 1.0f; |
| 1373 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1374 | for (NotificationContentView l : mLayouts) { |
| 1375 | l.setAlpha(contentAlpha); |
| 1376 | l.setTranslationY(translationY); |
| 1377 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1378 | if (mChildrenContainer != null) { |
| 1379 | mChildrenContainer.setAlpha(contentAlpha); |
| 1380 | mChildrenContainer.setTranslationY(translationY); |
| 1381 | // TODO: handle children fade out better |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | private void updateIconVisibilities() { |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 1386 | boolean visible = isChildInGroup() |
| 1387 | || (isBelowSpeedBump() && !NotificationShelf.SHOW_AMBIENT_ICONS) |
| 1388 | || mIconsVisible; |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1389 | for (NotificationContentView l : mLayouts) { |
| 1390 | l.setIconsVisible(visible); |
| 1391 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 1392 | if (mChildrenContainer != null) { |
| 1393 | mChildrenContainer.setIconsVisible(visible); |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1394 | } |
| 1395 | } |
| 1396 | |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 1397 | /** |
| 1398 | * Get the relative top padding of a view relative to this view. This recursively walks up the |
| 1399 | * hierarchy and does the corresponding measuring. |
| 1400 | * |
| 1401 | * @param view the view to the the padding for. The requested view has to be a child of this |
| 1402 | * notification. |
| 1403 | * @return the toppadding |
| 1404 | */ |
| 1405 | public int getRelativeTopPadding(View view) { |
| 1406 | int topPadding = 0; |
| 1407 | while (view.getParent() instanceof ViewGroup) { |
| 1408 | topPadding += view.getTop(); |
| 1409 | view = (View) view.getParent(); |
| 1410 | if (view instanceof ExpandableNotificationRow) { |
| 1411 | return topPadding; |
| 1412 | } |
| 1413 | } |
| 1414 | return topPadding; |
| 1415 | } |
| 1416 | |
Selim Cinek | a1d9790 | 2016-12-14 16:31:40 -0800 | [diff] [blame] | 1417 | public float getContentTranslation() { |
| 1418 | return mPrivateLayout.getTranslationY(); |
| 1419 | } |
| 1420 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1421 | public void setIsLowPriority(boolean isLowPriority) { |
| 1422 | mIsLowPriority = isLowPriority; |
| 1423 | mPrivateLayout.setIsLowPriority(isLowPriority); |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1424 | mNotificationInflater.setIsLowPriority(mIsLowPriority); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1425 | if (mChildrenContainer != null) { |
| 1426 | mChildrenContainer.setIsLowPriority(isLowPriority); |
| 1427 | } |
| 1428 | } |
| 1429 | |
Selim Cinek | 55a3e73 | 2017-05-25 18:30:10 -0700 | [diff] [blame] | 1430 | |
| 1431 | public void setLowPriorityStateUpdated(boolean lowPriorityStateUpdated) { |
| 1432 | mLowPriorityStateUpdated = lowPriorityStateUpdated; |
| 1433 | } |
| 1434 | |
| 1435 | public boolean hasLowPriorityStateUpdated() { |
| 1436 | return mLowPriorityStateUpdated; |
| 1437 | } |
| 1438 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1439 | public boolean isLowPriority() { |
| 1440 | return mIsLowPriority; |
| 1441 | } |
| 1442 | |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 1443 | public void setUseIncreasedCollapsedHeight(boolean use) { |
| 1444 | mUseIncreasedCollapsedHeight = use; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1445 | mNotificationInflater.setUsesIncreasedHeight(use); |
Selim Cinek | 7d1009b | 2017-01-25 15:28:28 -0800 | [diff] [blame] | 1446 | } |
| 1447 | |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 1448 | public void setUseIncreasedHeadsUpHeight(boolean use) { |
| 1449 | mUseIncreasedHeadsUpHeight = use; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1450 | mNotificationInflater.setUsesIncreasedHeadsUpHeight(use); |
| 1451 | } |
| 1452 | |
| 1453 | public void setRemoteViewClickHandler(RemoteViews.OnClickHandler remoteViewClickHandler) { |
| 1454 | mNotificationInflater.setRemoteViewClickHandler(remoteViewClickHandler); |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 1455 | } |
| 1456 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 1457 | public void setInflationCallback(InflationCallback callback) { |
| 1458 | mNotificationInflater.setInflationCallback(callback); |
Selim Cinek | c478f90 | 2017-02-22 20:55:44 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 1461 | public void setNeedsRedaction(boolean needsRedaction) { |
| 1462 | mNotificationInflater.setRedactAmbient(needsRedaction); |
| 1463 | } |
| 1464 | |
Selim Cinek | 5ba2254 | 2017-04-20 15:16:10 -0700 | [diff] [blame] | 1465 | @VisibleForTesting |
| 1466 | public NotificationInflater getNotificationInflater() { |
| 1467 | return mNotificationInflater; |
| 1468 | } |
| 1469 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1470 | public int getNotificationColorAmbient() { |
| 1471 | return mNotificationColorAmbient; |
| 1472 | } |
| 1473 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1474 | public interface ExpansionLogger { |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 1475 | void logNotificationExpansion(String key, boolean userAction, boolean expanded); |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 1476 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1477 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1478 | public ExpandableNotificationRow(Context context, AttributeSet attrs) { |
| 1479 | super(context, attrs); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 1480 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1481 | mNotificationInflater = new NotificationInflater(this); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1482 | mMenuRow = new NotificationMenuRow(mContext); |
Selim Cinek | 01af334 | 2016-02-09 19:25:31 -0800 | [diff] [blame] | 1483 | initDimens(); |
| 1484 | } |
| 1485 | |
| 1486 | private void initDimens() { |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 1487 | mNotificationMinHeightLegacy = NotificationUtils.getFontScaledHeight(mContext, |
| 1488 | R.dimen.notification_min_height_legacy); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 1489 | mNotificationMinHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext, |
| 1490 | R.dimen.notification_min_height_before_p); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 1491 | mNotificationMinHeight = NotificationUtils.getFontScaledHeight(mContext, |
| 1492 | R.dimen.notification_min_height); |
| 1493 | mNotificationMinHeightLarge = NotificationUtils.getFontScaledHeight(mContext, |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 1494 | R.dimen.notification_min_height_increased); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 1495 | mNotificationMaxHeight = NotificationUtils.getFontScaledHeight(mContext, |
| 1496 | R.dimen.notification_max_height); |
| 1497 | mNotificationAmbientHeight = NotificationUtils.getFontScaledHeight(mContext, |
| 1498 | R.dimen.notification_ambient_height); |
| 1499 | mMaxHeadsUpHeightLegacy = NotificationUtils.getFontScaledHeight(mContext, |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 1500 | R.dimen.notification_max_heads_up_height_legacy); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 1501 | mMaxHeadsUpHeightBeforeP = NotificationUtils.getFontScaledHeight(mContext, |
| 1502 | R.dimen.notification_max_heads_up_height_before_p); |
Selim Cinek | e62255c | 2017-09-28 18:23:23 -0700 | [diff] [blame] | 1503 | mMaxHeadsUpHeight = NotificationUtils.getFontScaledHeight(mContext, |
| 1504 | R.dimen.notification_max_heads_up_height); |
| 1505 | mMaxHeadsUpHeightIncreased = NotificationUtils.getFontScaledHeight(mContext, |
Selim Cinek | 87ed69b | 2017-02-09 15:59:43 -0800 | [diff] [blame] | 1506 | R.dimen.notification_max_heads_up_height_increased); |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 1507 | |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1508 | Resources res = getResources(); |
| 1509 | mIncreasedPaddingBetweenElements = res.getDimensionPixelSize( |
| 1510 | R.dimen.notification_divider_height_increased); |
| 1511 | mIconTransformContentShiftNoIcon = res.getDimensionPixelSize( |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1512 | R.dimen.notification_icon_transform_content_shift); |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 1513 | mEnableNonGroupedNotificationExpand = |
| 1514 | res.getBoolean(R.bool.config_enableNonGroupedNotificationExpand); |
| 1515 | mShowGroupBackgroundWhenExpanded = |
| 1516 | res.getBoolean(R.bool.config_showGroupNotificationBgWhenExpanded); |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 1517 | } |
| 1518 | |
| 1519 | /** |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1520 | * Resets this view so it can be re-used for an updated notification. |
| 1521 | */ |
| 1522 | public void reset() { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 1523 | mShowingPublicInitialized = false; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 1524 | onHeightReset(); |
Selim Cinek | 6e28a67 | 2014-09-05 14:43:28 +0200 | [diff] [blame] | 1525 | requestLayout(); |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 1526 | } |
| 1527 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 1528 | public void showAppOpsIcons(ArraySet<Integer> activeOps) { |
| 1529 | if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() != null) { |
| 1530 | mChildrenContainer.getHeaderView().showAppOpsIcons(activeOps); |
| 1531 | } |
| 1532 | mPrivateLayout.showAppOpsIcons(activeOps); |
| 1533 | mPublicLayout.showAppOpsIcons(activeOps); |
| 1534 | } |
| 1535 | |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 1536 | public View.OnClickListener getAppOpsOnClickListener() { |
| 1537 | return mOnAppOpsClickListener; |
| 1538 | } |
| 1539 | |
| 1540 | protected void setAppOpsOnClickListener(ExpandableNotificationRow.OnAppOpsClickListener l) { |
| 1541 | mOnAppOpsClickListener = v -> { |
| 1542 | createMenu(); |
| 1543 | MenuItem menuItem = getProvider().getAppOpsMenuItem(mContext); |
| 1544 | if (menuItem != null) { |
| 1545 | l.onClick(this, v.getWidth() / 2, v.getHeight() / 2, menuItem); |
| 1546 | } |
| 1547 | }; |
| 1548 | } |
| 1549 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 1550 | @Override |
| 1551 | protected void onFinishInflate() { |
| 1552 | super.onFinishInflate(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1553 | mPublicLayout = (NotificationContentView) findViewById(R.id.expandedPublic); |
| 1554 | mPrivateLayout = (NotificationContentView) findViewById(R.id.expanded); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 1555 | mLayouts = new NotificationContentView[] {mPrivateLayout, mPublicLayout}; |
| 1556 | |
| 1557 | for (NotificationContentView l : mLayouts) { |
| 1558 | l.setExpandClickListener(mExpandClickListener); |
| 1559 | l.setContainingNotification(this); |
| 1560 | } |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1561 | mGutsStub = (ViewStub) findViewById(R.id.notification_guts_stub); |
| 1562 | mGutsStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1563 | @Override |
| 1564 | public void onInflate(ViewStub stub, View inflated) { |
| 1565 | mGuts = (NotificationGuts) inflated; |
| 1566 | mGuts.setClipTopAmount(getClipTopAmount()); |
| 1567 | mGuts.setActualHeight(getActualHeight()); |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1568 | mGutsStub = null; |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 1569 | } |
| 1570 | }); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1571 | mChildrenContainerStub = (ViewStub) findViewById(R.id.child_container_stub); |
| 1572 | mChildrenContainerStub.setOnInflateListener(new ViewStub.OnInflateListener() { |
| 1573 | |
| 1574 | @Override |
| 1575 | public void onInflate(ViewStub stub, View inflated) { |
| 1576 | mChildrenContainer = (NotificationChildrenContainer) inflated; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1577 | mChildrenContainer.setIsLowPriority(mIsLowPriority); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1578 | mChildrenContainer.setContainingNotification(ExpandableNotificationRow.this); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1579 | mChildrenContainer.onNotificationUpdated(); |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1580 | |
| 1581 | if (mShouldTranslateContents) { |
| 1582 | mTranslateableViews.add(mChildrenContainer); |
| 1583 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1584 | } |
| 1585 | }); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1586 | |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1587 | if (mShouldTranslateContents) { |
| 1588 | // Add the views that we translate to reveal the menu |
| 1589 | mTranslateableViews = new ArrayList<>(); |
| 1590 | for (int i = 0; i < getChildCount(); i++) { |
| 1591 | mTranslateableViews.add(getChildAt(i)); |
| 1592 | } |
| 1593 | // Remove views that don't translate |
| 1594 | mTranslateableViews.remove(mChildrenContainerStub); |
| 1595 | mTranslateableViews.remove(mGutsStub); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1596 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1597 | } |
| 1598 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 1599 | private void doLongClickCallback() { |
| 1600 | doLongClickCallback(getWidth() / 2, getHeight() / 2); |
| 1601 | } |
| 1602 | |
| 1603 | public void doLongClickCallback(int x, int y) { |
| 1604 | createMenu(); |
| 1605 | MenuItem menuItem = getProvider().getLongpressMenuItem(mContext); |
Mady Mellor | b3a6aed | 2018-05-11 13:24:07 -0700 | [diff] [blame] | 1606 | doLongClickCallback(x, y, menuItem); |
| 1607 | } |
| 1608 | |
| 1609 | private void doLongClickCallback(int x, int y, MenuItem menuItem) { |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 1610 | if (mLongPressListener != null && menuItem != null) { |
| 1611 | mLongPressListener.onLongPress(this, x, y, menuItem); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | @Override |
| 1616 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 1617 | if (KeyEvent.isConfirmKey(keyCode)) { |
| 1618 | event.startTracking(); |
| 1619 | return true; |
| 1620 | } |
| 1621 | return super.onKeyDown(keyCode, event); |
| 1622 | } |
| 1623 | |
| 1624 | @Override |
| 1625 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 1626 | if (KeyEvent.isConfirmKey(keyCode)) { |
| 1627 | if (!event.isCanceled()) { |
| 1628 | performClick(); |
| 1629 | } |
| 1630 | return true; |
| 1631 | } |
| 1632 | return super.onKeyUp(keyCode, event); |
| 1633 | } |
| 1634 | |
| 1635 | @Override |
| 1636 | public boolean onKeyLongPress(int keyCode, KeyEvent event) { |
| 1637 | if (KeyEvent.isConfirmKey(keyCode)) { |
| 1638 | doLongClickCallback(); |
| 1639 | return true; |
| 1640 | } |
| 1641 | return false; |
| 1642 | } |
| 1643 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1644 | public void resetTranslation() { |
Mady Mellor | 32c638a | 2016-09-14 08:58:25 -0700 | [diff] [blame] | 1645 | if (mTranslateAnim != null) { |
| 1646 | mTranslateAnim.cancel(); |
| 1647 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1648 | |
| 1649 | if (!mShouldTranslateContents) { |
| 1650 | setTranslationX(0); |
| 1651 | } else if (mTranslateableViews != null) { |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1652 | for (int i = 0; i < mTranslateableViews.size(); i++) { |
| 1653 | mTranslateableViews.get(i).setTranslationX(0); |
| 1654 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1655 | invalidateOutline(); |
shawnlin | 4fbeac4 | 2018-04-30 20:32:40 +0800 | [diff] [blame] | 1656 | getEntry().expandedIcon.setScrollX(0); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1657 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1658 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1659 | mMenuRow.resetMenu(); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
Rohan Shah | 56eb091 | 2018-05-10 21:49:04 -0700 | [diff] [blame] | 1662 | void onGutsOpened() { |
| 1663 | resetTranslation(); |
| 1664 | updateContentAccessibilityImportanceForGuts(false /* isEnabled */); |
| 1665 | } |
| 1666 | |
| 1667 | void onGutsClosed() { |
| 1668 | updateContentAccessibilityImportanceForGuts(true /* isEnabled */); |
| 1669 | } |
| 1670 | |
| 1671 | /** |
| 1672 | * Updates whether all the non-guts content inside this row is important for accessibility. |
| 1673 | * |
| 1674 | * @param isEnabled whether the content views should be enabled for accessibility |
| 1675 | */ |
| 1676 | private void updateContentAccessibilityImportanceForGuts(boolean isEnabled) { |
| 1677 | if (mChildrenContainer != null) { |
| 1678 | updateChildAccessibilityImportance(mChildrenContainer, isEnabled); |
| 1679 | } |
| 1680 | if (mLayouts != null) { |
| 1681 | for (View view : mLayouts) { |
| 1682 | updateChildAccessibilityImportance(view, isEnabled); |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | if (isEnabled) { |
| 1687 | this.requestAccessibilityFocus(); |
| 1688 | } |
| 1689 | } |
| 1690 | |
| 1691 | /** |
| 1692 | * Updates whether the given childView is important for accessibility based on |
| 1693 | * {@code isEnabled}. |
| 1694 | */ |
| 1695 | private void updateChildAccessibilityImportance(View childView, boolean isEnabled) { |
| 1696 | childView.setImportantForAccessibility(isEnabled |
| 1697 | ? View.IMPORTANT_FOR_ACCESSIBILITY_AUTO |
| 1698 | : View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS); |
| 1699 | } |
| 1700 | |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 1701 | public CharSequence getActiveRemoteInputText() { |
| 1702 | return mPrivateLayout.getActiveRemoteInputText(); |
| 1703 | } |
| 1704 | |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1705 | public void animateTranslateNotification(final float leftTarget) { |
| 1706 | if (mTranslateAnim != null) { |
| 1707 | mTranslateAnim.cancel(); |
| 1708 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1709 | mTranslateAnim = getTranslateViewAnimator(leftTarget, null /* updateListener */); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1710 | if (mTranslateAnim != null) { |
| 1711 | mTranslateAnim.start(); |
| 1712 | } |
| 1713 | } |
| 1714 | |
| 1715 | @Override |
| 1716 | public void setTranslation(float translationX) { |
| 1717 | if (areGutsExposed()) { |
| 1718 | // Don't translate if guts are showing. |
| 1719 | return; |
| 1720 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1721 | if (!mShouldTranslateContents) { |
| 1722 | setTranslationX(translationX); |
| 1723 | } else if (mTranslateableViews != null) { |
| 1724 | // Translate the group of views |
| 1725 | for (int i = 0; i < mTranslateableViews.size(); i++) { |
| 1726 | if (mTranslateableViews.get(i) != null) { |
| 1727 | mTranslateableViews.get(i).setTranslationX(translationX); |
| 1728 | } |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1729 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1730 | invalidateOutline(); |
Selim Cinek | 143672c | 2018-03-23 20:04:32 -0700 | [diff] [blame] | 1731 | |
| 1732 | // In order to keep the shelf in sync with this swiping, we're simply translating |
| 1733 | // it's icon by the same amount. The translation is already being used for the normal |
| 1734 | // positioning, so we can use the scrollX instead. |
| 1735 | getEntry().expandedIcon.setScrollX((int) -translationX); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1736 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1737 | if (mMenuRow.getMenuView() != null) { |
| 1738 | mMenuRow.onTranslationUpdate(translationX); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1739 | } |
| 1740 | } |
| 1741 | |
| 1742 | @Override |
| 1743 | public float getTranslation() { |
Anthony Chen | e04afcb | 2017-04-21 13:51:32 -0700 | [diff] [blame] | 1744 | if (!mShouldTranslateContents) { |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1745 | return getTranslationX(); |
| 1746 | } |
| 1747 | |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1748 | if (mTranslateableViews != null && mTranslateableViews.size() > 0) { |
| 1749 | // All of the views in the list should have same translation, just use first one. |
| 1750 | return mTranslateableViews.get(0).getTranslationX(); |
| 1751 | } |
Anthony Chen | 7acbb77 | 2017-04-07 16:45:25 -0700 | [diff] [blame] | 1752 | |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1753 | return 0; |
| 1754 | } |
| 1755 | |
| 1756 | public Animator getTranslateViewAnimator(final float leftTarget, |
| 1757 | AnimatorUpdateListener listener) { |
Mady Mellor | 723f1f9 | 2016-03-13 15:54:06 -0700 | [diff] [blame] | 1758 | if (mTranslateAnim != null) { |
| 1759 | mTranslateAnim.cancel(); |
| 1760 | } |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 1761 | if (areGutsExposed()) { |
| 1762 | // No translation if guts are exposed. |
| 1763 | return null; |
| 1764 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1765 | final ObjectAnimator translateAnim = ObjectAnimator.ofFloat(this, TRANSLATE_CONTENT, |
| 1766 | leftTarget); |
| 1767 | if (listener != null) { |
| 1768 | translateAnim.addUpdateListener(listener); |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1769 | } |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1770 | translateAnim.addListener(new AnimatorListenerAdapter() { |
| 1771 | boolean cancelled = false; |
| 1772 | |
| 1773 | @Override |
| 1774 | public void onAnimationCancel(Animator anim) { |
| 1775 | cancelled = true; |
| 1776 | } |
| 1777 | |
| 1778 | @Override |
| 1779 | public void onAnimationEnd(Animator anim) { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 1780 | if (!cancelled && leftTarget == 0) { |
| 1781 | mMenuRow.resetMenu(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1782 | mTranslateAnim = null; |
| 1783 | } |
| 1784 | } |
| 1785 | }); |
| 1786 | mTranslateAnim = translateAnim; |
| 1787 | return translateAnim; |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 1788 | } |
| 1789 | |
Selim Cinek | ab29aeb | 2015-02-20 18:18:32 +0100 | [diff] [blame] | 1790 | public void inflateGuts() { |
| 1791 | if (mGuts == null) { |
| 1792 | mGutsStub.inflate(); |
| 1793 | } |
| 1794 | } |
| 1795 | |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1796 | private void updateChildrenVisibility() { |
Selim Cinek | 7fa385a | 2018-01-24 08:35:28 -0800 | [diff] [blame] | 1797 | boolean hideContentWhileLaunching = mExpandAnimationRunning && mGuts != null |
| 1798 | && mGuts.isExposed(); |
| 1799 | mPrivateLayout.setVisibility(!shouldShowPublic() && !mIsSummaryWithChildren |
| 1800 | && !hideContentWhileLaunching ? VISIBLE : INVISIBLE); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1801 | if (mChildrenContainer != null) { |
Selim Cinek | 7fa385a | 2018-01-24 08:35:28 -0800 | [diff] [blame] | 1802 | mChildrenContainer.setVisibility(!shouldShowPublic() && mIsSummaryWithChildren |
| 1803 | && !hideContentWhileLaunching ? VISIBLE |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1804 | : INVISIBLE); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 1805 | } |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 1806 | // The limits might have changed if the view suddenly became a group or vice versa |
| 1807 | updateLimits(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 1808 | } |
| 1809 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1810 | @Override |
Alan Viverette | a54956a | 2015-01-07 16:05:02 -0800 | [diff] [blame] | 1811 | public boolean onRequestSendAccessibilityEventInternal(View child, AccessibilityEvent event) { |
| 1812 | if (super.onRequestSendAccessibilityEventInternal(child, event)) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 1813 | // Add a record for the entire layout since its content is somehow small. |
| 1814 | // The event comes from a leaf view that is interacted with. |
| 1815 | AccessibilityEvent record = AccessibilityEvent.obtain(); |
| 1816 | onInitializeAccessibilityEvent(record); |
| 1817 | dispatchPopulateAccessibilityEvent(record); |
| 1818 | event.appendRecord(record); |
| 1819 | return true; |
| 1820 | } |
| 1821 | return false; |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1822 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1823 | |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1824 | @Override |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1825 | public void setDark(boolean dark, boolean fade, long delay) { |
| 1826 | super.setDark(dark, fade, delay); |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 1827 | mDark = dark; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 1828 | if (!mIsHeadsUp) { |
| 1829 | // Only fade the showing view of the pulsing notification. |
| 1830 | fade = false; |
| 1831 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1832 | final NotificationContentView showing = getShowingLayout(); |
| 1833 | if (showing != null) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1834 | showing.setDark(dark, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1835 | } |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1836 | if (mIsSummaryWithChildren) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1837 | mChildrenContainer.setDark(dark, fade, delay); |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 1838 | } |
Selim Cinek | a7c6963 | 2017-06-07 15:51:29 -0700 | [diff] [blame] | 1839 | updateShelfIconColor(); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1840 | } |
| 1841 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1842 | public void applyExpandAnimationParams(ExpandAnimationParameters params) { |
| 1843 | if (params == null) { |
| 1844 | return; |
| 1845 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1846 | float zProgress = Interpolators.FAST_OUT_SLOW_IN.getInterpolation( |
| 1847 | params.getProgress(0, 50)); |
| 1848 | float translationZ = MathUtils.lerp(params.getStartTranslationZ(), |
| 1849 | mNotificationLaunchHeight, |
| 1850 | zProgress); |
| 1851 | setTranslationZ(translationZ); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1852 | float extraWidthForClipping = params.getWidth() - getWidth() |
| 1853 | + MathUtils.lerp(0, mOutlineRadius * 2, params.getProgress()); |
| 1854 | setExtraWidthForClipping(extraWidthForClipping); |
| 1855 | int top = params.getTop(); |
| 1856 | float interpolation = Interpolators.FAST_OUT_SLOW_IN.getInterpolation(params.getProgress()); |
| 1857 | int startClipTopAmount = params.getStartClipTopAmount(); |
| 1858 | if (mNotificationParent != null) { |
Selim Cinek | ffd3dc6 | 2018-11-30 18:06:57 -0800 | [diff] [blame] | 1859 | float parentY = mNotificationParent.getTranslationY(); |
| 1860 | top -= parentY; |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1861 | mNotificationParent.setTranslationZ(translationZ); |
| 1862 | int parentStartClipTopAmount = params.getParentStartClipTopAmount(); |
| 1863 | if (startClipTopAmount != 0) { |
| 1864 | int clipTopAmount = (int) MathUtils.lerp(parentStartClipTopAmount, |
| 1865 | parentStartClipTopAmount - startClipTopAmount, |
| 1866 | interpolation); |
| 1867 | mNotificationParent.setClipTopAmount(clipTopAmount); |
| 1868 | } |
| 1869 | mNotificationParent.setExtraWidthForClipping(extraWidthForClipping); |
Selim Cinek | ffd3dc6 | 2018-11-30 18:06:57 -0800 | [diff] [blame] | 1870 | float clipBottom = Math.max(params.getBottom(), |
| 1871 | parentY + mNotificationParent.getActualHeight() |
| 1872 | - mNotificationParent.getClipBottomAmount()); |
| 1873 | float clipTop = Math.min(params.getTop(), parentY); |
| 1874 | int minimumHeightForClipping = (int) (clipBottom - clipTop); |
| 1875 | mNotificationParent.setMinimumHeightForClipping(minimumHeightForClipping); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1876 | } else if (startClipTopAmount != 0) { |
| 1877 | int clipTopAmount = (int) MathUtils.lerp(startClipTopAmount, 0, interpolation); |
| 1878 | setClipTopAmount(clipTopAmount); |
| 1879 | } |
| 1880 | setTranslationY(top); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1881 | setActualHeight(params.getHeight()); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1882 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1883 | mBackgroundNormal.setExpandAnimationParams(params); |
| 1884 | } |
| 1885 | |
| 1886 | public void setExpandAnimationRunning(boolean expandAnimationRunning) { |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1887 | View contentView; |
| 1888 | if (mIsSummaryWithChildren) { |
| 1889 | contentView = mChildrenContainer; |
| 1890 | } else { |
| 1891 | contentView = getShowingLayout(); |
| 1892 | } |
| 1893 | if (mGuts != null && mGuts.isExposed()) { |
| 1894 | contentView = mGuts; |
| 1895 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1896 | if (expandAnimationRunning) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1897 | contentView.animate() |
| 1898 | .alpha(0f) |
| 1899 | .setDuration(ActivityLaunchAnimator.ANIMATION_DURATION_FADE_CONTENT) |
| 1900 | .setInterpolator(Interpolators.ALPHA_OUT); |
| 1901 | setAboveShelf(true); |
| 1902 | mExpandAnimationRunning = true; |
| 1903 | mNotificationViewState.cancelAnimations(this); |
| 1904 | mNotificationLaunchHeight = AmbientState.getNotificationLaunchHeight(getContext()); |
| 1905 | } else { |
| 1906 | mExpandAnimationRunning = false; |
| 1907 | setAboveShelf(isAboveShelf()); |
Selim Cinek | 7fa385a | 2018-01-24 08:35:28 -0800 | [diff] [blame] | 1908 | if (mGuts != null) { |
| 1909 | mGuts.setAlpha(1.0f); |
| 1910 | } |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1911 | if (contentView != null) { |
| 1912 | contentView.setAlpha(1.0f); |
| 1913 | } |
| 1914 | setExtraWidthForClipping(0.0f); |
| 1915 | if (mNotificationParent != null) { |
| 1916 | mNotificationParent.setExtraWidthForClipping(0.0f); |
| 1917 | mNotificationParent.setMinimumHeightForClipping(0); |
| 1918 | } |
| 1919 | } |
| 1920 | if (mNotificationParent != null) { |
| 1921 | mNotificationParent.setChildIsExpanding(mExpandAnimationRunning); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1922 | } |
Selim Cinek | 7fa385a | 2018-01-24 08:35:28 -0800 | [diff] [blame] | 1923 | updateChildrenVisibility(); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1924 | updateClipping(); |
| 1925 | mBackgroundNormal.setExpandAnimationRunning(expandAnimationRunning); |
| 1926 | } |
| 1927 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1928 | private void setChildIsExpanding(boolean isExpanding) { |
| 1929 | mChildIsExpanding = isExpanding; |
Selim Cinek | ffd3dc6 | 2018-11-30 18:06:57 -0800 | [diff] [blame] | 1930 | updateClipping(); |
| 1931 | invalidate(); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | @Override |
| 1935 | public boolean hasExpandingChild() { |
| 1936 | return mChildIsExpanding; |
| 1937 | } |
| 1938 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1939 | @Override |
| 1940 | protected boolean shouldClipToActualHeight() { |
Selim Cinek | ffd3dc6 | 2018-11-30 18:06:57 -0800 | [diff] [blame] | 1941 | return super.shouldClipToActualHeight() && !mExpandAnimationRunning; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | @Override |
| 1945 | public boolean isExpandAnimationRunning() { |
| 1946 | return mExpandAnimationRunning; |
| 1947 | } |
| 1948 | |
Lucas Dupin | cecc7c2 | 2017-09-12 16:02:45 -0700 | [diff] [blame] | 1949 | /** |
| 1950 | * Tap sounds should not be played when we're unlocking. |
| 1951 | * Doing so would cause audio collision and the system would feel unpolished. |
| 1952 | */ |
| 1953 | @Override |
| 1954 | public boolean isSoundEffectsEnabled() { |
| 1955 | final boolean mute = mDark && mSecureStateProvider != null && |
| 1956 | !mSecureStateProvider.getAsBoolean(); |
| 1957 | return !mute && super.isSoundEffectsEnabled(); |
| 1958 | } |
| 1959 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1960 | public boolean isExpandable() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 1961 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1962 | return !mChildrenExpanded; |
| 1963 | } |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 1964 | return mEnableNonGroupedNotificationExpand && mExpandable; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1965 | } |
| 1966 | |
| 1967 | public void setExpandable(boolean expandable) { |
| 1968 | mExpandable = expandable; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1969 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1970 | } |
| 1971 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1972 | @Override |
| 1973 | public void setClipToActualHeight(boolean clipToActualHeight) { |
Selim Cinek | 084c16b | 2016-01-22 17:48:22 -0800 | [diff] [blame] | 1974 | super.setClipToActualHeight(clipToActualHeight || isUserLocked()); |
| 1975 | getShowingLayout().setClipToActualHeight(clipToActualHeight || isUserLocked()); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1976 | } |
| 1977 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1978 | /** |
| 1979 | * @return whether the user has changed the expansion state |
| 1980 | */ |
| 1981 | public boolean hasUserChangedExpansion() { |
| 1982 | return mHasUserChangedExpansion; |
| 1983 | } |
| 1984 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1985 | public boolean isUserExpanded() { |
| 1986 | return mUserExpanded; |
| 1987 | } |
| 1988 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 1989 | /** |
| 1990 | * Set this notification to be expanded by the user |
| 1991 | * |
| 1992 | * @param userExpanded whether the user wants this notification to be expanded |
| 1993 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 1994 | public void setUserExpanded(boolean userExpanded) { |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 1995 | setUserExpanded(userExpanded, false /* allowChildExpansion */); |
| 1996 | } |
| 1997 | |
| 1998 | /** |
| 1999 | * Set this notification to be expanded by the user |
| 2000 | * |
| 2001 | * @param userExpanded whether the user wants this notification to be expanded |
| 2002 | * @param allowChildExpansion whether a call to this method allows expanding children |
| 2003 | */ |
| 2004 | public void setUserExpanded(boolean userExpanded, boolean allowChildExpansion) { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 2005 | mFalsingManager.setNotificationExpanded(); |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2006 | if (mIsSummaryWithChildren && !shouldShowPublic() && allowChildExpansion |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2007 | && !mChildrenContainer.showingAsLowPriority()) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 2008 | final boolean wasExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 2009 | mGroupManager.setGroupExpanded(mStatusBarNotification, userExpanded); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2010 | onExpansionChanged(true /* userAction */, wasExpanded); |
Selim Cinek | 388df6d | 2015-10-22 13:25:11 -0700 | [diff] [blame] | 2011 | return; |
| 2012 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 2013 | if (userExpanded && !mExpandable) return; |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2014 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2015 | mHasUserChangedExpansion = true; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2016 | mUserExpanded = userExpanded; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2017 | onExpansionChanged(true /* userAction */, wasExpanded); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 2018 | if (!wasExpanded && isExpanded() |
| 2019 | && getActualHeight() != getIntrinsicHeight()) { |
| 2020 | notifyHeightChanged(true /* needsAnimation */); |
| 2021 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2022 | } |
| 2023 | |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 2024 | public void resetUserExpansion() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2025 | boolean changed = mUserExpanded; |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 2026 | mHasUserChangedExpansion = false; |
| 2027 | mUserExpanded = false; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2028 | if (changed && mIsSummaryWithChildren) { |
| 2029 | mChildrenContainer.onExpansionChanged(); |
| 2030 | } |
| 2031 | updateShelfIconColor(); |
Selim Cinek | ccd14fb | 2014-08-12 18:53:24 +0200 | [diff] [blame] | 2032 | } |
| 2033 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2034 | public boolean isUserLocked() { |
Selim Cinek | 1b2a05e | 2016-04-28 14:20:39 -0700 | [diff] [blame] | 2035 | return mUserLocked && !mForceUnlocked; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | public void setUserLocked(boolean userLocked) { |
| 2039 | mUserLocked = userLocked; |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 2040 | mPrivateLayout.setUserExpanding(userLocked); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 2041 | // This is intentionally not guarded with mIsSummaryWithChildren since we might have had |
| 2042 | // children but not anymore. |
| 2043 | if (mChildrenContainer != null) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2044 | mChildrenContainer.setUserLocked(userLocked); |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 2045 | if (mIsSummaryWithChildren && (userLocked || !isGroupExpanded())) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2046 | updateBackgroundForGroupState(); |
| 2047 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2048 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2049 | } |
| 2050 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2051 | /** |
| 2052 | * @return has the system set this notification to be expanded |
| 2053 | */ |
| 2054 | public boolean isSystemExpanded() { |
| 2055 | return mIsSystemExpanded; |
| 2056 | } |
| 2057 | |
| 2058 | /** |
| 2059 | * Set this notification to be expanded by the system. |
| 2060 | * |
| 2061 | * @param expand whether the system wants this notification to be expanded. |
| 2062 | */ |
| 2063 | public void setSystemExpanded(boolean expand) { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2064 | if (expand != mIsSystemExpanded) { |
| 2065 | final boolean wasExpanded = isExpanded(); |
| 2066 | mIsSystemExpanded = expand; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2067 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2068 | onExpansionChanged(false /* userAction */, wasExpanded); |
Selim Cinek | ed6913b | 2016-06-01 12:01:17 -0700 | [diff] [blame] | 2069 | if (mIsSummaryWithChildren) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 2070 | mChildrenContainer.updateGroupOverflow(); |
| 2071 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2072 | } |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | /** |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2076 | * @param onKeyguard whether to prevent notification expansion |
Jorim Jaggi | dce3c4c | 2014-04-29 23:12:24 +0200 | [diff] [blame] | 2077 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2078 | public void setOnKeyguard(boolean onKeyguard) { |
| 2079 | if (onKeyguard != mOnKeyguard) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 2080 | boolean wasAboveShelf = isAboveShelf(); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2081 | final boolean wasExpanded = isExpanded(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2082 | mOnKeyguard = onKeyguard; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2083 | onExpansionChanged(false /* userAction */, wasExpanded); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2084 | if (wasExpanded != isExpanded()) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 2085 | if (mIsSummaryWithChildren) { |
| 2086 | mChildrenContainer.updateGroupOverflow(); |
| 2087 | } |
Mady Mellor | 4b80b10 | 2016-01-22 08:03:58 -0800 | [diff] [blame] | 2088 | notifyHeightChanged(false /* needsAnimation */); |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2089 | } |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 2090 | if (isAboveShelf() != wasAboveShelf) { |
| 2091 | mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf); |
| 2092 | } |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 2093 | } |
Selim Cinek | fe24fb7 | 2018-02-13 14:34:55 -0800 | [diff] [blame] | 2094 | updateRippleAllowed(); |
| 2095 | } |
| 2096 | |
| 2097 | private void updateRippleAllowed() { |
| 2098 | boolean allowed = isOnKeyguard() |
| 2099 | || mEntry.notification.getNotification().contentIntent == null; |
| 2100 | setRippleAllowed(allowed); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | /** |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 2104 | * @return Can the underlying notification be cleared? This can be different from whether the |
| 2105 | * notification can be dismissed in case notifications are sensitive on the lockscreen. |
| 2106 | * @see #canViewBeDismissed() |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 2107 | */ |
| 2108 | public boolean isClearable() { |
Selim Cinek | 506deb6 | 2016-07-20 15:43:59 -0700 | [diff] [blame] | 2109 | if (mStatusBarNotification == null || !mStatusBarNotification.isClearable()) { |
| 2110 | return false; |
| 2111 | } |
| 2112 | if (mIsSummaryWithChildren) { |
| 2113 | List<ExpandableNotificationRow> notificationChildren = |
| 2114 | mChildrenContainer.getNotificationChildren(); |
| 2115 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 2116 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 2117 | if (!child.isClearable()) { |
| 2118 | return false; |
| 2119 | } |
| 2120 | } |
| 2121 | } |
| 2122 | return true; |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 2123 | } |
| 2124 | |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 2125 | @Override |
| 2126 | public int getIntrinsicHeight() { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2127 | if (isUserLocked()) { |
| 2128 | return getActualHeight(); |
| 2129 | } |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 2130 | if (mGuts != null && mGuts.isExposed()) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 2131 | return mGuts.getIntrinsicHeight(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 2132 | } else if ((isChildInGroup() && !isGroupExpanded())) { |
| 2133 | return mPrivateLayout.getMinHeight(); |
| 2134 | } else if (mSensitive && mHideSensitiveForIntrinsicHeight) { |
| 2135 | return getMinHeight(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 2136 | } else if (mIsSummaryWithChildren && (!mOnKeyguard || mShowAmbient)) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 2137 | return mChildrenContainer.getIntrinsicHeight(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 2138 | } else if (isHeadsUpAllowed() && (mIsHeadsUp || mHeadsupDisappearRunning)) { |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 2139 | if (isPinned() || mHeadsupDisappearRunning) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 2140 | return getPinnedHeadsUpHeight(true /* atLeastMinHeight */); |
| 2141 | } else if (isExpanded()) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2142 | return Math.max(getMaxExpandHeight(), getHeadsUpHeight()); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2143 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2144 | return Math.max(getCollapsedHeight(), getHeadsUpHeight()); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 2145 | } |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 2146 | } else if (isExpanded()) { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2147 | return getMaxExpandHeight(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 2148 | } else { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2149 | return getCollapsedHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2150 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2151 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2152 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 2153 | private boolean isHeadsUpAllowed() { |
| 2154 | return !mOnKeyguard && !mShowAmbient; |
| 2155 | } |
| 2156 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 2157 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2158 | public boolean isGroupExpanded() { |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 2159 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2160 | } |
| 2161 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 2162 | private void onChildrenCountChanged() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 2163 | mIsSummaryWithChildren = StatusBar.ENABLE_CHILD_NOTIFICATIONS |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2164 | && mChildrenContainer != null && mChildrenContainer.getNotificationChildCount() > 0; |
| 2165 | if (mIsSummaryWithChildren && mChildrenContainer.getHeaderView() == null) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2166 | mChildrenContainer.recreateNotificationHeader(mExpandClickListener |
| 2167 | ); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 2168 | } |
Mady Mellor | 6baed9e | 2016-05-25 16:05:09 -0700 | [diff] [blame] | 2169 | getShowingLayout().updateBackgroundColor(false /* animate */); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 2170 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 2171 | updateChildrenHeaderAppearance(); |
Selim Cinek | da42d65 | 2015-12-04 15:51:16 -0800 | [diff] [blame] | 2172 | updateChildrenVisibility(); |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 2173 | applyChildrenRoundness(); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 2174 | } |
Rohan Shah | 63411fc | 2018-03-28 19:05:52 -0700 | [diff] [blame] | 2175 | /** |
| 2176 | * Returns the number of channels covered by the notification row (including its children if |
| 2177 | * it's a summary notification). |
| 2178 | */ |
| 2179 | public int getNumUniqueChannels() { |
| 2180 | ArraySet<NotificationChannel> channels = new ArraySet<>(); |
| 2181 | |
| 2182 | channels.add(mEntry.channel); |
| 2183 | |
| 2184 | // If this is a summary, then add in the children notification channels for the |
| 2185 | // same user and pkg. |
| 2186 | if (mIsSummaryWithChildren) { |
| 2187 | final List<ExpandableNotificationRow> childrenRows = getNotificationChildren(); |
| 2188 | final int numChildren = childrenRows.size(); |
| 2189 | for (int i = 0; i < numChildren; i++) { |
| 2190 | final ExpandableNotificationRow childRow = childrenRows.get(i); |
| 2191 | final NotificationChannel childChannel = childRow.getEntry().channel; |
| 2192 | final StatusBarNotification childSbn = childRow.getStatusBarNotification(); |
| 2193 | if (childSbn.getUser().equals(mStatusBarNotification.getUser()) && |
| 2194 | childSbn.getPackageName().equals(mStatusBarNotification.getPackageName())) { |
| 2195 | channels.add(childChannel); |
| 2196 | } |
| 2197 | } |
| 2198 | } |
| 2199 | return channels.size(); |
| 2200 | } |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 2201 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2202 | public void updateChildrenHeaderAppearance() { |
Selim Cinek | ed6913b | 2016-06-01 12:01:17 -0700 | [diff] [blame] | 2203 | if (mIsSummaryWithChildren) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2204 | mChildrenContainer.updateChildrenHeaderAppearance(); |
| 2205 | } |
| 2206 | } |
| 2207 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2208 | /** |
| 2209 | * Check whether the view state is currently expanded. This is given by the system in {@link |
| 2210 | * #setSystemExpanded(boolean)} and can be overridden by user expansion or |
| 2211 | * collapsing in {@link #setUserExpanded(boolean)}. Note that the visual appearance of this |
| 2212 | * view can differ from this state, if layout params are modified from outside. |
| 2213 | * |
| 2214 | * @return whether the view state is currently expanded. |
| 2215 | */ |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2216 | public boolean isExpanded() { |
Selim Cinek | e81b82b | 2016-03-04 11:22:28 -0800 | [diff] [blame] | 2217 | return isExpanded(false /* allowOnKeyguard */); |
| 2218 | } |
| 2219 | |
| 2220 | public boolean isExpanded(boolean allowOnKeyguard) { |
| 2221 | return (!mOnKeyguard || allowOnKeyguard) |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2222 | && (!hasUserChangedExpansion() && (isSystemExpanded() || isSystemChildExpanded()) |
| 2223 | || isUserExpanded()); |
| 2224 | } |
| 2225 | |
| 2226 | private boolean isSystemChildExpanded() { |
| 2227 | return mIsSystemChildExpanded; |
| 2228 | } |
| 2229 | |
| 2230 | public void setSystemChildExpanded(boolean expanded) { |
| 2231 | mIsSystemChildExpanded = expanded; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2232 | } |
| 2233 | |
Mady Mellor | 035badd | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 2234 | public void setLayoutListener(LayoutListener listener) { |
| 2235 | mLayoutListener = listener; |
| 2236 | } |
| 2237 | |
| 2238 | public void removeListener() { |
| 2239 | mLayoutListener = null; |
| 2240 | } |
| 2241 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2242 | @Override |
| 2243 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2244 | int intrinsicBefore = getIntrinsicHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2245 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2246 | if (intrinsicBefore != getIntrinsicHeight()) { |
| 2247 | notifyHeightChanged(true /* needsAnimation */); |
| 2248 | } |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 2249 | if (mMenuRow.getMenuView() != null) { |
| 2250 | mMenuRow.onHeightUpdate(); |
Mady Mellor | a6edc87 | 2016-04-26 11:01:03 -0700 | [diff] [blame] | 2251 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 2252 | updateContentShiftHeight(); |
Mady Mellor | 035badd | 2017-04-04 18:45:30 -0700 | [diff] [blame] | 2253 | if (mLayoutListener != null) { |
| 2254 | mLayoutListener.onLayout(); |
| 2255 | } |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /** |
| 2259 | * Updates the content shift height such that the header is completely hidden when coming from |
| 2260 | * the top. |
| 2261 | */ |
| 2262 | private void updateContentShiftHeight() { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2263 | NotificationHeaderView notificationHeader = getVisibleNotificationHeader(); |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 2264 | if (notificationHeader != null) { |
| 2265 | CachingIconView icon = notificationHeader.getIcon(); |
| 2266 | mIconTransformContentShift = getRelativeTopPadding(icon) + icon.getHeight(); |
| 2267 | } else { |
| 2268 | mIconTransformContentShift = mIconTransformContentShiftNoIcon; |
| 2269 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2270 | } |
| 2271 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 2272 | @Override |
| 2273 | public void notifyHeightChanged(boolean needsAnimation) { |
| 2274 | super.notifyHeightChanged(needsAnimation); |
| 2275 | getShowingLayout().requestSelectLayout(needsAnimation || isUserLocked()); |
| 2276 | } |
| 2277 | |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 2278 | public void setSensitive(boolean sensitive, boolean hideSensitive) { |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2279 | mSensitive = sensitive; |
Selim Cinek | 3c76d50 | 2016-02-19 15:16:33 -0800 | [diff] [blame] | 2280 | mSensitiveHiddenInGeneral = hideSensitive; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 2283 | @Override |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2284 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
Selim Cinek | 60122be | 2015-04-15 18:16:50 -0700 | [diff] [blame] | 2285 | mHideSensitiveForIntrinsicHeight = hideSensitive; |
Selim Cinek | a52f6a1 | 2016-02-29 15:35:58 -0800 | [diff] [blame] | 2286 | if (mIsSummaryWithChildren) { |
| 2287 | List<ExpandableNotificationRow> notificationChildren = |
| 2288 | mChildrenContainer.getNotificationChildren(); |
| 2289 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 2290 | ExpandableNotificationRow child = notificationChildren.get(i); |
| 2291 | child.setHideSensitiveForIntrinsicHeight(hideSensitive); |
| 2292 | } |
| 2293 | } |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2294 | } |
| 2295 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 2296 | @Override |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2297 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 2298 | long duration) { |
Selim Cinek | 69594fb | 2018-05-18 12:06:10 -0700 | [diff] [blame] | 2299 | if (getVisibility() == GONE) { |
| 2300 | // If we are GONE, the hideSensitive parameter will not be calculated and always be |
| 2301 | // false, which is incorrect, let's wait until a real call comes in later. |
| 2302 | return; |
| 2303 | } |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2304 | boolean oldShowingPublic = mShowingPublic; |
| 2305 | mShowingPublic = mSensitive && hideSensitive; |
| 2306 | if (mShowingPublicInitialized && mShowingPublic == oldShowingPublic) { |
| 2307 | return; |
| 2308 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2309 | |
| 2310 | // bail out if no public version |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2311 | if (mPublicLayout.getChildCount() == 0) return; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2312 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2313 | if (!animated) { |
| 2314 | mPublicLayout.animate().cancel(); |
| 2315 | mPrivateLayout.animate().cancel(); |
Selim Cinek | a554c70 | 2016-06-17 18:02:12 -0700 | [diff] [blame] | 2316 | if (mChildrenContainer != null) { |
| 2317 | mChildrenContainer.animate().cancel(); |
| 2318 | mChildrenContainer.setAlpha(1f); |
| 2319 | } |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2320 | mPublicLayout.setAlpha(1f); |
| 2321 | mPrivateLayout.setAlpha(1f); |
| 2322 | mPublicLayout.setVisibility(mShowingPublic ? View.VISIBLE : View.INVISIBLE); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 2323 | updateChildrenVisibility(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2324 | } else { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2325 | animateShowingPublic(delay, duration, mShowingPublic); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2326 | } |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 2327 | NotificationContentView showingLayout = getShowingLayout(); |
| 2328 | showingLayout.updateBackgroundColor(animated); |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 2329 | mPrivateLayout.updateExpandButtons(isExpandable()); |
Lucas Dupin | b6ed63b | 2017-05-30 16:17:42 -0700 | [diff] [blame] | 2330 | updateShelfIconColor(); |
Adrian Roos | e5726a2 | 2016-12-19 14:26:51 -0800 | [diff] [blame] | 2331 | showingLayout.setDark(isDark(), false /* animate */, 0 /* delay */); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 2332 | mShowingPublicInitialized = true; |
| 2333 | } |
| 2334 | |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2335 | private void animateShowingPublic(long delay, long duration, boolean showingPublic) { |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2336 | View[] privateViews = mIsSummaryWithChildren |
| 2337 | ? new View[] {mChildrenContainer} |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 2338 | : new View[] {mPrivateLayout}; |
| 2339 | View[] publicViews = new View[] {mPublicLayout}; |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2340 | View[] hiddenChildren = showingPublic ? privateViews : publicViews; |
| 2341 | View[] shownChildren = showingPublic ? publicViews : privateViews; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 2342 | for (final View hiddenView : hiddenChildren) { |
| 2343 | hiddenView.setVisibility(View.VISIBLE); |
| 2344 | hiddenView.animate().cancel(); |
| 2345 | hiddenView.animate() |
| 2346 | .alpha(0f) |
| 2347 | .setStartDelay(delay) |
| 2348 | .setDuration(duration) |
| 2349 | .withEndAction(new Runnable() { |
| 2350 | @Override |
| 2351 | public void run() { |
| 2352 | hiddenView.setVisibility(View.INVISIBLE); |
| 2353 | } |
| 2354 | }); |
| 2355 | } |
| 2356 | for (View showView : shownChildren) { |
| 2357 | showView.setVisibility(View.VISIBLE); |
| 2358 | showView.setAlpha(0f); |
| 2359 | showView.animate().cancel(); |
| 2360 | showView.animate() |
| 2361 | .alpha(1f) |
| 2362 | .setStartDelay(delay) |
| 2363 | .setDuration(duration); |
| 2364 | } |
Dan Sandler | 0d3e62f | 2014-07-14 17:13:50 -0400 | [diff] [blame] | 2365 | } |
| 2366 | |
Mady Mellor | 43c2cd1 | 2016-12-12 21:05:13 -0800 | [diff] [blame] | 2367 | @Override |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2368 | public boolean mustStayOnScreen() { |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 2369 | return mIsHeadsUp && mMustStayOnScreen; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 2370 | } |
| 2371 | |
Selim Cinek | 9e624e7 | 2016-07-20 13:46:49 -0700 | [diff] [blame] | 2372 | /** |
| 2373 | * @return Whether this view is allowed to be dismissed. Only valid for visible notifications as |
| 2374 | * otherwise some state might not be updated. To request about the general clearability |
| 2375 | * see {@link #isClearable()}. |
| 2376 | */ |
| 2377 | public boolean canViewBeDismissed() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2378 | return isClearable() && (!shouldShowPublic() || !mSensitiveHiddenInGeneral); |
| 2379 | } |
| 2380 | |
| 2381 | private boolean shouldShowPublic() { |
| 2382 | return mSensitive && mHideSensitiveForIntrinsicHeight; |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 2383 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 2384 | |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 2385 | public void makeActionsVisibile() { |
| 2386 | setUserExpanded(true, true); |
| 2387 | if (isChildInGroup()) { |
| 2388 | mGroupManager.setGroupExpanded(mStatusBarNotification, true); |
| 2389 | } |
Selim Cinek | bb42b7d | 2016-08-10 13:02:38 -0700 | [diff] [blame] | 2390 | notifyHeightChanged(false /* needsAnimation */); |
Ricky Wai | cd35def | 2016-05-03 11:07:07 +0100 | [diff] [blame] | 2391 | } |
| 2392 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2393 | public void setChildrenExpanded(boolean expanded, boolean animate) { |
| 2394 | mChildrenExpanded = expanded; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2395 | if (mChildrenContainer != null) { |
| 2396 | mChildrenContainer.setChildrenExpanded(expanded); |
| 2397 | } |
Mady Mellor | 1a5d8ea | 2016-06-09 10:42:42 -0700 | [diff] [blame] | 2398 | updateBackgroundForGroupState(); |
Selim Cinek | ddf1b39 | 2016-05-27 16:33:10 -0700 | [diff] [blame] | 2399 | updateClickAndFocus(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2400 | } |
| 2401 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2402 | public static void applyTint(View v, int color) { |
| 2403 | int alpha; |
| 2404 | if (color != 0) { |
| 2405 | alpha = COLORED_DIVIDER_ALPHA; |
| 2406 | } else { |
| 2407 | color = 0xff000000; |
| 2408 | alpha = DEFAULT_DIVIDER_ALPHA; |
| 2409 | } |
| 2410 | if (v.getBackground() instanceof ColorDrawable) { |
| 2411 | ColorDrawable background = (ColorDrawable) v.getBackground(); |
| 2412 | background.mutate(); |
| 2413 | background.setColor(color); |
| 2414 | background.setAlpha(alpha); |
| 2415 | } |
| 2416 | } |
| 2417 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 2418 | public int getMaxExpandHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2419 | return mPrivateLayout.getExpandHeight(); |
| 2420 | } |
| 2421 | |
| 2422 | |
| 2423 | private int getHeadsUpHeight() { |
| 2424 | return mPrivateLayout.getHeadsUpHeight(); |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2425 | } |
Jorim Jaggi | 584a7aa | 2014-04-10 23:26:13 +0200 | [diff] [blame] | 2426 | |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 2427 | public boolean areGutsExposed() { |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 2428 | return (mGuts != null && mGuts.isExposed()); |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 2429 | } |
| 2430 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2431 | @Override |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2432 | public boolean isContentExpandable() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2433 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 2434 | return true; |
| 2435 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 2436 | NotificationContentView showingLayout = getShowingLayout(); |
| 2437 | return showingLayout.isContentExpandable(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | @Override |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 2441 | protected View getContentView() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2442 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | a570318 | 2016-05-11 21:23:16 -0400 | [diff] [blame] | 2443 | return mChildrenContainer; |
| 2444 | } |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 2445 | return getShowingLayout(); |
| 2446 | } |
| 2447 | |
| 2448 | @Override |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 2449 | protected void onAppearAnimationFinished(boolean wasAppearing) { |
| 2450 | super.onAppearAnimationFinished(wasAppearing); |
| 2451 | if (wasAppearing) { |
| 2452 | // During the animation the visible view might have changed, so let's make sure all |
| 2453 | // alphas are reset |
| 2454 | if (mChildrenContainer != null) { |
| 2455 | mChildrenContainer.setAlpha(1.0f); |
| 2456 | mChildrenContainer.setLayerType(LAYER_TYPE_NONE, null); |
| 2457 | } |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2458 | for (NotificationContentView l : mLayouts) { |
| 2459 | l.setAlpha(1.0f); |
| 2460 | l.setLayerType(LAYER_TYPE_NONE, null); |
| 2461 | } |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | @Override |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2466 | public int getExtraBottomPadding() { |
| 2467 | if (mIsSummaryWithChildren && isGroupExpanded()) { |
| 2468 | return mIncreasedPaddingBetweenElements; |
| 2469 | } |
| 2470 | return 0; |
| 2471 | } |
| 2472 | |
| 2473 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 2474 | public void setActualHeight(int height, boolean notifyListeners) { |
Selim Cinek | 4ca6c63 | 2017-02-23 18:03:37 -0800 | [diff] [blame] | 2475 | boolean changed = height != getActualHeight(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2476 | super.setActualHeight(height, notifyListeners); |
Selim Cinek | 4ca6c63 | 2017-02-23 18:03:37 -0800 | [diff] [blame] | 2477 | if (changed && isRemoved()) { |
| 2478 | // TODO: remove this once we found the gfx bug for this. |
| 2479 | // This is a hack since a removed view sometimes would just stay blank. it occured |
| 2480 | // when sending yourself a message and then clicking on it. |
| 2481 | ViewGroup parent = (ViewGroup) getParent(); |
| 2482 | if (parent != null) { |
| 2483 | parent.invalidate(); |
| 2484 | } |
| 2485 | } |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 2486 | if (mGuts != null && mGuts.isExposed()) { |
Mady Mellor | b53bc27 | 2016-02-11 18:28:23 -0800 | [diff] [blame] | 2487 | mGuts.setActualHeight(height); |
| 2488 | return; |
| 2489 | } |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 2490 | int contentHeight = Math.max(getMinHeight(), height); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2491 | for (NotificationContentView l : mLayouts) { |
| 2492 | l.setContentHeight(contentHeight); |
| 2493 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2494 | if (mIsSummaryWithChildren) { |
| 2495 | mChildrenContainer.setActualHeight(height); |
| 2496 | } |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 2497 | if (mGuts != null) { |
| 2498 | mGuts.setActualHeight(height); |
| 2499 | } |
Mady Mellor | 5454097 | 2017-06-07 11:55:36 -0700 | [diff] [blame] | 2500 | if (mMenuRow.getMenuView() != null) { |
| 2501 | mMenuRow.onHeightUpdate(); |
| 2502 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2503 | } |
| 2504 | |
| 2505 | @Override |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 2506 | public int getMaxContentHeight() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2507 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 2508 | return mChildrenContainer.getMaxContentHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2509 | } |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 2510 | NotificationContentView showingLayout = getShowingLayout(); |
| 2511 | return showingLayout.getMaxHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2512 | } |
| 2513 | |
| 2514 | @Override |
Selim Cinek | eb3fc3d | 2017-09-15 13:37:14 -0700 | [diff] [blame] | 2515 | public int getMinHeight(boolean ignoreTemporaryStates) { |
| 2516 | if (!ignoreTemporaryStates && mGuts != null && mGuts.isExposed()) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 2517 | return mGuts.getIntrinsicHeight(); |
Selim Cinek | eb3fc3d | 2017-09-15 13:37:14 -0700 | [diff] [blame] | 2518 | } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp |
| 2519 | && mHeadsUpManager.isTrackingHeadsUp()) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 2520 | return getPinnedHeadsUpHeight(false /* atLeastMinHeight */); |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2521 | } else if (mIsSummaryWithChildren && !isGroupExpanded() && !shouldShowPublic()) { |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2522 | return mChildrenContainer.getMinHeight(); |
Selim Cinek | eb3fc3d | 2017-09-15 13:37:14 -0700 | [diff] [blame] | 2523 | } else if (!ignoreTemporaryStates && isHeadsUpAllowed() && mIsHeadsUp) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 2524 | return getHeadsUpHeight(); |
Selim Cinek | b55386d | 2015-12-16 17:26:49 -0800 | [diff] [blame] | 2525 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2526 | NotificationContentView showingLayout = getShowingLayout(); |
| 2527 | return showingLayout.getMinHeight(); |
| 2528 | } |
| 2529 | |
| 2530 | @Override |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2531 | public int getCollapsedHeight() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2532 | if (mIsSummaryWithChildren && !shouldShowPublic()) { |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 2533 | return mChildrenContainer.getCollapsedHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 2534 | } |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 2535 | return getMinHeight(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 2536 | } |
| 2537 | |
| 2538 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2539 | public void setClipTopAmount(int clipTopAmount) { |
| 2540 | super.setClipTopAmount(clipTopAmount); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2541 | for (NotificationContentView l : mLayouts) { |
| 2542 | l.setClipTopAmount(clipTopAmount); |
| 2543 | } |
Jorim Jaggi | b1cd3c1 | 2014-09-08 19:55:17 +0200 | [diff] [blame] | 2544 | if (mGuts != null) { |
| 2545 | mGuts.setClipTopAmount(clipTopAmount); |
| 2546 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 2547 | } |
| 2548 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 2549 | @Override |
| 2550 | public void setClipBottomAmount(int clipBottomAmount) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2551 | if (mExpandAnimationRunning) { |
| 2552 | return; |
| 2553 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 2554 | if (clipBottomAmount != mClipBottomAmount) { |
| 2555 | super.setClipBottomAmount(clipBottomAmount); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2556 | for (NotificationContentView l : mLayouts) { |
| 2557 | l.setClipBottomAmount(clipBottomAmount); |
| 2558 | } |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 2559 | if (mGuts != null) { |
| 2560 | mGuts.setClipBottomAmount(clipBottomAmount); |
| 2561 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 2562 | } |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 2563 | if (mChildrenContainer != null && !mChildIsExpanding) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 2564 | // We have to update this even if it hasn't changed, since the children locations can |
| 2565 | // have changed |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 2566 | mChildrenContainer.setClipBottomAmount(clipBottomAmount); |
| 2567 | } |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 2568 | } |
| 2569 | |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2570 | public NotificationContentView getShowingLayout() { |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2571 | return shouldShowPublic() ? mPublicLayout : mPrivateLayout; |
Selim Cinek | 2f0df8a | 2014-06-10 17:40:42 +0200 | [diff] [blame] | 2572 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2573 | |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 2574 | public void setLegacy(boolean legacy) { |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2575 | for (NotificationContentView l : mLayouts) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 2576 | l.setLegacy(legacy); |
Adrian Roos | eb434ff | 2017-01-11 11:18:48 -0800 | [diff] [blame] | 2577 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 2580 | @Override |
| 2581 | protected void updateBackgroundTint() { |
| 2582 | super.updateBackgroundTint(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2583 | updateBackgroundForGroupState(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 2584 | if (mIsSummaryWithChildren) { |
| 2585 | List<ExpandableNotificationRow> notificationChildren = |
| 2586 | mChildrenContainer.getNotificationChildren(); |
| 2587 | for (int i = 0; i < notificationChildren.size(); i++) { |
| 2588 | ExpandableNotificationRow child = notificationChildren.get(i); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2589 | child.updateBackgroundForGroupState(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 2590 | } |
| 2591 | } |
| 2592 | } |
| 2593 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2594 | /** |
| 2595 | * Called when a group has finished animating from collapsed or expanded state. |
| 2596 | */ |
| 2597 | public void onFinishedExpansionChange() { |
| 2598 | mGroupExpansionChanging = false; |
| 2599 | updateBackgroundForGroupState(); |
| 2600 | } |
| 2601 | |
| 2602 | /** |
| 2603 | * Updates the parent and children backgrounds in a group based on the expansion state. |
| 2604 | */ |
| 2605 | public void updateBackgroundForGroupState() { |
| 2606 | if (mIsSummaryWithChildren) { |
| 2607 | // Only when the group has finished expanding do we hide its background. |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 2608 | mShowNoBackground = !mShowGroupBackgroundWhenExpanded && isGroupExpanded() |
| 2609 | && !isGroupExpansionChanging() && !isUserLocked(); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2610 | mChildrenContainer.updateHeaderForExpansion(mShowNoBackground); |
| 2611 | List<ExpandableNotificationRow> children = mChildrenContainer.getNotificationChildren(); |
| 2612 | for (int i = 0; i < children.size(); i++) { |
| 2613 | children.get(i).updateBackgroundForGroupState(); |
| 2614 | } |
| 2615 | } else if (isChildInGroup()) { |
| 2616 | final int childColor = getShowingLayout().getBackgroundColorForExpansionState(); |
| 2617 | // 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] | 2618 | // and has a custom background color. |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2619 | final boolean showBackground = isGroupExpanded() |
| 2620 | || ((mNotificationParent.isGroupExpansionChanging() |
Anthony Chen | 6bf88a0 | 2017-04-10 14:41:44 -0700 | [diff] [blame] | 2621 | || mNotificationParent.isUserLocked()) && childColor != 0); |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 2622 | mShowNoBackground = !showBackground; |
| 2623 | } else { |
| 2624 | // Only children or parents ever need no background. |
| 2625 | mShowNoBackground = false; |
| 2626 | } |
| 2627 | updateOutline(); |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 2628 | updateBackground(); |
| 2629 | } |
| 2630 | |
Adrian Roos | 4a57967 | 2016-05-24 16:54:37 -0700 | [diff] [blame] | 2631 | public int getPositionOfChild(ExpandableNotificationRow childRow) { |
| 2632 | if (mIsSummaryWithChildren) { |
| 2633 | return mChildrenContainer.getPositionInLinearLayout(childRow); |
| 2634 | } |
| 2635 | return 0; |
| 2636 | } |
| 2637 | |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2638 | public void setExpansionLogger(ExpansionLogger logger, String key) { |
| 2639 | mLogger = logger; |
| 2640 | mLoggingKey = key; |
| 2641 | } |
| 2642 | |
Chris Wren | 6abeeb9 | 2016-05-26 14:44:38 -0400 | [diff] [blame] | 2643 | public void onExpandedByGesture(boolean userExpanded) { |
| 2644 | int event = MetricsEvent.ACTION_NOTIFICATION_GESTURE_EXPANDER; |
| 2645 | if (mGroupManager.isSummaryOfGroup(getStatusBarNotification())) { |
| 2646 | event = MetricsEvent.ACTION_NOTIFICATION_GROUP_GESTURE_EXPANDER; |
| 2647 | } |
| 2648 | MetricsLogger.action(mContext, event, userExpanded); |
| 2649 | } |
| 2650 | |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 2651 | @Override |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2652 | public float getIncreasedPaddingAmount() { |
| 2653 | if (mIsSummaryWithChildren) { |
| 2654 | if (isGroupExpanded()) { |
| 2655 | return 1.0f; |
| 2656 | } else if (isUserLocked()) { |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2657 | return mChildrenContainer.getIncreasedPaddingAmount(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2658 | } |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 2659 | } else if (isColorized() && (!mIsLowPriority || isExpanded())) { |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2660 | return -1.0f; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 2661 | } |
| 2662 | return 0.0f; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2663 | } |
| 2664 | |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2665 | private boolean isColorized() { |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 2666 | return mIsColorized && mBgTint != NO_COLOR; |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 2667 | } |
| 2668 | |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 2669 | @Override |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 2670 | protected boolean disallowSingleClick(MotionEvent event) { |
dongwan0605.kim | c4ddef4 | 2018-05-06 17:40:23 +0900 | [diff] [blame] | 2671 | if (areGutsExposed()) { |
| 2672 | return false; |
| 2673 | } |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 2674 | float x = event.getX(); |
| 2675 | float y = event.getY(); |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 2676 | NotificationHeaderView header = getVisibleNotificationHeader(); |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 2677 | if (header != null && header.isInTouchRect(x - getTranslation(), y)) { |
| 2678 | return true; |
| 2679 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2680 | if ((!mIsSummaryWithChildren || shouldShowPublic()) |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 2681 | && getShowingLayout().disallowSingleClick(x, y)) { |
| 2682 | return true; |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 2683 | } |
| 2684 | return super.disallowSingleClick(event); |
| 2685 | } |
| 2686 | |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2687 | private void onExpansionChanged(boolean userAction, boolean wasExpanded) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 2688 | boolean nowExpanded = isExpanded(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2689 | if (mIsSummaryWithChildren && (!mIsLowPriority || wasExpanded)) { |
Chris Wren | 698b170 | 2016-05-23 11:16:32 -0400 | [diff] [blame] | 2690 | nowExpanded = mGroupManager.isGroupExpanded(mStatusBarNotification); |
| 2691 | } |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 2692 | if (nowExpanded != wasExpanded) { |
| 2693 | updateShelfIconColor(); |
| 2694 | if (mLogger != null) { |
| 2695 | mLogger.logNotificationExpansion(mLoggingKey, userAction, nowExpanded); |
| 2696 | } |
| 2697 | if (mIsSummaryWithChildren) { |
| 2698 | mChildrenContainer.onExpansionChanged(); |
| 2699 | } |
Chris Wren | 78403d7 | 2014-07-28 10:23:24 +0100 | [diff] [blame] | 2700 | } |
| 2701 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 2702 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2703 | @Override |
| 2704 | public void onInitializeAccessibilityNodeInfoInternal(AccessibilityNodeInfo info) { |
| 2705 | super.onInitializeAccessibilityNodeInfoInternal(info); |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2706 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_LONG_CLICK); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2707 | if (canViewBeDismissed()) { |
| 2708 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_DISMISS); |
| 2709 | } |
Selim Cinek | 0b9cf46 | 2017-12-07 16:31:03 -0800 | [diff] [blame] | 2710 | boolean expandable = shouldShowPublic(); |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 2711 | boolean isExpanded = false; |
| 2712 | if (!expandable) { |
| 2713 | if (mIsSummaryWithChildren) { |
| 2714 | expandable = true; |
| 2715 | if (!mIsLowPriority || isExpanded()) { |
| 2716 | isExpanded = isGroupExpanded(); |
| 2717 | } |
| 2718 | } else { |
| 2719 | expandable = mPrivateLayout.isContentExpandable(); |
| 2720 | isExpanded = isExpanded(); |
| 2721 | } |
| 2722 | } |
| 2723 | if (expandable) { |
| 2724 | if (isExpanded) { |
| 2725 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_COLLAPSE); |
| 2726 | } else { |
| 2727 | info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_EXPAND); |
| 2728 | } |
| 2729 | } |
Mady Mellor | b3a6aed | 2018-05-11 13:24:07 -0700 | [diff] [blame] | 2730 | NotificationMenuRowPlugin provider = getProvider(); |
| 2731 | if (provider != null) { |
| 2732 | MenuItem snoozeMenu = provider.getSnoozeMenuItem(getContext()); |
| 2733 | if (snoozeMenu != null) { |
| 2734 | AccessibilityAction action = new AccessibilityAction(R.id.action_snooze, |
| 2735 | getContext().getResources() |
| 2736 | .getString(R.string.notification_menu_snooze_action)); |
| 2737 | info.addAction(action); |
| 2738 | } |
| 2739 | } |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2740 | } |
| 2741 | |
| 2742 | @Override |
| 2743 | public boolean performAccessibilityActionInternal(int action, Bundle arguments) { |
| 2744 | if (super.performAccessibilityActionInternal(action, arguments)) { |
| 2745 | return true; |
| 2746 | } |
| 2747 | switch (action) { |
| 2748 | case AccessibilityNodeInfo.ACTION_DISMISS: |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 2749 | performDismissWithBlockingHelper(true /* fromAccessibility */); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2750 | return true; |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 2751 | case AccessibilityNodeInfo.ACTION_COLLAPSE: |
| 2752 | case AccessibilityNodeInfo.ACTION_EXPAND: |
| 2753 | mExpandClickListener.onClick(this); |
| 2754 | return true; |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2755 | case AccessibilityNodeInfo.ACTION_LONG_CLICK: |
| 2756 | doLongClickCallback(); |
| 2757 | return true; |
Jason Monk | a9b2fca | 2018-08-09 09:38:21 -0400 | [diff] [blame] | 2758 | default: |
| 2759 | if (action == R.id.action_snooze) { |
| 2760 | NotificationMenuRowPlugin provider = getProvider(); |
| 2761 | if (provider == null) { |
| 2762 | provider = createMenu(); |
| 2763 | } |
| 2764 | MenuItem snoozeMenu = provider.getSnoozeMenuItem(getContext()); |
| 2765 | if (snoozeMenu != null) { |
| 2766 | doLongClickCallback(getWidth() / 2, getHeight() / 2, snoozeMenu); |
| 2767 | } |
| 2768 | return true; |
Mady Mellor | b3a6aed | 2018-05-11 13:24:07 -0700 | [diff] [blame] | 2769 | } |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 2770 | } |
| 2771 | return false; |
| 2772 | } |
| 2773 | |
| 2774 | public boolean shouldRefocusOnDismiss() { |
| 2775 | return mRefocusOnDismiss || isAccessibilityFocused(); |
| 2776 | } |
| 2777 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 2778 | public interface OnExpandClickListener { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 2779 | void onExpandClicked(NotificationData.Entry clickedEntry, boolean nowExpanded); |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 2780 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2781 | |
| 2782 | @Override |
| 2783 | public ExpandableViewState createNewViewState(StackScrollState stackScrollState) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2784 | mNotificationViewState = new NotificationViewState(stackScrollState); |
| 2785 | return mNotificationViewState; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2786 | } |
| 2787 | |
Selim Cinek | f93bf3e | 2018-05-08 14:43:21 -0700 | [diff] [blame] | 2788 | public NotificationViewState getViewState() { |
| 2789 | return mNotificationViewState; |
| 2790 | } |
| 2791 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 2792 | @Override |
| 2793 | public boolean isAboveShelf() { |
Selim Cinek | c8007c5 | 2017-02-28 16:09:56 -0800 | [diff] [blame] | 2794 | return !isOnKeyguard() |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2795 | && (mIsPinned || mHeadsupDisappearRunning || (mIsHeadsUp && mAboveShelf) |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 2796 | || mExpandAnimationRunning || mChildIsExpanding); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 2797 | } |
| 2798 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 2799 | public void setShowAmbient(boolean showAmbient) { |
| 2800 | if (showAmbient != mShowAmbient) { |
| 2801 | mShowAmbient = showAmbient; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 2802 | if (mChildrenContainer != null) { |
| 2803 | mChildrenContainer.notifyShowAmbientChanged(); |
| 2804 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 2805 | notifyHeightChanged(false /* needsAnimation */); |
| 2806 | } |
| 2807 | } |
| 2808 | |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 2809 | @Override |
Tony Huang | c092c43 | 2018-05-18 17:38:54 +0800 | [diff] [blame] | 2810 | public boolean topAmountNeedsClipping() { |
| 2811 | if (isGroupExpanded()) { |
| 2812 | return true; |
| 2813 | } |
| 2814 | if (isGroupExpansionChanging()) { |
| 2815 | return true; |
| 2816 | } |
| 2817 | if (getShowingLayout().shouldClipToRounding(true /* topRounded */, |
| 2818 | false /* bottomRounded */)) { |
| 2819 | return true; |
| 2820 | } |
| 2821 | if (mGuts != null && mGuts.getAlpha() != 0.0f) { |
| 2822 | return true; |
| 2823 | } |
| 2824 | return false; |
| 2825 | } |
| 2826 | |
| 2827 | @Override |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2828 | protected boolean childNeedsClipping(View child) { |
| 2829 | if (child instanceof NotificationContentView) { |
| 2830 | NotificationContentView contentView = (NotificationContentView) child; |
| 2831 | if (isClippingNeeded()) { |
| 2832 | return true; |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 2833 | } else if (!hasNoRounding() |
| 2834 | && contentView.shouldClipToRounding(getCurrentTopRoundness() != 0.0f, |
| 2835 | getCurrentBottomRoundness() != 0.0f)) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2836 | return true; |
| 2837 | } |
| 2838 | } else if (child == mChildrenContainer) { |
Selim Cinek | ffd3dc6 | 2018-11-30 18:06:57 -0800 | [diff] [blame] | 2839 | if (isClippingNeeded() || !hasNoRounding()) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2840 | return true; |
| 2841 | } |
| 2842 | } else if (child instanceof NotificationGuts) { |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 2843 | return !hasNoRounding(); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2844 | } |
| 2845 | return super.childNeedsClipping(child); |
| 2846 | } |
| 2847 | |
| 2848 | @Override |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 2849 | protected void applyRoundness() { |
| 2850 | super.applyRoundness(); |
| 2851 | applyChildrenRoundness(); |
| 2852 | } |
| 2853 | |
| 2854 | private void applyChildrenRoundness() { |
| 2855 | if (mIsSummaryWithChildren) { |
| 2856 | mChildrenContainer.setCurrentBottomRoundness(getCurrentBottomRoundness()); |
| 2857 | } |
| 2858 | } |
| 2859 | |
| 2860 | @Override |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2861 | public Path getCustomClipPath(View child) { |
| 2862 | if (child instanceof NotificationGuts) { |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 2863 | return getClipPath(true, /* ignoreTranslation */ |
| 2864 | false /* clipRoundedToBottom */); |
| 2865 | } |
| 2866 | if (child instanceof NotificationChildrenContainer) { |
| 2867 | return getClipPath(false, /* ignoreTranslation */ |
| 2868 | true /* clipRoundedToBottom */); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 2869 | } |
| 2870 | return super.getCustomClipPath(child); |
| 2871 | } |
| 2872 | |
Selim Cinek | b95fd18 | 2017-12-21 13:03:32 -0800 | [diff] [blame] | 2873 | private boolean hasNoRounding() { |
| 2874 | return getCurrentBottomRoundness() == 0.0f && getCurrentTopRoundness() == 0.0f; |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 2875 | } |
| 2876 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 2877 | public boolean isShowingAmbient() { |
| 2878 | return mShowAmbient; |
| 2879 | } |
| 2880 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 2881 | public void setAboveShelf(boolean aboveShelf) { |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 2882 | boolean wasAboveShelf = isAboveShelf(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 2883 | mAboveShelf = aboveShelf; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 2884 | if (isAboveShelf() != wasAboveShelf) { |
| 2885 | mAboveShelfChangedListener.onAboveShelfStateChanged(!wasAboveShelf); |
| 2886 | } |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Selim Cinek | d4776a5 | 2017-02-14 18:50:16 -0800 | [diff] [blame] | 2889 | public static class NotificationViewState extends ExpandableViewState { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2890 | |
| 2891 | private final StackScrollState mOverallState; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 2892 | |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2893 | |
| 2894 | private NotificationViewState(StackScrollState stackScrollState) { |
| 2895 | mOverallState = stackScrollState; |
| 2896 | } |
| 2897 | |
| 2898 | @Override |
| 2899 | public void applyToView(View view) { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2900 | if (view instanceof ExpandableNotificationRow) { |
| 2901 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2902 | if (row.isExpandAnimationRunning()) { |
| 2903 | return; |
| 2904 | } |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 2905 | handleFixedTranslationZ(row); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2906 | super.applyToView(view); |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2907 | row.applyChildrenState(mOverallState); |
| 2908 | } |
| 2909 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2910 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 2911 | private void handleFixedTranslationZ(ExpandableNotificationRow row) { |
| 2912 | if (row.hasExpandingChild()) { |
| 2913 | zTranslation = row.getTranslationZ(); |
| 2914 | clipTopAmount = row.getClipTopAmount(); |
| 2915 | } |
| 2916 | } |
| 2917 | |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2918 | @Override |
Selim Cinek | 2b549f4 | 2016-11-22 16:38:51 -0800 | [diff] [blame] | 2919 | protected void onYTranslationAnimationFinished(View view) { |
| 2920 | super.onYTranslationAnimationFinished(view); |
Selim Cinek | d4776a5 | 2017-02-14 18:50:16 -0800 | [diff] [blame] | 2921 | if (view instanceof ExpandableNotificationRow) { |
| 2922 | ExpandableNotificationRow row = (ExpandableNotificationRow) view; |
| 2923 | if (row.isHeadsUpAnimatingAway()) { |
| 2924 | row.setHeadsUpAnimatingAway(false); |
| 2925 | } |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2926 | } |
| 2927 | } |
| 2928 | |
| 2929 | @Override |
| 2930 | public void animateTo(View child, AnimationProperties properties) { |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2931 | if (child instanceof ExpandableNotificationRow) { |
| 2932 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2933 | if (row.isExpandAnimationRunning()) { |
| 2934 | return; |
| 2935 | } |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 2936 | handleFixedTranslationZ(row); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 2937 | super.animateTo(child, properties); |
Selim Cinek | 0cfbef4 | 2016-11-09 19:06:36 -0800 | [diff] [blame] | 2938 | row.startChildAnimation(mOverallState, properties); |
| 2939 | } |
| 2940 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 2941 | } |
Selim Cinek | 817abe7 | 2017-05-24 11:08:55 -0700 | [diff] [blame] | 2942 | |
| 2943 | @VisibleForTesting |
| 2944 | protected void setChildrenContainer(NotificationChildrenContainer childrenContainer) { |
| 2945 | mChildrenContainer = childrenContainer; |
| 2946 | } |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2947 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 2948 | @VisibleForTesting |
| 2949 | protected void setPrivateLayout(NotificationContentView privateLayout) { |
| 2950 | mPrivateLayout = privateLayout; |
| 2951 | } |
| 2952 | |
| 2953 | @VisibleForTesting |
| 2954 | protected void setPublicLayout(NotificationContentView publicLayout) { |
| 2955 | mPublicLayout = publicLayout; |
| 2956 | } |
| 2957 | |
Geoffrey Pitsch | 409db27 | 2017-08-28 14:51:52 +0000 | [diff] [blame] | 2958 | /** |
| 2959 | * Equivalent to View.OnLongClickListener with coordinates |
| 2960 | */ |
| 2961 | public interface LongPressListener { |
| 2962 | /** |
| 2963 | * Equivalent to {@link View.OnLongClickListener#onLongClick(View)} with coordinates |
| 2964 | * @return whether the longpress was handled |
| 2965 | */ |
| 2966 | boolean onLongPress(View v, int x, int y, MenuItem item); |
| 2967 | } |
Julia Reynolds | b586745 | 2018-02-28 16:31:35 -0500 | [diff] [blame] | 2968 | |
| 2969 | /** |
| 2970 | * Equivalent to View.OnClickListener with coordinates |
| 2971 | */ |
| 2972 | public interface OnAppOpsClickListener { |
| 2973 | /** |
| 2974 | * Equivalent to {@link View.OnClickListener#onClick(View)} with coordinates |
| 2975 | * @return whether the click was handled |
| 2976 | */ |
| 2977 | boolean onClick(View v, int x, int y, MenuItem item); |
| 2978 | } |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 2979 | |
| 2980 | /** |
| 2981 | * Background task for executing IPCs to check if the notification is a system notification. The |
| 2982 | * output is used for both the blocking helper and the notification info. |
| 2983 | */ |
| 2984 | private class SystemNotificationAsyncTask extends AsyncTask<Void, Void, Boolean> { |
| 2985 | |
| 2986 | @Override |
| 2987 | protected Boolean doInBackground(Void... voids) { |
| 2988 | return isSystemNotification(mContext, mStatusBarNotification); |
| 2989 | } |
| 2990 | |
| 2991 | @Override |
| 2992 | protected void onPostExecute(Boolean result) { |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 2993 | if (mEntry != null) { |
| 2994 | mEntry.mIsSystemNotification = result; |
| 2995 | } |
Rohan Shah | 4ed1b2a | 2018-03-30 13:26:01 -0700 | [diff] [blame] | 2996 | } |
| 2997 | } |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 2998 | } |