Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 18 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 20 | import android.app.Notification; |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 21 | import android.app.PendingIntent; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.graphics.Rect; |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 24 | import android.os.Build; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 25 | import android.service.notification.StatusBarNotification; |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 26 | import android.util.ArrayMap; |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 27 | import android.util.ArraySet; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Selim Cinek | 011bde9 | 2017-11-22 05:53:38 -0800 | [diff] [blame] | 29 | import android.util.Log; |
Selim Cinek | a77d2c5 | 2018-04-09 10:44:52 -0700 | [diff] [blame] | 30 | import android.view.MotionEvent; |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 31 | import android.view.NotificationHeaderView; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 32 | import android.view.View; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 33 | import android.view.ViewGroup; |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 34 | import android.view.ViewTreeObserver; |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 35 | import android.widget.FrameLayout; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 36 | import android.widget.ImageView; |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 37 | import android.widget.LinearLayout; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 38 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 39 | import com.android.internal.annotations.VisibleForTesting; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 40 | import com.android.internal.util.ContrastColorUtil; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 41 | import com.android.systemui.Dependency; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 42 | import com.android.systemui.R; |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 43 | import com.android.systemui.statusbar.MediaTransferManager; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 44 | import com.android.systemui.statusbar.RemoteInputController; |
| 45 | import com.android.systemui.statusbar.SmartReplyController; |
| 46 | import com.android.systemui.statusbar.TransformableView; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 47 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 48 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 49 | import com.android.systemui.statusbar.notification.row.wrapper.NotificationCustomViewWrapper; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 50 | import com.android.systemui.statusbar.notification.row.wrapper.NotificationViewWrapper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 51 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
Gustav Sennton | b944ce5 | 2019-02-25 18:52:43 +0000 | [diff] [blame] | 52 | import com.android.systemui.statusbar.policy.InflatedSmartReplies; |
| 53 | import com.android.systemui.statusbar.policy.InflatedSmartReplies.SmartRepliesAndActions; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 54 | import com.android.systemui.statusbar.policy.RemoteInputView; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 55 | import com.android.systemui.statusbar.policy.SmartReplyConstants; |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 56 | import com.android.systemui.statusbar.policy.SmartReplyView; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 57 | |
Selim Cinek | 85a8f9f | 2018-11-21 13:58:27 -0800 | [diff] [blame] | 58 | import java.io.FileDescriptor; |
| 59 | import java.io.PrintWriter; |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 60 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 61 | /** |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 62 | * A frame layout containing the actual payload of the notification, including the contracted, |
| 63 | * expanded and heads up layout. This class is responsible for clipping the content and and |
| 64 | * switching between the expanded, contracted and the heads up view depending on its clipped size. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 65 | */ |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 66 | public class NotificationContentView extends FrameLayout { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 67 | |
Selim Cinek | 011bde9 | 2017-11-22 05:53:38 -0800 | [diff] [blame] | 68 | private static final String TAG = "NotificationContentView"; |
Gustav Sennton | 2d66b51 | 2019-01-31 17:48:17 +0000 | [diff] [blame] | 69 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 70 | public static final int VISIBLE_TYPE_CONTRACTED = 0; |
| 71 | public static final int VISIBLE_TYPE_EXPANDED = 1; |
| 72 | public static final int VISIBLE_TYPE_HEADSUP = 2; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 73 | private static final int VISIBLE_TYPE_SINGLELINE = 3; |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 74 | public static final int VISIBLE_TYPE_AMBIENT = 4; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 75 | public static final int UNDEFINED = -1; |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 76 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 77 | private final Rect mClipBounds = new Rect(); |
| 78 | |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 79 | private int mMinContractedHeight; |
| 80 | private int mNotificationContentMarginEnd; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 81 | private View mContractedChild; |
| 82 | private View mExpandedChild; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 83 | private View mHeadsUpChild; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 84 | private HybridNotificationView mSingleLineView; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 85 | private View mAmbientChild; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 86 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 87 | private RemoteInputView mExpandedRemoteInput; |
| 88 | private RemoteInputView mHeadsUpRemoteInput; |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 89 | |
| 90 | private SmartReplyConstants mSmartReplyConstants; |
Milo Sredkov | e7cf498 | 2018-04-09 15:08:26 +0100 | [diff] [blame] | 91 | private SmartReplyView mExpandedSmartReplyView; |
Gustav Sennton | d0e8453 | 2018-12-03 16:48:36 +0000 | [diff] [blame] | 92 | private SmartReplyView mHeadsUpSmartReplyView; |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 93 | private SmartReplyController mSmartReplyController; |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 94 | private InflatedSmartReplies mExpandedInflatedSmartReplies; |
| 95 | private InflatedSmartReplies mHeadsUpInflatedSmartReplies; |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 96 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 97 | private NotificationViewWrapper mContractedWrapper; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 98 | private NotificationViewWrapper mExpandedWrapper; |
| 99 | private NotificationViewWrapper mHeadsUpWrapper; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 100 | private NotificationViewWrapper mAmbientWrapper; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 101 | private HybridGroupManager mHybridGroupManager; |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 102 | private int mClipTopAmount; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 103 | private int mContentHeight; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 104 | private int mVisibleType = VISIBLE_TYPE_CONTRACTED; |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 105 | private boolean mDark; |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 106 | private boolean mAnimate; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 107 | private boolean mIsHeadsUp; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 108 | private boolean mLegacy; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 109 | private boolean mIsChildInGroup; |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 110 | private int mSmallHeight; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 111 | private int mHeadsUpHeight; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 112 | private int mNotificationMaxHeight; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 113 | private int mNotificationAmbientHeight; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 114 | private StatusBarNotification mStatusBarNotification; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 115 | private NotificationGroupManager mGroupManager; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 116 | private RemoteInputController mRemoteInputController; |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 117 | private Runnable mExpandedVisibleListener; |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 118 | /** |
| 119 | * List of listeners for when content views become inactive (i.e. not the showing view). |
| 120 | */ |
| 121 | private final ArrayMap<View, Runnable> mOnContentViewInactiveListeners = new ArrayMap<>(); |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 122 | |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 123 | private final ViewTreeObserver.OnPreDrawListener mEnableAnimationPredrawListener |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 124 | = new ViewTreeObserver.OnPreDrawListener() { |
| 125 | @Override |
| 126 | public boolean onPreDraw() { |
Selim Cinek | d1ad9ab | 2016-03-01 17:52:20 -0800 | [diff] [blame] | 127 | // We need to post since we don't want the notification to animate on the very first |
| 128 | // frame |
| 129 | post(new Runnable() { |
| 130 | @Override |
| 131 | public void run() { |
| 132 | mAnimate = true; |
| 133 | } |
| 134 | }); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 135 | getViewTreeObserver().removeOnPreDrawListener(this); |
| 136 | return true; |
| 137 | } |
| 138 | }; |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 139 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 140 | private OnClickListener mExpandClickListener; |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 141 | private boolean mBeforeN; |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 142 | private boolean mExpandable; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 143 | private boolean mClipToActualHeight = true; |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 144 | private ExpandableNotificationRow mContainingNotification; |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 145 | /** The visible type at the start of a touch driven transformation */ |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 146 | private int mTransformationStartVisibleType; |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 147 | /** The visible type at the start of an animation driven transformation */ |
| 148 | private int mAnimationStartVisibleType = UNDEFINED; |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 149 | private boolean mUserExpanding; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 150 | private int mSingleLineWidthIndention; |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 151 | private boolean mForceSelectNextLayout = true; |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 152 | private PendingIntent mPreviousExpandedRemoteInputIntent; |
| 153 | private PendingIntent mPreviousHeadsUpRemoteInputIntent; |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 154 | private RemoteInputView mCachedExpandedRemoteInput; |
| 155 | private RemoteInputView mCachedHeadsUpRemoteInput; |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 156 | |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 157 | private int mContentHeightAtAnimationStart = UNDEFINED; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 158 | private boolean mFocusOnVisibilityChange; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 159 | private boolean mHeadsUpAnimatingAway; |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 160 | private boolean mIconsVisible; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 161 | private int mClipBottomAmount; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 162 | private boolean mIsLowPriority; |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 163 | private boolean mIsContentExpandable; |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 164 | private boolean mRemoteInputVisible; |
| 165 | private int mUnrestrictedContentHeight; |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 166 | private MediaTransferManager mMediaTransferManager; |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 167 | |
| 168 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 169 | public NotificationContentView(Context context, AttributeSet attrs) { |
| 170 | super(context, attrs); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 171 | mHybridGroupManager = new HybridGroupManager(getContext(), this); |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 172 | mMediaTransferManager = new MediaTransferManager(getContext()); |
Petr Cermak | 10011fa | 2018-02-05 19:00:54 +0000 | [diff] [blame] | 173 | mSmartReplyConstants = Dependency.get(SmartReplyConstants.class); |
Kenny Guy | a0f6de8 | 2018-04-06 16:20:16 +0100 | [diff] [blame] | 174 | mSmartReplyController = Dependency.get(SmartReplyController.class); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 175 | initView(); |
| 176 | } |
| 177 | |
| 178 | public void initView() { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 179 | mMinContractedHeight = getResources().getDimensionPixelSize( |
| 180 | R.dimen.min_notification_layout_height); |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 181 | mNotificationContentMarginEnd = getResources().getDimensionPixelSize( |
| 182 | com.android.internal.R.dimen.notification_content_margin_end); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 185 | public void setHeights(int smallHeight, int headsUpMaxHeight, int maxHeight, |
| 186 | int ambientHeight) { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 187 | mSmallHeight = smallHeight; |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 188 | mHeadsUpHeight = headsUpMaxHeight; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 189 | mNotificationMaxHeight = maxHeight; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 190 | mNotificationAmbientHeight = ambientHeight; |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 193 | @Override |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 194 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 195 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 196 | boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY; |
| 197 | boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST; |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 198 | int maxSize = Integer.MAX_VALUE / 2; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 199 | int width = MeasureSpec.getSize(widthMeasureSpec); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 200 | if (hasFixedHeight || isHeightLimited) { |
| 201 | maxSize = MeasureSpec.getSize(heightMeasureSpec); |
| 202 | } |
| 203 | int maxChildHeight = 0; |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 204 | if (mExpandedChild != null) { |
Milo Sredkov | e7cf498 | 2018-04-09 15:08:26 +0100 | [diff] [blame] | 205 | int notificationMaxHeight = mNotificationMaxHeight; |
| 206 | if (mExpandedSmartReplyView != null) { |
| 207 | notificationMaxHeight += mExpandedSmartReplyView.getHeightUpperLimit(); |
| 208 | } |
Selim Cinek | bee4e07 | 2018-05-21 22:06:43 -0700 | [diff] [blame] | 209 | notificationMaxHeight += mExpandedWrapper.getExtraMeasureHeight(); |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 210 | int size = notificationMaxHeight; |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 211 | ViewGroup.LayoutParams layoutParams = mExpandedChild.getLayoutParams(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 212 | boolean useExactly = false; |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 213 | if (layoutParams.height >= 0) { |
| 214 | // An actual height is set |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 215 | size = Math.min(size, layoutParams.height); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 216 | useExactly = true; |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 217 | } |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 218 | int spec = MeasureSpec.makeMeasureSpec(size, useExactly |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 219 | ? MeasureSpec.EXACTLY |
| 220 | : MeasureSpec.AT_MOST); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 221 | measureChildWithMargins(mExpandedChild, widthMeasureSpec, 0, spec, 0); |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 222 | maxChildHeight = Math.max(maxChildHeight, mExpandedChild.getMeasuredHeight()); |
| 223 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 224 | if (mContractedChild != null) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 225 | int heightSpec; |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 226 | int size = mSmallHeight; |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 227 | ViewGroup.LayoutParams layoutParams = mContractedChild.getLayoutParams(); |
| 228 | boolean useExactly = false; |
| 229 | if (layoutParams.height >= 0) { |
| 230 | // An actual height is set |
| 231 | size = Math.min(size, layoutParams.height); |
| 232 | useExactly = true; |
| 233 | } |
| 234 | if (shouldContractedBeFixedSize() || useExactly) { |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 235 | heightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); |
| 236 | } else { |
Selim Cinek | f619ffc | 2016-02-17 14:53:05 -0800 | [diff] [blame] | 237 | heightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 238 | } |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 239 | measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 240 | int measuredHeight = mContractedChild.getMeasuredHeight(); |
| 241 | if (measuredHeight < mMinContractedHeight) { |
| 242 | heightSpec = MeasureSpec.makeMeasureSpec(mMinContractedHeight, MeasureSpec.EXACTLY); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 243 | measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 244 | } |
| 245 | maxChildHeight = Math.max(maxChildHeight, measuredHeight); |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 246 | if (updateContractedHeaderWidth()) { |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 247 | measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 248 | } |
Selim Cinek | 1ba41d1 | 2016-04-21 16:14:46 -0700 | [diff] [blame] | 249 | if (mExpandedChild != null |
| 250 | && mContractedChild.getMeasuredHeight() > mExpandedChild.getMeasuredHeight()) { |
| 251 | // the Expanded child is smaller then the collapsed. Let's remeasure it. |
| 252 | heightSpec = MeasureSpec.makeMeasureSpec(mContractedChild.getMeasuredHeight(), |
| 253 | MeasureSpec.EXACTLY); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 254 | measureChildWithMargins(mExpandedChild, widthMeasureSpec, 0, heightSpec, 0); |
Selim Cinek | 1ba41d1 | 2016-04-21 16:14:46 -0700 | [diff] [blame] | 255 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 256 | } |
| 257 | if (mHeadsUpChild != null) { |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 258 | int maxHeight = mHeadsUpHeight; |
Gustav Sennton | d0e8453 | 2018-12-03 16:48:36 +0000 | [diff] [blame] | 259 | if (mHeadsUpSmartReplyView != null) { |
| 260 | maxHeight += mHeadsUpSmartReplyView.getHeightUpperLimit(); |
| 261 | } |
Selim Cinek | 396caca | 2018-04-10 17:46:46 -0700 | [diff] [blame] | 262 | maxHeight += mHeadsUpWrapper.getExtraMeasureHeight(); |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 263 | int size = maxHeight; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 264 | ViewGroup.LayoutParams layoutParams = mHeadsUpChild.getLayoutParams(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 265 | boolean useExactly = false; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 266 | if (layoutParams.height >= 0) { |
| 267 | // An actual height is set |
Selim Cinek | 77019c7 | 2015-12-09 10:18:02 -0800 | [diff] [blame] | 268 | size = Math.min(size, layoutParams.height); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 269 | useExactly = true; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 270 | } |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 271 | measureChildWithMargins(mHeadsUpChild, widthMeasureSpec, 0, |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 272 | MeasureSpec.makeMeasureSpec(size, useExactly ? MeasureSpec.EXACTLY |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 273 | : MeasureSpec.AT_MOST), 0); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 274 | maxChildHeight = Math.max(maxChildHeight, mHeadsUpChild.getMeasuredHeight()); |
| 275 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 276 | if (mSingleLineView != null) { |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 277 | int singleLineWidthSpec = widthMeasureSpec; |
| 278 | if (mSingleLineWidthIndention != 0 |
| 279 | && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED) { |
| 280 | singleLineWidthSpec = MeasureSpec.makeMeasureSpec( |
| 281 | width - mSingleLineWidthIndention + mSingleLineView.getPaddingEnd(), |
Selim Cinek | 09b7dea | 2016-08-30 11:28:19 -0700 | [diff] [blame] | 282 | MeasureSpec.EXACTLY); |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 283 | } |
| 284 | mSingleLineView.measure(singleLineWidthSpec, |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 285 | MeasureSpec.makeMeasureSpec(mNotificationMaxHeight, MeasureSpec.AT_MOST)); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 286 | maxChildHeight = Math.max(maxChildHeight, mSingleLineView.getMeasuredHeight()); |
| 287 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 288 | if (mAmbientChild != null) { |
Selim Cinek | be570ce | 2018-05-11 12:29:52 -0700 | [diff] [blame] | 289 | int size = mNotificationAmbientHeight; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 290 | ViewGroup.LayoutParams layoutParams = mAmbientChild.getLayoutParams(); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 291 | boolean useExactly = false; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 292 | if (layoutParams.height >= 0) { |
| 293 | // An actual height is set |
| 294 | size = Math.min(size, layoutParams.height); |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 295 | useExactly = true; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 296 | } |
| 297 | mAmbientChild.measure(widthMeasureSpec, |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 298 | MeasureSpec.makeMeasureSpec(size, useExactly ? MeasureSpec.EXACTLY |
| 299 | : MeasureSpec.AT_MOST)); |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 300 | maxChildHeight = Math.max(maxChildHeight, mAmbientChild.getMeasuredHeight()); |
| 301 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 302 | int ownHeight = Math.min(maxChildHeight, maxSize); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 303 | setMeasuredDimension(width, ownHeight); |
| 304 | } |
| 305 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 306 | /** |
| 307 | * Get the extra height that needs to be added to the notification height for a given |
| 308 | * {@link RemoteInputView}. |
| 309 | * This is needed when the user is inline replying in order to ensure that the reply bar has |
| 310 | * enough padding. |
| 311 | * |
| 312 | * @param remoteInput The remote input to check. |
| 313 | * @return The extra height needed. |
| 314 | */ |
| 315 | private int getExtraRemoteInputHeight(RemoteInputView remoteInput) { |
Selim Cinek | 09b442e | 2018-05-04 15:46:18 -0700 | [diff] [blame] | 316 | if (remoteInput != null && (remoteInput.isActive() || remoteInput.isSending())) { |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 317 | return getResources().getDimensionPixelSize( |
| 318 | com.android.internal.R.dimen.notification_content_margin); |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 323 | private boolean updateContractedHeaderWidth() { |
| 324 | // We need to update the expanded and the collapsed header to have exactly the same with to |
| 325 | // have the expand buttons laid out at the same location. |
| 326 | NotificationHeaderView contractedHeader = mContractedWrapper.getNotificationHeader(); |
| 327 | if (contractedHeader != null) { |
| 328 | if (mExpandedChild != null |
| 329 | && mExpandedWrapper.getNotificationHeader() != null) { |
| 330 | NotificationHeaderView expandedHeader = mExpandedWrapper.getNotificationHeader(); |
Beth Thibodeau | 837bfc2 | 2019-02-19 12:26:53 -0500 | [diff] [blame] | 331 | |
| 332 | int headerTextMargin = expandedHeader.getHeaderTextMarginEnd(); |
| 333 | if (headerTextMargin != contractedHeader.getHeaderTextMarginEnd()) { |
| 334 | contractedHeader.setHeaderTextMarginEnd(headerTextMargin); |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 335 | return true; |
| 336 | } |
| 337 | } else { |
| 338 | int paddingEnd = mNotificationContentMarginEnd; |
| 339 | if (contractedHeader.getPaddingEnd() != paddingEnd) { |
| 340 | contractedHeader.setPadding( |
Selim Cinek | cb44568 | 2016-01-29 16:13:12 -0800 | [diff] [blame] | 341 | contractedHeader.isLayoutRtl() |
| 342 | ? paddingEnd |
| 343 | : contractedHeader.getPaddingLeft(), |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 344 | contractedHeader.getPaddingTop(), |
Selim Cinek | cb44568 | 2016-01-29 16:13:12 -0800 | [diff] [blame] | 345 | contractedHeader.isLayoutRtl() |
| 346 | ? contractedHeader.getPaddingLeft() |
| 347 | : paddingEnd, |
Selim Cinek | 6ecc810 | 2016-01-26 18:26:19 -0800 | [diff] [blame] | 348 | contractedHeader.getPaddingBottom()); |
| 349 | contractedHeader.setShowWorkBadgeAtEnd(false); |
| 350 | return true; |
| 351 | } |
| 352 | } |
| 353 | } |
| 354 | return false; |
| 355 | } |
| 356 | |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 357 | private boolean shouldContractedBeFixedSize() { |
| 358 | return mBeforeN && mContractedWrapper instanceof NotificationCustomViewWrapper; |
| 359 | } |
| 360 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 361 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 362 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 363 | int previousHeight = 0; |
| 364 | if (mExpandedChild != null) { |
| 365 | previousHeight = mExpandedChild.getHeight(); |
| 366 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 367 | super.onLayout(changed, left, top, right, bottom); |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 368 | if (previousHeight != 0 && mExpandedChild.getHeight() != previousHeight) { |
| 369 | mContentHeightAtAnimationStart = previousHeight; |
| 370 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 371 | updateClipping(); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 372 | invalidateOutline(); |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 373 | selectLayout(false /* animate */, mForceSelectNextLayout /* force */); |
| 374 | mForceSelectNextLayout = false; |
Selim Cinek | 5f56d85 | 2016-05-24 16:55:13 -0700 | [diff] [blame] | 375 | updateExpandButtons(mExpandable); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 376 | } |
| 377 | |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 378 | @Override |
Selim Cinek | 7b8157e | 2014-11-20 16:00:32 +0100 | [diff] [blame] | 379 | protected void onAttachedToWindow() { |
| 380 | super.onAttachedToWindow(); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 381 | updateVisibility(); |
| 382 | } |
| 383 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 384 | public View getContractedChild() { |
| 385 | return mContractedChild; |
| 386 | } |
| 387 | |
| 388 | public View getExpandedChild() { |
| 389 | return mExpandedChild; |
| 390 | } |
| 391 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 392 | public View getHeadsUpChild() { |
| 393 | return mHeadsUpChild; |
| 394 | } |
| 395 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 396 | public View getAmbientChild() { |
| 397 | return mAmbientChild; |
| 398 | } |
| 399 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 400 | /** |
| 401 | * Sets the contracted view. Child may be null to remove the content view. |
| 402 | * |
| 403 | * @param child contracted content view to set |
| 404 | */ |
| 405 | public void setContractedChild(@Nullable View child) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 406 | if (mContractedChild != null) { |
Jorim Jaggi | 0d9f35d | 2014-08-20 17:06:55 +0200 | [diff] [blame] | 407 | mContractedChild.animate().cancel(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 408 | removeView(mContractedChild); |
| 409 | } |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 410 | if (child == null) { |
| 411 | mContractedChild = null; |
| 412 | mContractedWrapper = null; |
| 413 | if (mTransformationStartVisibleType == VISIBLE_TYPE_CONTRACTED) { |
| 414 | mTransformationStartVisibleType = UNDEFINED; |
| 415 | } |
| 416 | return; |
| 417 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 418 | addView(child); |
| 419 | mContractedChild = child; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 420 | mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child, |
| 421 | mContainingNotification); |
Selim Cinek | 9b49f6d | 2017-11-13 18:19:35 -0800 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | private NotificationViewWrapper getWrapperForView(View child) { |
| 425 | if (child == mContractedChild) { |
| 426 | return mContractedWrapper; |
| 427 | } |
| 428 | if (child == mExpandedChild) { |
| 429 | return mExpandedWrapper; |
| 430 | } |
| 431 | if (child == mHeadsUpChild) { |
| 432 | return mHeadsUpWrapper; |
| 433 | } |
| 434 | if (child == mAmbientChild) { |
| 435 | return mAmbientWrapper; |
| 436 | } |
| 437 | return null; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 438 | } |
| 439 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 440 | /** |
| 441 | * Sets the expanded view. Child may be null to remove the content view. |
| 442 | * |
| 443 | * @param child expanded content view to set |
| 444 | */ |
| 445 | public void setExpandedChild(@Nullable View child) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 446 | if (mExpandedChild != null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 447 | mPreviousExpandedRemoteInputIntent = null; |
| 448 | if (mExpandedRemoteInput != null) { |
| 449 | mExpandedRemoteInput.onNotificationUpdateOrReset(); |
| 450 | if (mExpandedRemoteInput.isActive()) { |
| 451 | mPreviousExpandedRemoteInputIntent = mExpandedRemoteInput.getPendingIntent(); |
| 452 | mCachedExpandedRemoteInput = mExpandedRemoteInput; |
| 453 | mExpandedRemoteInput.dispatchStartTemporaryDetach(); |
| 454 | ((ViewGroup)mExpandedRemoteInput.getParent()).removeView(mExpandedRemoteInput); |
| 455 | } |
| 456 | } |
Jorim Jaggi | 0d9f35d | 2014-08-20 17:06:55 +0200 | [diff] [blame] | 457 | mExpandedChild.animate().cancel(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 458 | removeView(mExpandedChild); |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 459 | mExpandedRemoteInput = null; |
| 460 | } |
| 461 | if (child == null) { |
| 462 | mExpandedChild = null; |
| 463 | mExpandedWrapper = null; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 464 | if (mTransformationStartVisibleType == VISIBLE_TYPE_EXPANDED) { |
| 465 | mTransformationStartVisibleType = UNDEFINED; |
| 466 | } |
Selim Cinek | 9f18664 | 2018-11-29 15:47:40 -0800 | [diff] [blame] | 467 | if (mVisibleType == VISIBLE_TYPE_EXPANDED) { |
| 468 | selectLayout(false /* animate */, true /* force */); |
| 469 | } |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 470 | return; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 471 | } |
| 472 | addView(child); |
| 473 | mExpandedChild = child; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 474 | mExpandedWrapper = NotificationViewWrapper.wrap(getContext(), child, |
| 475 | mContainingNotification); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 476 | } |
| 477 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 478 | /** |
| 479 | * Sets the heads up view. Child may be null to remove the content view. |
| 480 | * |
| 481 | * @param child heads up content view to set |
| 482 | */ |
| 483 | public void setHeadsUpChild(@Nullable View child) { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 484 | if (mHeadsUpChild != null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 485 | mPreviousHeadsUpRemoteInputIntent = null; |
| 486 | if (mHeadsUpRemoteInput != null) { |
| 487 | mHeadsUpRemoteInput.onNotificationUpdateOrReset(); |
| 488 | if (mHeadsUpRemoteInput.isActive()) { |
| 489 | mPreviousHeadsUpRemoteInputIntent = mHeadsUpRemoteInput.getPendingIntent(); |
| 490 | mCachedHeadsUpRemoteInput = mHeadsUpRemoteInput; |
| 491 | mHeadsUpRemoteInput.dispatchStartTemporaryDetach(); |
| 492 | ((ViewGroup)mHeadsUpRemoteInput.getParent()).removeView(mHeadsUpRemoteInput); |
| 493 | } |
| 494 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 495 | mHeadsUpChild.animate().cancel(); |
| 496 | removeView(mHeadsUpChild); |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 497 | mHeadsUpRemoteInput = null; |
| 498 | } |
| 499 | if (child == null) { |
| 500 | mHeadsUpChild = null; |
| 501 | mHeadsUpWrapper = null; |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 502 | if (mTransformationStartVisibleType == VISIBLE_TYPE_HEADSUP) { |
| 503 | mTransformationStartVisibleType = UNDEFINED; |
| 504 | } |
Selim Cinek | 9f18664 | 2018-11-29 15:47:40 -0800 | [diff] [blame] | 505 | if (mVisibleType == VISIBLE_TYPE_HEADSUP) { |
| 506 | selectLayout(false /* animate */, true /* force */); |
| 507 | } |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 508 | return; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 509 | } |
| 510 | addView(child); |
| 511 | mHeadsUpChild = child; |
Selim Cinek | 7d1c63e | 2016-04-21 15:26:10 -0700 | [diff] [blame] | 512 | mHeadsUpWrapper = NotificationViewWrapper.wrap(getContext(), child, |
| 513 | mContainingNotification); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 516 | /** |
| 517 | * Sets the ambient view. Child may be null to remove the content view. |
| 518 | * |
| 519 | * @param child ambient content view to set |
| 520 | */ |
| 521 | public void setAmbientChild(@Nullable View child) { |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 522 | if (mAmbientChild != null) { |
| 523 | mAmbientChild.animate().cancel(); |
| 524 | removeView(mAmbientChild); |
| 525 | } |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 526 | if (child == null) { |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 527 | mAmbientChild = null; |
| 528 | mAmbientWrapper = null; |
Kevin | d4660b2 | 2018-09-27 10:57:35 -0700 | [diff] [blame] | 529 | if (mTransformationStartVisibleType == VISIBLE_TYPE_AMBIENT) { |
| 530 | mTransformationStartVisibleType = UNDEFINED; |
| 531 | } |
Selim Cinek | 9f18664 | 2018-11-29 15:47:40 -0800 | [diff] [blame] | 532 | if (mVisibleType == VISIBLE_TYPE_AMBIENT) { |
| 533 | selectLayout(false /* animate */, true /* force */); |
| 534 | } |
Adrian Roos | 1a1ecfc | 2017-04-17 11:17:59 -0700 | [diff] [blame] | 535 | return; |
| 536 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 537 | addView(child); |
| 538 | mAmbientChild = child; |
| 539 | mAmbientWrapper = NotificationViewWrapper.wrap(getContext(), child, |
| 540 | mContainingNotification); |
| 541 | } |
| 542 | |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 543 | @Override |
| 544 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 545 | super.onVisibilityChanged(changedView, visibility); |
| 546 | updateVisibility(); |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 547 | if (visibility != VISIBLE) { |
| 548 | // View is no longer visible so all content views are inactive. |
| 549 | for (Runnable r : mOnContentViewInactiveListeners.values()) { |
| 550 | r.run(); |
| 551 | } |
| 552 | mOnContentViewInactiveListeners.clear(); |
| 553 | } |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | private void updateVisibility() { |
| 557 | setVisible(isShown()); |
| 558 | } |
| 559 | |
Jorim Jaggi | 38b5ec9 | 2016-04-12 01:39:49 -0700 | [diff] [blame] | 560 | @Override |
| 561 | protected void onDetachedFromWindow() { |
| 562 | super.onDetachedFromWindow(); |
| 563 | getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener); |
| 564 | } |
| 565 | |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 566 | private void setVisible(final boolean isVisible) { |
| 567 | if (isVisible) { |
Selim Cinek | f1614a6 | 2016-05-26 16:57:20 -0700 | [diff] [blame] | 568 | // This call can happen multiple times, but removing only removes a single one. |
| 569 | // We therefore need to remove the old one. |
| 570 | getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 571 | // We only animate if we are drawn at least once, otherwise the view might animate when |
| 572 | // it's shown the first time |
| 573 | getViewTreeObserver().addOnPreDrawListener(mEnableAnimationPredrawListener); |
| 574 | } else { |
| 575 | getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener); |
| 576 | mAnimate = false; |
| 577 | } |
| 578 | } |
| 579 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 580 | private void focusExpandButtonIfNecessary() { |
| 581 | if (mFocusOnVisibilityChange) { |
| 582 | NotificationHeaderView header = getVisibleNotificationHeader(); |
| 583 | if (header != null) { |
| 584 | ImageView expandButton = header.getExpandButton(); |
| 585 | if (expandButton != null) { |
| 586 | expandButton.requestAccessibilityFocus(); |
| 587 | } |
| 588 | } |
| 589 | mFocusOnVisibilityChange = false; |
| 590 | } |
| 591 | } |
| 592 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 593 | public void setContentHeight(int contentHeight) { |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 594 | mUnrestrictedContentHeight = Math.max(contentHeight, getMinHeight()); |
| 595 | int maxContentHeight = mContainingNotification.getIntrinsicHeight() |
| 596 | - getExtraRemoteInputHeight(mExpandedRemoteInput) |
| 597 | - getExtraRemoteInputHeight(mHeadsUpRemoteInput); |
| 598 | mContentHeight = Math.min(mUnrestrictedContentHeight, maxContentHeight); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 599 | selectLayout(mAnimate /* animate */, false /* force */); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 600 | |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 601 | if (mContractedChild == null) { |
| 602 | // Contracted child may be null if this is the public content view and we don't need to |
| 603 | // show it. |
| 604 | return; |
| 605 | } |
| 606 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 607 | int minHeightHint = getMinContentHeightHint(); |
| 608 | |
| 609 | NotificationViewWrapper wrapper = getVisibleWrapper(mVisibleType); |
| 610 | if (wrapper != null) { |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 611 | wrapper.setContentHeight(mUnrestrictedContentHeight, minHeightHint); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | wrapper = getVisibleWrapper(mTransformationStartVisibleType); |
| 615 | if (wrapper != null) { |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 616 | wrapper.setContentHeight(mUnrestrictedContentHeight, minHeightHint); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 617 | } |
| 618 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 619 | updateClipping(); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 620 | invalidateOutline(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 621 | } |
| 622 | |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 623 | /** |
| 624 | * @return the minimum apparent height that the wrapper should allow for the purpose |
| 625 | * of aligning elements at the bottom edge. If this is larger than the content |
| 626 | * height, the notification is clipped instead of being further shrunk. |
| 627 | */ |
| 628 | private int getMinContentHeightHint() { |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 629 | if (mIsChildInGroup && isVisibleOrTransitioning(VISIBLE_TYPE_SINGLELINE)) { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 630 | return mContext.getResources().getDimensionPixelSize( |
| 631 | com.android.internal.R.dimen.notification_action_list_height); |
| 632 | } |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 633 | |
| 634 | // Transition between heads-up & expanded, or pinned. |
| 635 | if (mHeadsUpChild != null && mExpandedChild != null) { |
| 636 | boolean transitioningBetweenHunAndExpanded = |
| 637 | isTransitioningFromTo(VISIBLE_TYPE_HEADSUP, VISIBLE_TYPE_EXPANDED) || |
| 638 | isTransitioningFromTo(VISIBLE_TYPE_EXPANDED, VISIBLE_TYPE_HEADSUP); |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 639 | boolean pinned = !isVisibleOrTransitioning(VISIBLE_TYPE_CONTRACTED) |
Selim Cinek | c494e38 | 2017-01-31 16:09:23 -0800 | [diff] [blame] | 640 | && (mIsHeadsUp || mHeadsUpAnimatingAway) |
| 641 | && !mContainingNotification.isOnKeyguard(); |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 642 | if (transitioningBetweenHunAndExpanded || pinned) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 643 | return Math.min(getViewHeight(VISIBLE_TYPE_HEADSUP), |
| 644 | getViewHeight(VISIBLE_TYPE_EXPANDED)); |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 645 | } |
| 646 | } |
| 647 | |
| 648 | // Size change of the expanded version |
| 649 | if ((mVisibleType == VISIBLE_TYPE_EXPANDED) && mContentHeightAtAnimationStart >= 0 |
| 650 | && mExpandedChild != null) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 651 | return Math.min(mContentHeightAtAnimationStart, getViewHeight(VISIBLE_TYPE_EXPANDED)); |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Adrian Roos | bb73e9c6 | 2016-05-26 12:06:40 -0700 | [diff] [blame] | 654 | int hint; |
Adrian Roos | 05d3d00 | 2017-01-26 15:28:07 -0800 | [diff] [blame] | 655 | if (mAmbientChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_AMBIENT)) { |
| 656 | hint = mAmbientChild.getHeight(); |
Selim Cinek | 7927c73 | 2019-03-06 15:21:39 -0800 | [diff] [blame] | 657 | } else if (mHeadsUpChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_HEADSUP)) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 658 | hint = getViewHeight(VISIBLE_TYPE_HEADSUP); |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 659 | } else if (mExpandedChild != null) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 660 | hint = getViewHeight(VISIBLE_TYPE_EXPANDED); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 661 | } else { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 662 | hint = getViewHeight(VISIBLE_TYPE_CONTRACTED) |
| 663 | + mContext.getResources().getDimensionPixelSize( |
| 664 | com.android.internal.R.dimen.notification_action_list_height); |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 665 | } |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 666 | |
| 667 | if (mExpandedChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_EXPANDED)) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 668 | hint = Math.min(hint, getViewHeight(VISIBLE_TYPE_EXPANDED)); |
Adrian Roos | bb73e9c6 | 2016-05-26 12:06:40 -0700 | [diff] [blame] | 669 | } |
| 670 | return hint; |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 671 | } |
| 672 | |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 673 | private boolean isTransitioningFromTo(int from, int to) { |
| 674 | return (mTransformationStartVisibleType == from || mAnimationStartVisibleType == from) |
| 675 | && mVisibleType == to; |
| 676 | } |
| 677 | |
| 678 | private boolean isVisibleOrTransitioning(int type) { |
| 679 | return mVisibleType == type || mTransformationStartVisibleType == type |
| 680 | || mAnimationStartVisibleType == type; |
| 681 | } |
| 682 | |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 683 | private void updateContentTransformation() { |
| 684 | int visibleType = calculateVisibleType(); |
| 685 | if (visibleType != mVisibleType) { |
| 686 | // A new transformation starts |
| 687 | mTransformationStartVisibleType = mVisibleType; |
| 688 | final TransformableView shownView = getTransformableViewForVisibleType(visibleType); |
| 689 | final TransformableView hiddenView = getTransformableViewForVisibleType( |
| 690 | mTransformationStartVisibleType); |
| 691 | shownView.transformFrom(hiddenView, 0.0f); |
| 692 | getViewForVisibleType(visibleType).setVisibility(View.VISIBLE); |
| 693 | hiddenView.transformTo(shownView, 0.0f); |
| 694 | mVisibleType = visibleType; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 695 | updateBackgroundColor(true /* animate */); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 696 | } |
Selim Cinek | e857887 | 2016-05-03 16:42:50 -0700 | [diff] [blame] | 697 | if (mForceSelectNextLayout) { |
| 698 | forceUpdateVisibilities(); |
| 699 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 700 | if (mTransformationStartVisibleType != UNDEFINED |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 701 | && mVisibleType != mTransformationStartVisibleType |
| 702 | && getViewForVisibleType(mTransformationStartVisibleType) != null) { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 703 | final TransformableView shownView = getTransformableViewForVisibleType(mVisibleType); |
| 704 | final TransformableView hiddenView = getTransformableViewForVisibleType( |
| 705 | mTransformationStartVisibleType); |
| 706 | float transformationAmount = calculateTransformationAmount(); |
| 707 | shownView.transformFrom(hiddenView, transformationAmount); |
| 708 | hiddenView.transformTo(shownView, transformationAmount); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 709 | updateBackgroundTransformation(transformationAmount); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 710 | } else { |
| 711 | updateViewVisibilities(visibleType); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 712 | updateBackgroundColor(false); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 713 | } |
| 714 | } |
| 715 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 716 | private void updateBackgroundTransformation(float transformationAmount) { |
| 717 | int endColor = getBackgroundColor(mVisibleType); |
| 718 | int startColor = getBackgroundColor(mTransformationStartVisibleType); |
| 719 | if (endColor != startColor) { |
| 720 | if (startColor == 0) { |
| 721 | startColor = mContainingNotification.getBackgroundColorWithoutTint(); |
| 722 | } |
| 723 | if (endColor == 0) { |
| 724 | endColor = mContainingNotification.getBackgroundColorWithoutTint(); |
| 725 | } |
| 726 | endColor = NotificationUtils.interpolateColors(startColor, endColor, |
| 727 | transformationAmount); |
| 728 | } |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 729 | mContainingNotification.updateBackgroundAlpha(transformationAmount); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 730 | mContainingNotification.setContentBackground(endColor, false, this); |
| 731 | } |
| 732 | |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 733 | private float calculateTransformationAmount() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 734 | int startHeight = getViewHeight(mTransformationStartVisibleType); |
| 735 | int endHeight = getViewHeight(mVisibleType); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 736 | int progress = Math.abs(mContentHeight - startHeight); |
| 737 | int totalDistance = Math.abs(endHeight - startHeight); |
Selim Cinek | 011bde9 | 2017-11-22 05:53:38 -0800 | [diff] [blame] | 738 | if (totalDistance == 0) { |
| 739 | Log.wtf(TAG, "the total transformation distance is 0" |
| 740 | + "\n StartType: " + mTransformationStartVisibleType + " height: " + startHeight |
| 741 | + "\n VisibleType: " + mVisibleType + " height: " + endHeight |
| 742 | + "\n mContentHeight: " + mContentHeight); |
| 743 | return 1.0f; |
| 744 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 745 | float amount = (float) progress / (float) totalDistance; |
| 746 | return Math.min(1.0f, amount); |
| 747 | } |
| 748 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 749 | public int getContentHeight() { |
| 750 | return mContentHeight; |
| 751 | } |
| 752 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 753 | public int getMaxHeight() { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 754 | if (mExpandedChild != null) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 755 | return getViewHeight(VISIBLE_TYPE_EXPANDED) |
| 756 | + getExtraRemoteInputHeight(mExpandedRemoteInput); |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 757 | } else if (mContainingNotification.isOnAmbient() && getShowingAmbientView() != null) { |
| 758 | return getShowingAmbientView().getHeight(); |
Selim Cinek | c494e38 | 2017-01-31 16:09:23 -0800 | [diff] [blame] | 759 | } else if (mIsHeadsUp && mHeadsUpChild != null && !mContainingNotification.isOnKeyguard()) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 760 | return getViewHeight(VISIBLE_TYPE_HEADSUP) |
| 761 | + getExtraRemoteInputHeight(mHeadsUpRemoteInput); |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 762 | } else if (mContractedChild != null) { |
| 763 | return getViewHeight(VISIBLE_TYPE_CONTRACTED); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 764 | } |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 765 | return mNotificationMaxHeight; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | private int getViewHeight(int visibleType) { |
| 769 | View view = getViewForVisibleType(visibleType); |
| 770 | int height = view.getHeight(); |
| 771 | NotificationViewWrapper viewWrapper = getWrapperForView(view); |
| 772 | if (viewWrapper != null) { |
| 773 | height += viewWrapper.getHeaderTranslation(); |
| 774 | } |
| 775 | return height; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 776 | } |
| 777 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 778 | public int getMinHeight() { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 779 | return getMinHeight(false /* likeGroupExpanded */); |
| 780 | } |
| 781 | |
| 782 | public int getMinHeight(boolean likeGroupExpanded) { |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 783 | if (mContainingNotification.isOnAmbient() && getShowingAmbientView() != null) { |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 784 | return getShowingAmbientView().getHeight(); |
| 785 | } else if (likeGroupExpanded || !mIsChildInGroup || isGroupExpanded()) { |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 786 | return mContractedChild != null |
| 787 | ? getViewHeight(VISIBLE_TYPE_CONTRACTED) : mMinContractedHeight; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 788 | } else { |
| 789 | return mSingleLineView.getHeight(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 790 | } |
| 791 | } |
| 792 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 793 | public View getShowingAmbientView() { |
Selim Cinek | 7927c73 | 2019-03-06 15:21:39 -0800 | [diff] [blame] | 794 | View v = mIsChildInGroup ? mSingleLineView : mAmbientChild; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 795 | if (v != null) { |
| 796 | return v; |
| 797 | } else { |
| 798 | return mContractedChild; |
| 799 | } |
| 800 | } |
| 801 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 802 | private boolean isGroupExpanded() { |
| 803 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 804 | } |
| 805 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 806 | public void setClipTopAmount(int clipTopAmount) { |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 807 | mClipTopAmount = clipTopAmount; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 808 | updateClipping(); |
| 809 | } |
| 810 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 811 | |
| 812 | public void setClipBottomAmount(int clipBottomAmount) { |
| 813 | mClipBottomAmount = clipBottomAmount; |
| 814 | updateClipping(); |
| 815 | } |
| 816 | |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 817 | @Override |
| 818 | public void setTranslationY(float translationY) { |
| 819 | super.setTranslationY(translationY); |
| 820 | updateClipping(); |
| 821 | } |
| 822 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 823 | private void updateClipping() { |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 824 | if (mClipToActualHeight) { |
Selim Cinek | 875a3a1 | 2016-11-18 17:52:16 -0800 | [diff] [blame] | 825 | int top = (int) (mClipTopAmount - getTranslationY()); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 826 | int bottom = (int) (mUnrestrictedContentHeight - mClipBottomAmount - getTranslationY()); |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 827 | bottom = Math.max(top, bottom); |
| 828 | mClipBounds.set(0, top, getWidth(), bottom); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 829 | setClipBounds(mClipBounds); |
| 830 | } else { |
| 831 | setClipBounds(null); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | public void setClipToActualHeight(boolean clipToActualHeight) { |
| 836 | mClipToActualHeight = clipToActualHeight; |
| 837 | updateClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 838 | } |
| 839 | |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 840 | private void selectLayout(boolean animate, boolean force) { |
| 841 | if (mContractedChild == null) { |
| 842 | return; |
| 843 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 844 | if (mUserExpanding) { |
| 845 | updateContentTransformation(); |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 846 | } else { |
| 847 | int visibleType = calculateVisibleType(); |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 848 | boolean changedType = visibleType != mVisibleType; |
| 849 | if (changedType || force) { |
Adrian Roos | 181385c | 2016-05-05 17:45:44 -0400 | [diff] [blame] | 850 | View visibleView = getViewForVisibleType(visibleType); |
| 851 | if (visibleView != null) { |
| 852 | visibleView.setVisibility(VISIBLE); |
| 853 | transferRemoteInputFocus(visibleType); |
| 854 | } |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 855 | |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 856 | if (animate && ((visibleType == VISIBLE_TYPE_EXPANDED && mExpandedChild != null) |
| 857 | || (visibleType == VISIBLE_TYPE_HEADSUP && mHeadsUpChild != null) |
| 858 | || (visibleType == VISIBLE_TYPE_SINGLELINE && mSingleLineView != null) |
| 859 | || visibleType == VISIBLE_TYPE_CONTRACTED)) { |
| 860 | animateToVisibleType(visibleType); |
| 861 | } else { |
| 862 | updateViewVisibilities(visibleType); |
| 863 | } |
| 864 | mVisibleType = visibleType; |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 865 | if (changedType) { |
| 866 | focusExpandButtonIfNecessary(); |
| 867 | } |
Adrian Roos | 05d3d00 | 2017-01-26 15:28:07 -0800 | [diff] [blame] | 868 | NotificationViewWrapper visibleWrapper = getVisibleWrapper(visibleType); |
| 869 | if (visibleWrapper != null) { |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 870 | visibleWrapper.setContentHeight(mUnrestrictedContentHeight, |
| 871 | getMinContentHeightHint()); |
Adrian Roos | 05d3d00 | 2017-01-26 15:28:07 -0800 | [diff] [blame] | 872 | } |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 873 | updateBackgroundColor(animate); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 874 | } |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 875 | } |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | private void forceUpdateVisibilities() { |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 879 | forceUpdateVisibility(VISIBLE_TYPE_CONTRACTED, mContractedChild, mContractedWrapper); |
| 880 | forceUpdateVisibility(VISIBLE_TYPE_EXPANDED, mExpandedChild, mExpandedWrapper); |
| 881 | forceUpdateVisibility(VISIBLE_TYPE_HEADSUP, mHeadsUpChild, mHeadsUpWrapper); |
| 882 | forceUpdateVisibility(VISIBLE_TYPE_SINGLELINE, mSingleLineView, mSingleLineView); |
| 883 | forceUpdateVisibility(VISIBLE_TYPE_AMBIENT, mAmbientChild, mAmbientWrapper); |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 884 | fireExpandedVisibleListenerIfVisible(); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 885 | // forceUpdateVisibilities cancels outstanding animations without updating the |
| 886 | // mAnimationStartVisibleType. Do so here instead. |
| 887 | mAnimationStartVisibleType = UNDEFINED; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 888 | } |
| 889 | |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 890 | private void fireExpandedVisibleListenerIfVisible() { |
| 891 | if (mExpandedVisibleListener != null && mExpandedChild != null && isShown() |
| 892 | && mExpandedChild.getVisibility() == VISIBLE) { |
| 893 | Runnable listener = mExpandedVisibleListener; |
| 894 | mExpandedVisibleListener = null; |
| 895 | listener.run(); |
| 896 | } |
| 897 | } |
| 898 | |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 899 | private void forceUpdateVisibility(int type, View view, TransformableView wrapper) { |
| 900 | if (view == null) { |
| 901 | return; |
| 902 | } |
| 903 | boolean visible = mVisibleType == type |
| 904 | || mTransformationStartVisibleType == type; |
| 905 | if (!visible) { |
| 906 | view.setVisibility(INVISIBLE); |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 907 | } else { |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 908 | wrapper.setVisible(true); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 909 | } |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 910 | } |
| 911 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 912 | public void updateBackgroundColor(boolean animate) { |
| 913 | int customBackgroundColor = getBackgroundColor(mVisibleType); |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 914 | mContainingNotification.resetBackgroundAlpha(); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 915 | mContainingNotification.setContentBackground(customBackgroundColor, animate, this); |
| 916 | } |
| 917 | |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 918 | public void setBackgroundTintColor(int color) { |
| 919 | if (mExpandedSmartReplyView != null) { |
| 920 | mExpandedSmartReplyView.setBackgroundTintColor(color); |
| 921 | } |
Gustav Sennton | d0e8453 | 2018-12-03 16:48:36 +0000 | [diff] [blame] | 922 | if (mHeadsUpSmartReplyView != null) { |
| 923 | mHeadsUpSmartReplyView.setBackgroundTintColor(color); |
| 924 | } |
Kenny Guy | 14d035c | 2018-05-02 19:10:36 +0100 | [diff] [blame] | 925 | } |
| 926 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 927 | public int getVisibleType() { |
| 928 | return mVisibleType; |
| 929 | } |
| 930 | |
| 931 | public int getBackgroundColorForExpansionState() { |
| 932 | // When expanding or user locked we want the new type, when collapsing we want |
| 933 | // the original type |
| 934 | final int visibleType = (mContainingNotification.isGroupExpanded() |
| 935 | || mContainingNotification.isUserLocked()) |
| 936 | ? calculateVisibleType() |
| 937 | : getVisibleType(); |
| 938 | return getBackgroundColor(visibleType); |
| 939 | } |
| 940 | |
| 941 | public int getBackgroundColor(int visibleType) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 942 | NotificationViewWrapper currentVisibleWrapper = getVisibleWrapper(visibleType); |
| 943 | int customBackgroundColor = 0; |
| 944 | if (currentVisibleWrapper != null) { |
| 945 | customBackgroundColor = currentVisibleWrapper.getCustomBackgroundColor(); |
| 946 | } |
| 947 | return customBackgroundColor; |
| 948 | } |
| 949 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 950 | private void updateViewVisibilities(int visibleType) { |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 951 | updateViewVisibility(visibleType, VISIBLE_TYPE_CONTRACTED, |
| 952 | mContractedChild, mContractedWrapper); |
| 953 | updateViewVisibility(visibleType, VISIBLE_TYPE_EXPANDED, |
| 954 | mExpandedChild, mExpandedWrapper); |
| 955 | updateViewVisibility(visibleType, VISIBLE_TYPE_HEADSUP, |
| 956 | mHeadsUpChild, mHeadsUpWrapper); |
| 957 | updateViewVisibility(visibleType, VISIBLE_TYPE_SINGLELINE, |
| 958 | mSingleLineView, mSingleLineView); |
| 959 | updateViewVisibility(visibleType, VISIBLE_TYPE_AMBIENT, |
| 960 | mAmbientChild, mAmbientWrapper); |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 961 | fireExpandedVisibleListenerIfVisible(); |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 962 | // updateViewVisibilities cancels outstanding animations without updating the |
| 963 | // mAnimationStartVisibleType. Do so here instead. |
| 964 | mAnimationStartVisibleType = UNDEFINED; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 965 | } |
| 966 | |
| 967 | private void updateViewVisibility(int visibleType, int type, View view, |
| 968 | TransformableView wrapper) { |
| 969 | if (view != null) { |
| 970 | wrapper.setVisible(visibleType == type); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 971 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 972 | } |
| 973 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 974 | private void animateToVisibleType(int visibleType) { |
| 975 | final TransformableView shownView = getTransformableViewForVisibleType(visibleType); |
| 976 | final TransformableView hiddenView = getTransformableViewForVisibleType(mVisibleType); |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 977 | if (shownView == hiddenView || hiddenView == null) { |
Selim Cinek | 51d9491 | 2016-03-02 15:34:28 -0800 | [diff] [blame] | 978 | shownView.setVisible(true); |
| 979 | return; |
| 980 | } |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 981 | mAnimationStartVisibleType = mVisibleType; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 982 | shownView.transformFrom(hiddenView); |
| 983 | getViewForVisibleType(visibleType).setVisibility(View.VISIBLE); |
| 984 | hiddenView.transformTo(shownView, new Runnable() { |
| 985 | @Override |
| 986 | public void run() { |
Selim Cinek | 51d9491 | 2016-03-02 15:34:28 -0800 | [diff] [blame] | 987 | if (hiddenView != getTransformableViewForVisibleType(mVisibleType)) { |
| 988 | hiddenView.setVisible(false); |
| 989 | } |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 990 | mAnimationStartVisibleType = UNDEFINED; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 991 | } |
| 992 | }); |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 993 | fireExpandedVisibleListenerIfVisible(); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 994 | } |
| 995 | |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 996 | private void transferRemoteInputFocus(int visibleType) { |
| 997 | if (visibleType == VISIBLE_TYPE_HEADSUP |
| 998 | && mHeadsUpRemoteInput != null |
| 999 | && (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive())) { |
| 1000 | mHeadsUpRemoteInput.stealFocusFrom(mExpandedRemoteInput); |
| 1001 | } |
| 1002 | if (visibleType == VISIBLE_TYPE_EXPANDED |
| 1003 | && mExpandedRemoteInput != null |
| 1004 | && (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive())) { |
| 1005 | mExpandedRemoteInput.stealFocusFrom(mHeadsUpRemoteInput); |
| 1006 | } |
| 1007 | } |
| 1008 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1009 | /** |
| 1010 | * @param visibleType one of the static enum types in this view |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1011 | * @return the corresponding transformable view according to the given visible type |
| 1012 | */ |
| 1013 | private TransformableView getTransformableViewForVisibleType(int visibleType) { |
| 1014 | switch (visibleType) { |
| 1015 | case VISIBLE_TYPE_EXPANDED: |
| 1016 | return mExpandedWrapper; |
| 1017 | case VISIBLE_TYPE_HEADSUP: |
| 1018 | return mHeadsUpWrapper; |
| 1019 | case VISIBLE_TYPE_SINGLELINE: |
| 1020 | return mSingleLineView; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1021 | case VISIBLE_TYPE_AMBIENT: |
| 1022 | return mAmbientWrapper; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 1023 | default: |
| 1024 | return mContractedWrapper; |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * @param visibleType one of the static enum types in this view |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1030 | * @return the corresponding view according to the given visible type |
| 1031 | */ |
| 1032 | private View getViewForVisibleType(int visibleType) { |
| 1033 | switch (visibleType) { |
| 1034 | case VISIBLE_TYPE_EXPANDED: |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1035 | return mExpandedChild; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1036 | case VISIBLE_TYPE_HEADSUP: |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1037 | return mHeadsUpChild; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1038 | case VISIBLE_TYPE_SINGLELINE: |
| 1039 | return mSingleLineView; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1040 | case VISIBLE_TYPE_AMBIENT: |
| 1041 | return mAmbientChild; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1042 | default: |
| 1043 | return mContractedChild; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1044 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
Selim Cinek | 131f1a4 | 2017-06-05 17:50:19 -0700 | [diff] [blame] | 1047 | public NotificationViewWrapper getVisibleWrapper(int visibleType) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1048 | switch (visibleType) { |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 1049 | case VISIBLE_TYPE_EXPANDED: |
| 1050 | return mExpandedWrapper; |
| 1051 | case VISIBLE_TYPE_HEADSUP: |
| 1052 | return mHeadsUpWrapper; |
| 1053 | case VISIBLE_TYPE_CONTRACTED: |
| 1054 | return mContractedWrapper; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1055 | case VISIBLE_TYPE_AMBIENT: |
| 1056 | return mAmbientWrapper; |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 1057 | default: |
| 1058 | return null; |
| 1059 | } |
| 1060 | } |
| 1061 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1062 | /** |
| 1063 | * @return one of the static enum types in this view, calculated form the current state |
| 1064 | */ |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 1065 | public int calculateVisibleType() { |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1066 | if (mUserExpanding) { |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1067 | int height = !mIsChildInGroup || isGroupExpanded() |
Selim Cinek | e81b82b | 2016-03-04 11:22:28 -0800 | [diff] [blame] | 1068 | || mContainingNotification.isExpanded(true /* allowOnKeyguard */) |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1069 | ? mContainingNotification.getMaxContentHeight() |
| 1070 | : mContainingNotification.getShowingLayout().getMinHeight(); |
Selim Cinek | 51d9491 | 2016-03-02 15:34:28 -0800 | [diff] [blame] | 1071 | if (height == 0) { |
| 1072 | height = mContentHeight; |
| 1073 | } |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 1074 | int expandedVisualType = getVisualTypeForHeight(height); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1075 | int collapsedVisualType = mIsChildInGroup && !isGroupExpanded() |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 1076 | ? VISIBLE_TYPE_SINGLELINE |
| 1077 | : getVisualTypeForHeight(mContainingNotification.getCollapsedHeight()); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1078 | return mTransformationStartVisibleType == collapsedVisualType |
| 1079 | ? expandedVisualType |
| 1080 | : collapsedVisualType; |
| 1081 | } |
Selim Cinek | 51d9491 | 2016-03-02 15:34:28 -0800 | [diff] [blame] | 1082 | int intrinsicHeight = mContainingNotification.getIntrinsicHeight(); |
| 1083 | int viewHeight = mContentHeight; |
| 1084 | if (intrinsicHeight != 0) { |
| 1085 | // the intrinsicHeight might be 0 because it was just reset. |
| 1086 | viewHeight = Math.min(mContentHeight, intrinsicHeight); |
| 1087 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1088 | return getVisualTypeForHeight(viewHeight); |
| 1089 | } |
| 1090 | |
| 1091 | private int getVisualTypeForHeight(float viewHeight) { |
| 1092 | boolean noExpandedChild = mExpandedChild == null; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1093 | if (!noExpandedChild && viewHeight == getViewHeight(VISIBLE_TYPE_EXPANDED)) { |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 1094 | return VISIBLE_TYPE_EXPANDED; |
| 1095 | } |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1096 | boolean onAmbient = mContainingNotification.isOnAmbient(); |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1097 | if (!mUserExpanding && mIsChildInGroup && !isGroupExpanded()) { |
Selim Cinek | 7927c73 | 2019-03-06 15:21:39 -0800 | [diff] [blame] | 1098 | return VISIBLE_TYPE_SINGLELINE; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 1099 | } |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 1100 | |
Selim Cinek | c494e38 | 2017-01-31 16:09:23 -0800 | [diff] [blame] | 1101 | if ((mIsHeadsUp || mHeadsUpAnimatingAway) && mHeadsUpChild != null |
| 1102 | && !mContainingNotification.isOnKeyguard()) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1103 | if (viewHeight <= getViewHeight(VISIBLE_TYPE_HEADSUP) || noExpandedChild) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1104 | return VISIBLE_TYPE_HEADSUP; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1105 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1106 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1107 | } |
| 1108 | } else { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1109 | int collapsedType = onAmbient && mAmbientChild != null ? VISIBLE_TYPE_AMBIENT : |
| 1110 | VISIBLE_TYPE_CONTRACTED; |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 1111 | if (noExpandedChild || (mContractedChild != null |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1112 | && viewHeight <= getViewHeight(collapsedType) |
Selim Cinek | 6ac3fa8 | 2016-05-10 17:11:54 -0400 | [diff] [blame] | 1113 | && (!mIsChildInGroup || isGroupExpanded() |
Selim Cinek | e81b82b | 2016-03-04 11:22:28 -0800 | [diff] [blame] | 1114 | || !mContainingNotification.isExpanded(true /* allowOnKeyguard */)))) { |
Selim Cinek | 3d6ae23 | 2019-01-04 14:14:33 -0800 | [diff] [blame] | 1115 | return collapsedType; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1116 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 1117 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1118 | } |
| 1119 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1120 | } |
| 1121 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1122 | public boolean isContentExpandable() { |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 1123 | return mIsContentExpandable; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 1124 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1125 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 1126 | public void setDark(boolean dark, boolean fade, long delay) { |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 1127 | if (mContractedChild == null) { |
Selim Cinek | 0934bd9 | 2016-02-19 12:22:33 -0800 | [diff] [blame] | 1128 | return; |
| 1129 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1130 | mDark = dark; |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1131 | selectLayout(!dark && fade /* animate */, false /* force */); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 1132 | } |
| 1133 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1134 | public void setHeadsUp(boolean headsUp) { |
| 1135 | mIsHeadsUp = headsUp; |
| 1136 | selectLayout(false /* animate */, true /* force */); |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 1137 | updateExpandButtons(mExpandable); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 1138 | } |
| 1139 | |
Jorim Jaggi | aa92ffb | 2014-09-10 23:29:28 +0200 | [diff] [blame] | 1140 | @Override |
| 1141 | public boolean hasOverlappingRendering() { |
| 1142 | |
| 1143 | // This is not really true, but good enough when fading from the contracted to the expanded |
| 1144 | // layout, and saves us some layers. |
| 1145 | return false; |
| 1146 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1147 | |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1148 | public void setLegacy(boolean legacy) { |
| 1149 | mLegacy = legacy; |
| 1150 | updateLegacy(); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1151 | } |
| 1152 | |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1153 | private void updateLegacy() { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1154 | if (mContractedChild != null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1155 | mContractedWrapper.setLegacy(mLegacy); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1156 | } |
| 1157 | if (mExpandedChild != null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1158 | mExpandedWrapper.setLegacy(mLegacy); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1159 | } |
| 1160 | if (mHeadsUpChild != null) { |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1161 | mHeadsUpWrapper.setLegacy(mLegacy); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1162 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 1163 | } |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 1164 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1165 | public void setIsChildInGroup(boolean isChildInGroup) { |
| 1166 | mIsChildInGroup = isChildInGroup; |
Selim Cinek | 414ad33 | 2017-02-24 19:06:12 -0800 | [diff] [blame] | 1167 | if (mContractedChild != null) { |
| 1168 | mContractedWrapper.setIsChildInGroup(mIsChildInGroup); |
| 1169 | } |
| 1170 | if (mExpandedChild != null) { |
| 1171 | mExpandedWrapper.setIsChildInGroup(mIsChildInGroup); |
| 1172 | } |
| 1173 | if (mHeadsUpChild != null) { |
| 1174 | mHeadsUpWrapper.setIsChildInGroup(mIsChildInGroup); |
| 1175 | } |
| 1176 | if (mAmbientChild != null) { |
| 1177 | mAmbientWrapper.setIsChildInGroup(mIsChildInGroup); |
| 1178 | } |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1179 | updateAllSingleLineViews(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1182 | public void onNotificationUpdated(NotificationEntry entry) { |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1183 | mStatusBarNotification = entry.notification; |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 1184 | mOnContentViewInactiveListeners.clear(); |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 1185 | mBeforeN = entry.targetSdk < Build.VERSION_CODES.N; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1186 | updateAllSingleLineViews(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1187 | ExpandableNotificationRow row = entry.getRow(); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1188 | if (mContractedChild != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1189 | mContractedWrapper.onContentUpdated(row); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1190 | } |
| 1191 | if (mExpandedChild != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1192 | mExpandedWrapper.onContentUpdated(row); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1193 | } |
| 1194 | if (mHeadsUpChild != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1195 | mHeadsUpWrapper.onContentUpdated(row); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 1196 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1197 | if (mAmbientChild != null) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 1198 | mAmbientWrapper.onContentUpdated(row); |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1199 | } |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1200 | applyRemoteInputAndSmartReply(entry); |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 1201 | applyMediaTransfer(entry); |
Selim Cinek | 1a48bab | 2017-02-17 19:38:40 -0800 | [diff] [blame] | 1202 | updateLegacy(); |
Selim Cinek | 589fd3e | 2016-04-26 18:17:57 -0700 | [diff] [blame] | 1203 | mForceSelectNextLayout = true; |
Selim Cinek | b88b984 | 2016-02-26 09:25:33 -0800 | [diff] [blame] | 1204 | setDark(mDark, false /* animate */, 0 /* delay */); |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 1205 | mPreviousExpandedRemoteInputIntent = null; |
| 1206 | mPreviousHeadsUpRemoteInputIntent = null; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1207 | } |
| 1208 | |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1209 | private void updateAllSingleLineViews() { |
| 1210 | updateSingleLineView(); |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1211 | } |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 1212 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1213 | private void updateSingleLineView() { |
| 1214 | if (mIsChildInGroup) { |
Selim Cinek | c5926c3 | 2018-05-15 11:17:07 -0700 | [diff] [blame] | 1215 | boolean isNewView = mSingleLineView == null; |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1216 | mSingleLineView = mHybridGroupManager.bindFromNotification( |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1217 | mSingleLineView, mStatusBarNotification.getNotification()); |
Selim Cinek | c5926c3 | 2018-05-15 11:17:07 -0700 | [diff] [blame] | 1218 | if (isNewView) { |
| 1219 | updateViewVisibility(mVisibleType, VISIBLE_TYPE_SINGLELINE, |
| 1220 | mSingleLineView, mSingleLineView); |
| 1221 | } |
Selim Cinek | de33a4a | 2016-02-11 16:43:41 -0800 | [diff] [blame] | 1222 | } else if (mSingleLineView != null) { |
| 1223 | removeView(mSingleLineView); |
| 1224 | mSingleLineView = null; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1225 | } |
| 1226 | } |
| 1227 | |
linanson | 2bcd403 | 2019-01-14 15:22:04 +0800 | [diff] [blame] | 1228 | private void applyMediaTransfer(final NotificationEntry entry) { |
| 1229 | View bigContentView = mExpandedChild; |
| 1230 | if (bigContentView == null || !entry.isMediaNotification()) { |
| 1231 | return; |
| 1232 | } |
| 1233 | |
| 1234 | View mediaActionContainer = bigContentView.findViewById( |
| 1235 | com.android.internal.R.id.media_actions); |
| 1236 | if (!(mediaActionContainer instanceof LinearLayout)) { |
| 1237 | return; |
| 1238 | } |
| 1239 | |
| 1240 | mMediaTransferManager.applyMediaTransferView((ViewGroup) mediaActionContainer, |
| 1241 | entry); |
| 1242 | } |
| 1243 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1244 | private void applyRemoteInputAndSmartReply(final NotificationEntry entry) { |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1245 | if (mRemoteInputController == null) { |
| 1246 | return; |
| 1247 | } |
| 1248 | |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1249 | applyRemoteInput(entry, InflatedSmartReplies.hasFreeformRemoteInput(entry)); |
| 1250 | |
| 1251 | if (mExpandedInflatedSmartReplies == null && mHeadsUpInflatedSmartReplies == null) { |
| 1252 | if (DEBUG) { |
| 1253 | Log.d(TAG, "Both expanded, and heads-up InflatedSmartReplies are null, " |
| 1254 | + "don't add smart replies."); |
| 1255 | } |
| 1256 | return; |
| 1257 | } |
| 1258 | // The inflated smart-reply objects for the expanded view and the heads-up view both contain |
| 1259 | // the same SmartRepliesAndActions to avoid discrepancies between the two views. We here |
| 1260 | // reuse that object for our local SmartRepliesAndActions to avoid discrepancies between |
| 1261 | // this class and the InflatedSmartReplies classes. |
| 1262 | SmartRepliesAndActions smartRepliesAndActions = mExpandedInflatedSmartReplies != null |
| 1263 | ? mExpandedInflatedSmartReplies.getSmartRepliesAndActions() |
| 1264 | : mHeadsUpInflatedSmartReplies.getSmartRepliesAndActions(); |
Gustav Sennton | 2d66b51 | 2019-01-31 17:48:17 +0000 | [diff] [blame] | 1265 | if (DEBUG) { |
| 1266 | Log.d(TAG, String.format("Adding suggestions for %s, %d actions, and %d replies.", |
| 1267 | entry.notification.getKey(), |
| 1268 | smartRepliesAndActions.smartActions == null ? 0 : |
| 1269 | smartRepliesAndActions.smartActions.actions.size(), |
| 1270 | smartRepliesAndActions.smartReplies == null ? 0 : |
| 1271 | smartRepliesAndActions.smartReplies.choices.length)); |
| 1272 | } |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 1273 | applySmartReplyView(smartRepliesAndActions, entry); |
| 1274 | } |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 1275 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1276 | private void applyRemoteInput(NotificationEntry entry, boolean hasFreeformRemoteInput) { |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1277 | View bigContentView = mExpandedChild; |
| 1278 | if (bigContentView != null) { |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 1279 | mExpandedRemoteInput = applyRemoteInput(bigContentView, entry, hasFreeformRemoteInput, |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 1280 | mPreviousExpandedRemoteInputIntent, mCachedExpandedRemoteInput, |
| 1281 | mExpandedWrapper); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1282 | } else { |
| 1283 | mExpandedRemoteInput = null; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1284 | } |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 1285 | if (mCachedExpandedRemoteInput != null |
| 1286 | && mCachedExpandedRemoteInput != mExpandedRemoteInput) { |
| 1287 | // We had a cached remote input but didn't reuse it. Clean up required. |
| 1288 | mCachedExpandedRemoteInput.dispatchFinishTemporaryDetach(); |
| 1289 | } |
| 1290 | mCachedExpandedRemoteInput = null; |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 1291 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1292 | View headsUpContentView = mHeadsUpChild; |
| 1293 | if (headsUpContentView != null) { |
Tony Mak | 638430e | 2018-10-08 19:19:10 +0100 | [diff] [blame] | 1294 | mHeadsUpRemoteInput = applyRemoteInput( |
| 1295 | headsUpContentView, entry, hasFreeformRemoteInput, |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 1296 | mPreviousHeadsUpRemoteInputIntent, mCachedHeadsUpRemoteInput, mHeadsUpWrapper); |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1297 | } else { |
| 1298 | mHeadsUpRemoteInput = null; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1299 | } |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 1300 | if (mCachedHeadsUpRemoteInput != null |
| 1301 | && mCachedHeadsUpRemoteInput != mHeadsUpRemoteInput) { |
| 1302 | // We had a cached remote input but didn't reuse it. Clean up required. |
| 1303 | mCachedHeadsUpRemoteInput.dispatchFinishTemporaryDetach(); |
| 1304 | } |
| 1305 | mCachedHeadsUpRemoteInput = null; |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1306 | } |
| 1307 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1308 | private RemoteInputView applyRemoteInput(View view, NotificationEntry entry, |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 1309 | boolean hasRemoteInput, PendingIntent existingPendingIntent, |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 1310 | RemoteInputView cachedView, NotificationViewWrapper wrapper) { |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1311 | View actionContainerCandidate = view.findViewById( |
| 1312 | com.android.internal.R.id.actions_container); |
| 1313 | if (actionContainerCandidate instanceof FrameLayout) { |
| 1314 | RemoteInputView existing = (RemoteInputView) |
| 1315 | view.findViewWithTag(RemoteInputView.VIEW_TAG); |
| 1316 | |
| 1317 | if (existing != null) { |
Adrian Roos | 0789ee0 | 2016-06-01 11:34:58 -0700 | [diff] [blame] | 1318 | existing.onNotificationUpdateOrReset(); |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1319 | } |
| 1320 | |
| 1321 | if (existing == null && hasRemoteInput) { |
| 1322 | ViewGroup actionContainer = (FrameLayout) actionContainerCandidate; |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 1323 | if (cachedView == null) { |
| 1324 | RemoteInputView riv = RemoteInputView.inflate( |
| 1325 | mContext, actionContainer, entry, mRemoteInputController); |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1326 | |
Adrian Roos | 7813dd7 | 2016-09-23 17:12:17 -0700 | [diff] [blame] | 1327 | riv.setVisibility(View.INVISIBLE); |
| 1328 | actionContainer.addView(riv, new LayoutParams( |
| 1329 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 1330 | ViewGroup.LayoutParams.MATCH_PARENT) |
| 1331 | ); |
| 1332 | existing = riv; |
| 1333 | } else { |
| 1334 | actionContainer.addView(cachedView); |
| 1335 | cachedView.dispatchFinishTemporaryDetach(); |
| 1336 | cachedView.requestFocus(); |
| 1337 | existing = cachedView; |
| 1338 | } |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 1339 | } |
| 1340 | if (hasRemoteInput) { |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1341 | int color = entry.notification.getNotification().color; |
| 1342 | if (color == Notification.COLOR_DEFAULT) { |
| 1343 | color = mContext.getColor(R.color.default_remote_input_background); |
| 1344 | } |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 1345 | existing.setBackgroundColor(ContrastColorUtil.ensureTextBackgroundColor(color, |
Adrian Roos | 25ea5b8 | 2016-04-27 16:34:35 -0700 | [diff] [blame] | 1346 | mContext.getColor(R.color.remote_input_text_enabled), |
Adrian Roos | 4ff3b12 | 2016-02-01 12:26:13 -0800 | [diff] [blame] | 1347 | mContext.getColor(R.color.remote_input_hint))); |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 1348 | |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 1349 | existing.setWrapper(wrapper); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1350 | existing.setOnVisibilityChangedListener(this::setRemoteInputVisible); |
Adrian Roos | 7b9ed0d | 2017-01-24 15:55:18 -0800 | [diff] [blame] | 1351 | |
Adrian Roos | 4c1fcc8 | 2016-03-31 14:39:39 -0700 | [diff] [blame] | 1352 | if (existingPendingIntent != null || existing.isActive()) { |
| 1353 | // The current action could be gone, or the pending intent no longer valid. |
| 1354 | // If we find a matching action in the new notification, focus, otherwise close. |
| 1355 | Notification.Action[] actions = entry.notification.getNotification().actions; |
| 1356 | if (existingPendingIntent != null) { |
| 1357 | existing.setPendingIntent(existingPendingIntent); |
| 1358 | } |
| 1359 | if (existing.updatePendingIntentFromActions(actions)) { |
| 1360 | if (!existing.isActive()) { |
| 1361 | existing.focus(); |
| 1362 | } |
| 1363 | } else { |
| 1364 | if (existing.isActive()) { |
| 1365 | existing.close(); |
| 1366 | } |
| 1367 | } |
| 1368 | } |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1369 | } |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1370 | return existing; |
| 1371 | } |
| 1372 | return null; |
| 1373 | } |
| 1374 | |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1375 | private void applySmartReplyView( |
| 1376 | SmartRepliesAndActions smartRepliesAndActions, |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 1377 | NotificationEntry entry) { |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 1378 | if (mExpandedChild != null) { |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1379 | mExpandedSmartReplyView = applySmartReplyView(mExpandedChild, smartRepliesAndActions, |
| 1380 | entry, mExpandedInflatedSmartReplies); |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 1381 | if (mExpandedSmartReplyView != null) { |
| 1382 | if (smartRepliesAndActions.smartReplies != null |
| 1383 | || smartRepliesAndActions.smartActions != null) { |
| 1384 | int numSmartReplies = smartRepliesAndActions.smartReplies == null |
| 1385 | ? 0 : smartRepliesAndActions.smartReplies.choices.length; |
| 1386 | int numSmartActions = smartRepliesAndActions.smartActions == null |
| 1387 | ? 0 : smartRepliesAndActions.smartActions.actions.size(); |
| 1388 | boolean fromAssistant = smartRepliesAndActions.smartReplies == null |
| 1389 | ? smartRepliesAndActions.smartActions.fromAssistant |
| 1390 | : smartRepliesAndActions.smartReplies.fromAssistant; |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 1391 | boolean editBeforeSending = smartRepliesAndActions.smartReplies != null |
| 1392 | && mSmartReplyConstants.getEffectiveEditChoicesBeforeSending( |
| 1393 | smartRepliesAndActions.smartReplies.remoteInput |
| 1394 | .getEditChoicesBeforeSending()); |
| 1395 | |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 1396 | mSmartReplyController.smartSuggestionsAdded(entry, numSmartReplies, |
Milo Sredkov | 13d8811 | 2019-02-01 12:23:24 +0000 | [diff] [blame] | 1397 | numSmartActions, fromAssistant, editBeforeSending); |
Gustav Sennton | d25a64d | 2018-12-07 10:58:39 +0000 | [diff] [blame] | 1398 | } |
Kenny Guy | 2399110 | 2018-04-05 21:18:38 +0100 | [diff] [blame] | 1399 | } |
| 1400 | } |
Gustav Sennton | 3f3eaff | 2019-01-08 09:39:51 +0000 | [diff] [blame] | 1401 | if (mHeadsUpChild != null && mSmartReplyConstants.getShowInHeadsUp()) { |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1402 | mHeadsUpSmartReplyView = applySmartReplyView(mHeadsUpChild, smartRepliesAndActions, |
| 1403 | entry, mHeadsUpInflatedSmartReplies); |
Gustav Sennton | d0e8453 | 2018-12-03 16:48:36 +0000 | [diff] [blame] | 1404 | } |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1405 | } |
| 1406 | |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1407 | @Nullable |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 1408 | private SmartReplyView applySmartReplyView(View view, |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1409 | SmartRepliesAndActions smartRepliesAndActions, |
| 1410 | NotificationEntry entry, InflatedSmartReplies inflatedSmartReplyView) { |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1411 | View smartReplyContainerCandidate = view.findViewById( |
| 1412 | com.android.internal.R.id.smart_reply_container); |
| 1413 | if (!(smartReplyContainerCandidate instanceof LinearLayout)) { |
| 1414 | return null; |
| 1415 | } |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1416 | |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1417 | LinearLayout smartReplyContainer = (LinearLayout) smartReplyContainerCandidate; |
Gustav Sennton | b944ce5 | 2019-02-25 18:52:43 +0000 | [diff] [blame] | 1418 | if (!InflatedSmartReplies.shouldShowSmartReplyView(entry, smartRepliesAndActions)) { |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1419 | smartReplyContainer.setVisibility(View.GONE); |
| 1420 | return null; |
| 1421 | } |
Gustav Sennton | b944ce5 | 2019-02-25 18:52:43 +0000 | [diff] [blame] | 1422 | |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1423 | SmartReplyView smartReplyView = null; |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1424 | if (smartReplyContainer.getChildCount() == 1 |
| 1425 | && smartReplyContainer.getChildAt(0) instanceof SmartReplyView) { |
| 1426 | // If we already have a SmartReplyView - replace it with the newly inflated one. The |
| 1427 | // newly inflated one is connected to the new inflated smart reply/action buttons. |
| 1428 | smartReplyContainer.removeAllViews(); |
| 1429 | } |
| 1430 | if (smartReplyContainer.getChildCount() == 0 |
| 1431 | && inflatedSmartReplyView != null |
| 1432 | && inflatedSmartReplyView.getSmartReplyView() != null) { |
| 1433 | smartReplyView = inflatedSmartReplyView.getSmartReplyView(); |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1434 | smartReplyContainer.addView(smartReplyView); |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1435 | } |
| 1436 | if (smartReplyView != null) { |
Gustav Sennton | eab5368 | 2018-11-01 16:30:23 +0000 | [diff] [blame] | 1437 | smartReplyView.resetSmartSuggestions(smartReplyContainer); |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1438 | smartReplyView.addPreInflatedButtons( |
| 1439 | inflatedSmartReplyView.getSmartSuggestionButtons()); |
Petr Cermak | 7997d7a | 2018-01-18 15:52:10 +0000 | [diff] [blame] | 1440 | smartReplyContainer.setVisibility(View.VISIBLE); |
| 1441 | } |
| 1442 | return smartReplyView; |
| 1443 | } |
| 1444 | |
Gustav Sennton | 5759f87 | 2019-02-13 17:25:26 +0000 | [diff] [blame] | 1445 | /** |
| 1446 | * Set pre-inflated views necessary to display smart replies and actions in the expanded |
| 1447 | * notification state. |
| 1448 | * |
| 1449 | * @param inflatedSmartReplies the pre-inflated state to add to this view. If null the existing |
| 1450 | * {@link SmartReplyView} related to the expanded notification state is cleared. |
| 1451 | */ |
| 1452 | public void setExpandedInflatedSmartReplies( |
| 1453 | @Nullable InflatedSmartReplies inflatedSmartReplies) { |
| 1454 | mExpandedInflatedSmartReplies = inflatedSmartReplies; |
| 1455 | if (inflatedSmartReplies == null) { |
| 1456 | mExpandedSmartReplyView = null; |
| 1457 | } |
| 1458 | } |
| 1459 | |
| 1460 | /** |
| 1461 | * Set pre-inflated views necessary to display smart replies and actions in the heads-up |
| 1462 | * notification state. |
| 1463 | * |
| 1464 | * @param inflatedSmartReplies the pre-inflated state to add to this view. If null the existing |
| 1465 | * {@link SmartReplyView} related to the heads-up notification state is cleared. |
| 1466 | */ |
| 1467 | public void setHeadsUpInflatedSmartReplies( |
| 1468 | @Nullable InflatedSmartReplies inflatedSmartReplies) { |
| 1469 | mHeadsUpInflatedSmartReplies = inflatedSmartReplies; |
| 1470 | if (inflatedSmartReplies == null) { |
| 1471 | mHeadsUpSmartReplyView = null; |
| 1472 | } |
| 1473 | } |
| 1474 | |
Adrian Roos | 0bd8a4b | 2016-03-14 16:21:44 -0700 | [diff] [blame] | 1475 | public void closeRemoteInput() { |
| 1476 | if (mHeadsUpRemoteInput != null) { |
| 1477 | mHeadsUpRemoteInput.close(); |
| 1478 | } |
| 1479 | if (mExpandedRemoteInput != null) { |
| 1480 | mExpandedRemoteInput.close(); |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1481 | } |
| 1482 | } |
| 1483 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 1484 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 1485 | mGroupManager = groupManager; |
| 1486 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1487 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 1488 | public void setRemoteInputController(RemoteInputController r) { |
| 1489 | mRemoteInputController = r; |
| 1490 | } |
| 1491 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1492 | public void setExpandClickListener(OnClickListener expandClickListener) { |
| 1493 | mExpandClickListener = expandClickListener; |
| 1494 | } |
| 1495 | |
| 1496 | public void updateExpandButtons(boolean expandable) { |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 1497 | mExpandable = expandable; |
| 1498 | // if the expanded child has the same height as the collapsed one we hide it. |
Selim Cinek | 8ea2d5f | 2016-04-20 17:10:40 -0700 | [diff] [blame] | 1499 | if (mExpandedChild != null && mExpandedChild.getHeight() != 0) { |
Selim Cinek | 4ca6c63 | 2017-02-23 18:03:37 -0800 | [diff] [blame] | 1500 | if ((!mIsHeadsUp && !mHeadsUpAnimatingAway) |
| 1501 | || mHeadsUpChild == null || mContainingNotification.isOnKeyguard()) { |
Selim Cinek | 9635cf3 | 2017-03-03 16:59:03 -0800 | [diff] [blame] | 1502 | if (mExpandedChild.getHeight() <= mContractedChild.getHeight()) { |
Selim Cinek | 8ea2d5f | 2016-04-20 17:10:40 -0700 | [diff] [blame] | 1503 | expandable = false; |
| 1504 | } |
Selim Cinek | 9635cf3 | 2017-03-03 16:59:03 -0800 | [diff] [blame] | 1505 | } else if (mExpandedChild.getHeight() <= mHeadsUpChild.getHeight()) { |
Selim Cinek | 8ea2d5f | 2016-04-20 17:10:40 -0700 | [diff] [blame] | 1506 | expandable = false; |
| 1507 | } |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 1508 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1509 | if (mExpandedChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1510 | mExpandedWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1511 | } |
| 1512 | if (mContractedChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1513 | mContractedWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1514 | } |
| 1515 | if (mHeadsUpChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 1516 | mHeadsUpWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1517 | } |
Selim Cinek | c0ac4af | 2017-03-03 15:13:48 -0800 | [diff] [blame] | 1518 | mIsContentExpandable = expandable; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 1519 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1520 | |
| 1521 | public NotificationHeaderView getNotificationHeader() { |
| 1522 | NotificationHeaderView header = null; |
| 1523 | if (mContractedChild != null) { |
| 1524 | header = mContractedWrapper.getNotificationHeader(); |
| 1525 | } |
| 1526 | if (header == null && mExpandedChild != null) { |
| 1527 | header = mExpandedWrapper.getNotificationHeader(); |
| 1528 | } |
| 1529 | if (header == null && mHeadsUpChild != null) { |
| 1530 | header = mHeadsUpWrapper.getNotificationHeader(); |
| 1531 | } |
Adrian Roos | 0aac04f | 2016-12-08 15:59:29 -0800 | [diff] [blame] | 1532 | if (header == null && mAmbientChild != null) { |
| 1533 | header = mAmbientWrapper.getNotificationHeader(); |
| 1534 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 1535 | return header; |
| 1536 | } |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 1537 | |
Julia Reynolds | fc64001 | 2018-02-21 12:25:27 -0500 | [diff] [blame] | 1538 | public void showAppOpsIcons(ArraySet<Integer> activeOps) { |
| 1539 | if (mContractedChild != null && mContractedWrapper.getNotificationHeader() != null) { |
| 1540 | mContractedWrapper.getNotificationHeader().showAppOpsIcons(activeOps); |
| 1541 | } |
| 1542 | if (mExpandedChild != null && mExpandedWrapper.getNotificationHeader() != null) { |
| 1543 | mExpandedWrapper.getNotificationHeader().showAppOpsIcons(activeOps); |
| 1544 | } |
| 1545 | if (mHeadsUpChild != null && mHeadsUpWrapper.getNotificationHeader() != null) { |
| 1546 | mHeadsUpWrapper.getNotificationHeader().showAppOpsIcons(activeOps); |
| 1547 | } |
| 1548 | } |
Selim Cinek | b26afa3 | 2017-06-29 10:28:17 +0200 | [diff] [blame] | 1549 | |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1550 | /** Sets whether the notification being displayed audibly alerted the user. */ |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1551 | public void setRecentlyAudiblyAlerted(boolean audiblyAlerted) { |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1552 | if (mContractedChild != null && mContractedWrapper.getNotificationHeader() != null) { |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1553 | mContractedWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1554 | } |
| 1555 | if (mExpandedChild != null && mExpandedWrapper.getNotificationHeader() != null) { |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1556 | mExpandedWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1557 | } |
| 1558 | if (mHeadsUpChild != null && mHeadsUpWrapper.getNotificationHeader() != null) { |
Gus Prevas | 7306b90 | 2018-12-11 10:57:06 -0500 | [diff] [blame] | 1559 | mHeadsUpWrapper.getNotificationHeader().setRecentlyAudiblyAlerted(audiblyAlerted); |
Gus Prevas | a322649 | 2018-10-23 11:10:09 -0400 | [diff] [blame] | 1560 | } |
| 1561 | } |
| 1562 | |
Selim Cinek | b26afa3 | 2017-06-29 10:28:17 +0200 | [diff] [blame] | 1563 | public NotificationHeaderView getContractedNotificationHeader() { |
| 1564 | if (mContractedChild != null) { |
| 1565 | return mContractedWrapper.getNotificationHeader(); |
| 1566 | } |
| 1567 | return null; |
| 1568 | } |
| 1569 | |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 1570 | public NotificationHeaderView getVisibleNotificationHeader() { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1571 | NotificationViewWrapper wrapper = getVisibleWrapper(mVisibleType); |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 1572 | return wrapper == null ? null : wrapper.getNotificationHeader(); |
| 1573 | } |
| 1574 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 1575 | public void setContainingNotification(ExpandableNotificationRow containingNotification) { |
| 1576 | mContainingNotification = containingNotification; |
| 1577 | } |
| 1578 | |
| 1579 | public void requestSelectLayout(boolean needsAnimation) { |
| 1580 | selectLayout(needsAnimation, false); |
| 1581 | } |
Selim Cinek | de33a4a | 2016-02-11 16:43:41 -0800 | [diff] [blame] | 1582 | |
| 1583 | public void reInflateViews() { |
| 1584 | if (mIsChildInGroup && mSingleLineView != null) { |
| 1585 | removeView(mSingleLineView); |
| 1586 | mSingleLineView = null; |
Adrian Roos | 6f6e159 | 2017-05-02 16:22:53 -0700 | [diff] [blame] | 1587 | updateAllSingleLineViews(); |
Selim Cinek | de33a4a | 2016-02-11 16:43:41 -0800 | [diff] [blame] | 1588 | } |
| 1589 | } |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1590 | |
| 1591 | public void setUserExpanding(boolean userExpanding) { |
| 1592 | mUserExpanding = userExpanding; |
| 1593 | if (userExpanding) { |
| 1594 | mTransformationStartVisibleType = mVisibleType; |
| 1595 | } else { |
| 1596 | mTransformationStartVisibleType = UNDEFINED; |
| 1597 | mVisibleType = calculateVisibleType(); |
| 1598 | updateViewVisibilities(mVisibleType); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1599 | updateBackgroundColor(false); |
Selim Cinek | 8f2f6a6 | 2016-02-23 19:56:31 -0800 | [diff] [blame] | 1600 | } |
| 1601 | } |
Selim Cinek | c897bd3 | 2016-03-18 17:32:31 -0700 | [diff] [blame] | 1602 | |
| 1603 | /** |
| 1604 | * Set by how much the single line view should be indented. Used when a overflow indicator is |
| 1605 | * present and only during measuring |
| 1606 | */ |
| 1607 | public void setSingleLineWidthIndention(int singleLineWidthIndention) { |
| 1608 | if (singleLineWidthIndention != mSingleLineWidthIndention) { |
| 1609 | mSingleLineWidthIndention = singleLineWidthIndention; |
| 1610 | mContainingNotification.forceLayout(); |
| 1611 | forceLayout(); |
| 1612 | } |
| 1613 | } |
| 1614 | |
| 1615 | public HybridNotificationView getSingleLineView() { |
| 1616 | return mSingleLineView; |
| 1617 | } |
Adrian Roos | d009ab1 | 2016-05-20 17:58:53 -0700 | [diff] [blame] | 1618 | |
| 1619 | public void setRemoved() { |
| 1620 | if (mExpandedRemoteInput != null) { |
| 1621 | mExpandedRemoteInput.setRemoved(); |
| 1622 | } |
| 1623 | if (mHeadsUpRemoteInput != null) { |
| 1624 | mHeadsUpRemoteInput.setRemoved(); |
| 1625 | } |
| 1626 | } |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 1627 | |
| 1628 | public void setContentHeightAnimating(boolean animating) { |
| 1629 | if (!animating) { |
| 1630 | mContentHeightAtAnimationStart = UNDEFINED; |
| 1631 | } |
| 1632 | } |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1633 | |
Adrian Roos | e18033c | 2017-01-17 15:22:49 -0800 | [diff] [blame] | 1634 | @VisibleForTesting |
| 1635 | boolean isAnimatingVisibleType() { |
| 1636 | return mAnimationStartVisibleType != UNDEFINED; |
| 1637 | } |
| 1638 | |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 1639 | public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) { |
| 1640 | mHeadsUpAnimatingAway = headsUpAnimatingAway; |
Selim Cinek | 73cf02a | 2016-06-17 13:08:00 -0700 | [diff] [blame] | 1641 | selectLayout(false /* animate */, true /* force */); |
| 1642 | } |
| 1643 | |
Selim Cinek | e9bad24 | 2016-06-15 11:46:37 -0700 | [diff] [blame] | 1644 | public void setFocusOnVisibilityChange() { |
| 1645 | mFocusOnVisibilityChange = true; |
| 1646 | } |
Selim Cinek | 0242fbb | 2016-10-19 13:38:32 -0700 | [diff] [blame] | 1647 | |
| 1648 | public void setIconsVisible(boolean iconsVisible) { |
| 1649 | mIconsVisible = iconsVisible; |
| 1650 | updateIconVisibilities(); |
| 1651 | } |
| 1652 | |
| 1653 | private void updateIconVisibilities() { |
| 1654 | if (mContractedWrapper != null) { |
| 1655 | NotificationHeaderView header = mContractedWrapper.getNotificationHeader(); |
| 1656 | if (header != null) { |
| 1657 | header.getIcon().setForceHidden(!mIconsVisible); |
| 1658 | } |
| 1659 | } |
| 1660 | if (mHeadsUpWrapper != null) { |
| 1661 | NotificationHeaderView header = mHeadsUpWrapper.getNotificationHeader(); |
| 1662 | if (header != null) { |
| 1663 | header.getIcon().setForceHidden(!mIconsVisible); |
| 1664 | } |
| 1665 | } |
| 1666 | if (mExpandedWrapper != null) { |
| 1667 | NotificationHeaderView header = mExpandedWrapper.getNotificationHeader(); |
| 1668 | if (header != null) { |
| 1669 | header.getIcon().setForceHidden(!mIconsVisible); |
| 1670 | } |
| 1671 | } |
| 1672 | } |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1673 | |
Adrian Roos | 4320e89 | 2017-01-24 12:50:34 -0800 | [diff] [blame] | 1674 | @Override |
| 1675 | public void onVisibilityAggregated(boolean isVisible) { |
| 1676 | super.onVisibilityAggregated(isVisible); |
| 1677 | if (isVisible) { |
| 1678 | fireExpandedVisibleListenerIfVisible(); |
| 1679 | } |
| 1680 | } |
| 1681 | |
| 1682 | /** |
| 1683 | * Sets a one-shot listener for when the expanded view becomes visible. |
| 1684 | * |
| 1685 | * This will fire the listener immediately if the expanded view is already visible. |
| 1686 | */ |
| 1687 | public void setOnExpandedVisibleListener(Runnable r) { |
| 1688 | mExpandedVisibleListener = r; |
| 1689 | fireExpandedVisibleListenerIfVisible(); |
| 1690 | } |
| 1691 | |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 1692 | /** |
| 1693 | * Set a one-shot listener to run when a given content view becomes inactive. |
| 1694 | * |
| 1695 | * @param visibleType visible type corresponding to the content view to listen |
| 1696 | * @param listener runnable to run once when the content view becomes inactive |
| 1697 | */ |
| 1698 | public void performWhenContentInactive(int visibleType, Runnable listener) { |
| 1699 | View view = getViewForVisibleType(visibleType); |
| 1700 | // View is already inactive |
| 1701 | if (view == null || isContentViewInactive(visibleType)) { |
| 1702 | listener.run(); |
| 1703 | return; |
| 1704 | } |
| 1705 | mOnContentViewInactiveListeners.put(view, listener); |
| 1706 | } |
| 1707 | |
| 1708 | /** |
| 1709 | * Whether or not the content view is inactive. This means it should not be visible |
| 1710 | * or the showing content as removing it would cause visual jank. |
| 1711 | * |
| 1712 | * @param visibleType visible type corresponding to the content view to be removed |
| 1713 | * @return true if the content view is inactive, false otherwise |
| 1714 | */ |
| 1715 | public boolean isContentViewInactive(int visibleType) { |
| 1716 | View view = getViewForVisibleType(visibleType); |
| 1717 | return isContentViewInactive(view); |
| 1718 | } |
| 1719 | |
| 1720 | /** |
| 1721 | * Whether or not the content view is inactive. |
| 1722 | * |
| 1723 | * @param view view to see if its inactive |
| 1724 | * @return true if the view is inactive, false o/w |
| 1725 | */ |
| 1726 | private boolean isContentViewInactive(View view) { |
| 1727 | if (view == null) { |
| 1728 | return true; |
| 1729 | } |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 1730 | return !isShown() |
| 1731 | || (view.getVisibility() != VISIBLE && getViewForVisibleType(mVisibleType) != view); |
Kevin | d5022f9 | 2018-10-08 18:30:26 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
| 1734 | @Override |
| 1735 | protected void onChildVisibilityChanged(View child, int oldVisibility, int newVisibility) { |
| 1736 | super.onChildVisibilityChanged(child, oldVisibility, newVisibility); |
| 1737 | if (isContentViewInactive(child)) { |
| 1738 | Runnable listener = mOnContentViewInactiveListeners.remove(child); |
| 1739 | if (listener != null) { |
| 1740 | listener.run(); |
| 1741 | } |
| 1742 | } |
| 1743 | } |
| 1744 | |
Selim Cinek | 6743c0b | 2017-01-18 18:24:01 -0800 | [diff] [blame] | 1745 | public void setIsLowPriority(boolean isLowPriority) { |
| 1746 | mIsLowPriority = isLowPriority; |
| 1747 | } |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 1748 | |
| 1749 | public boolean isDimmable() { |
Kevin | 38ce6fa | 2018-10-17 16:00:14 -0700 | [diff] [blame] | 1750 | return mContractedWrapper != null && mContractedWrapper.isDimmable(); |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 1751 | } |
Selim Cinek | 5d6ef8d | 2017-05-18 22:16:00 -0700 | [diff] [blame] | 1752 | |
| 1753 | /** |
| 1754 | * Should a single click be disallowed on this view when on the keyguard? |
| 1755 | */ |
| 1756 | public boolean disallowSingleClick(float x, float y) { |
| 1757 | NotificationViewWrapper visibleWrapper = getVisibleWrapper(getVisibleType()); |
| 1758 | if (visibleWrapper != null) { |
| 1759 | return visibleWrapper.disallowSingleClick(x, y); |
| 1760 | } |
| 1761 | return false; |
| 1762 | } |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 1763 | |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 1764 | public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) { |
| 1765 | boolean needsPaddings = shouldClipToRounding(getVisibleType(), topRounded, bottomRounded); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 1766 | if (mUserExpanding) { |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 1767 | needsPaddings |= shouldClipToRounding(mTransformationStartVisibleType, topRounded, |
| 1768 | bottomRounded); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 1769 | } |
| 1770 | return needsPaddings; |
| 1771 | } |
| 1772 | |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 1773 | private boolean shouldClipToRounding(int visibleType, boolean topRounded, |
| 1774 | boolean bottomRounded) { |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 1775 | NotificationViewWrapper visibleWrapper = getVisibleWrapper(visibleType); |
| 1776 | if (visibleWrapper == null) { |
| 1777 | return false; |
| 1778 | } |
Selim Cinek | 86bfcee | 2018-01-17 11:00:47 -0800 | [diff] [blame] | 1779 | return visibleWrapper.shouldClipToRounding(topRounded, bottomRounded); |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 1780 | } |
Selim Cinek | de4de0e | 2018-01-24 16:21:07 -0800 | [diff] [blame] | 1781 | |
| 1782 | public CharSequence getActiveRemoteInputText() { |
| 1783 | if (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive()) { |
| 1784 | return mExpandedRemoteInput.getText(); |
| 1785 | } |
| 1786 | if (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive()) { |
| 1787 | return mHeadsUpRemoteInput.getText(); |
| 1788 | } |
| 1789 | return null; |
| 1790 | } |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1791 | |
Selim Cinek | a77d2c5 | 2018-04-09 10:44:52 -0700 | [diff] [blame] | 1792 | @Override |
| 1793 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 1794 | float y = ev.getY(); |
| 1795 | // We still want to distribute touch events to the remote input even if it's outside the |
| 1796 | // view boundary. We're therefore manually dispatching these events to the remote view |
| 1797 | RemoteInputView riv = getRemoteInputForView(getViewForVisibleType(mVisibleType)); |
| 1798 | if (riv != null && riv.getVisibility() == VISIBLE) { |
| 1799 | int inputStart = mUnrestrictedContentHeight - riv.getHeight(); |
| 1800 | if (y <= mUnrestrictedContentHeight && y >= inputStart) { |
| 1801 | ev.offsetLocation(0, -inputStart); |
| 1802 | return riv.dispatchTouchEvent(ev); |
| 1803 | } |
| 1804 | } |
| 1805 | return super.dispatchTouchEvent(ev); |
| 1806 | } |
| 1807 | |
| 1808 | /** |
| 1809 | * Overridden to make sure touches to the reply action bar actually go through to this view |
| 1810 | */ |
| 1811 | @Override |
| 1812 | public boolean pointInView(float localX, float localY, float slop) { |
| 1813 | float top = mClipTopAmount; |
| 1814 | float bottom = mUnrestrictedContentHeight; |
| 1815 | return localX >= -slop && localY >= top - slop && localX < ((mRight - mLeft) + slop) && |
| 1816 | localY < (bottom + slop); |
| 1817 | } |
| 1818 | |
| 1819 | private RemoteInputView getRemoteInputForView(View child) { |
| 1820 | if (child == mExpandedChild) { |
| 1821 | return mExpandedRemoteInput; |
| 1822 | } else if (child == mHeadsUpChild) { |
| 1823 | return mHeadsUpRemoteInput; |
| 1824 | } |
| 1825 | return null; |
| 1826 | } |
| 1827 | |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1828 | public int getExpandHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1829 | int viewType = VISIBLE_TYPE_EXPANDED; |
| 1830 | if (mExpandedChild == null) { |
| 1831 | viewType = VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1832 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1833 | return getViewHeight(viewType) + getExtraRemoteInputHeight(mExpandedRemoteInput); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1834 | } |
| 1835 | |
| 1836 | public int getHeadsUpHeight() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1837 | int viewType = VISIBLE_TYPE_HEADSUP; |
| 1838 | if (mHeadsUpChild == null) { |
| 1839 | viewType = VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1840 | } |
Selim Cinek | 09b442e | 2018-05-04 15:46:18 -0700 | [diff] [blame] | 1841 | // The headsUp remote input quickly switches to the expanded one, so lets also include that |
| 1842 | // one |
| 1843 | return getViewHeight(viewType) + getExtraRemoteInputHeight(mHeadsUpRemoteInput) |
| 1844 | + getExtraRemoteInputHeight(mExpandedRemoteInput); |
Selim Cinek | ed64a14 | 2018-02-06 18:06:01 -0800 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | public void setRemoteInputVisible(boolean remoteInputVisible) { |
| 1848 | mRemoteInputVisible = remoteInputVisible; |
| 1849 | setClipChildren(!remoteInputVisible); |
| 1850 | } |
| 1851 | |
| 1852 | @Override |
| 1853 | public void setClipChildren(boolean clipChildren) { |
| 1854 | clipChildren = clipChildren && !mRemoteInputVisible; |
| 1855 | super.setClipChildren(clipChildren); |
| 1856 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1857 | |
| 1858 | public void setHeaderVisibleAmount(float headerVisibleAmount) { |
| 1859 | if (mContractedWrapper != null) { |
| 1860 | mContractedWrapper.setHeaderVisibleAmount(headerVisibleAmount); |
| 1861 | } |
| 1862 | if (mHeadsUpWrapper != null) { |
| 1863 | mHeadsUpWrapper.setHeaderVisibleAmount(headerVisibleAmount); |
| 1864 | } |
| 1865 | if (mExpandedWrapper != null) { |
| 1866 | mExpandedWrapper.setHeaderVisibleAmount(headerVisibleAmount); |
| 1867 | } |
| 1868 | } |
Selim Cinek | 85a8f9f | 2018-11-21 13:58:27 -0800 | [diff] [blame] | 1869 | |
| 1870 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 1871 | pw.print(" "); |
| 1872 | pw.print("contentView visibility: " + getVisibility()); |
| 1873 | pw.print(", alpha: " + getAlpha()); |
| 1874 | pw.print(", clipBounds: " + getClipBounds()); |
| 1875 | pw.print(", contentHeight: " + mContentHeight); |
| 1876 | pw.print(", visibleType: " + mVisibleType); |
| 1877 | View view = getViewForVisibleType(mVisibleType); |
| 1878 | pw.print(", visibleView "); |
| 1879 | if (view != null) { |
| 1880 | pw.print(" visibility: " + view.getVisibility()); |
| 1881 | pw.print(", alpha: " + view.getAlpha()); |
| 1882 | pw.print(", clipBounds: " + view.getClipBounds()); |
| 1883 | } else { |
| 1884 | pw.print("null"); |
| 1885 | } |
| 1886 | pw.println(); |
| 1887 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 1888 | } |