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