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