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