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