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