blob: 8030bde2553b8c8d824faa73e165a82279766e96 [file] [log] [blame]
Jorim Jaggibe565df2014-04-28 17:51:23 +02001/*
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
17package com.android.systemui.statusbar;
18
Adrian Roosb88b1a12015-12-09 18:51:05 -080019import android.app.Notification;
Adrian Roos4c1fcc82016-03-31 14:39:39 -070020import android.app.PendingIntent;
Adrian Roosb88b1a12015-12-09 18:51:05 -080021import android.app.RemoteInput;
Jorim Jaggibe565df2014-04-28 17:51:23 +020022import android.content.Context;
23import android.graphics.Rect;
Selim Cinek860b6da2015-12-16 19:02:19 -080024import android.os.Build;
Selim Cinek83bc7832015-10-22 13:26:54 -070025import android.service.notification.StatusBarNotification;
Julia Reynoldsfc640012018-02-21 12:25:27 -050026import android.util.ArraySet;
Jorim Jaggibe565df2014-04-28 17:51:23 +020027import android.util.AttributeSet;
Selim Cinek011bde92017-11-22 05:53:38 -080028import android.util.Log;
Selim Cineka77d2c52018-04-09 10:44:52 -070029import android.view.MotionEvent;
Selim Cinekeaa29ca2015-11-23 13:51:13 -080030import android.view.NotificationHeaderView;
Jorim Jaggibe565df2014-04-28 17:51:23 +020031import android.view.View;
Selim Cinek8d490d42015-04-10 00:05:50 -070032import android.view.ViewGroup;
Selim Cinekbb3d1cf2014-10-31 00:12:56 +010033import android.view.ViewTreeObserver;
Selim Cinekc9c00ae2014-05-20 03:33:40 +020034import android.widget.FrameLayout;
Selim Cineke9bad242016-06-15 11:46:37 -070035import android.widget.ImageView;
Petr Cermak7997d7a2018-01-18 15:52:10 +000036import android.widget.LinearLayout;
Selim Cinek8d490d42015-04-10 00:05:50 -070037
Adrian Roose18033c2017-01-17 15:22:49 -080038import com.android.internal.annotations.VisibleForTesting;
Adrian Roos4ff3b122016-02-01 12:26:13 -080039import com.android.internal.util.NotificationColorUtil;
Petr Cermak10011fa2018-02-05 19:00:54 +000040import com.android.systemui.Dependency;
Jorim Jaggibe565df2014-04-28 17:51:23 +020041import com.android.systemui.R;
Selim Cinekc897bd32016-03-18 17:32:31 -070042import com.android.systemui.statusbar.notification.HybridGroupManager;
Selim Cinek011bde92017-11-22 05:53:38 -080043import com.android.systemui.statusbar.notification.HybridNotificationView;
Selim Cinek0ffbda62016-01-01 20:29:12 +010044import com.android.systemui.statusbar.notification.NotificationCustomViewWrapper;
Selim Cinekc3179332016-03-04 14:44:56 -080045import com.android.systemui.statusbar.notification.NotificationUtils;
Selim Cinek0ffbda62016-01-01 20:29:12 +010046import com.android.systemui.statusbar.notification.NotificationViewWrapper;
Selim Cinek83bc7832015-10-22 13:26:54 -070047import com.android.systemui.statusbar.phone.NotificationGroupManager;
Adrian Roosb88b1a12015-12-09 18:51:05 -080048import com.android.systemui.statusbar.policy.RemoteInputView;
Petr Cermak10011fa2018-02-05 19:00:54 +000049import com.android.systemui.statusbar.policy.SmartReplyConstants;
Petr Cermak7997d7a2018-01-18 15:52:10 +000050import com.android.systemui.statusbar.policy.SmartReplyView;
Jorim Jaggibe565df2014-04-28 17:51:23 +020051
52/**
Selim Cinek684a4422015-04-15 16:18:39 -070053 * A frame layout containing the actual payload of the notification, including the contracted,
54 * expanded and heads up layout. This class is responsible for clipping the content and and
55 * switching between the expanded, contracted and the heads up view depending on its clipped size.
Jorim Jaggibe565df2014-04-28 17:51:23 +020056 */
Selim Cinekc9c00ae2014-05-20 03:33:40 +020057public class NotificationContentView extends FrameLayout {
Jorim Jaggibe565df2014-04-28 17:51:23 +020058
Selim Cinek011bde92017-11-22 05:53:38 -080059 private static final String TAG = "NotificationContentView";
Selim Cinek131f1a42017-06-05 17:50:19 -070060 public static final int VISIBLE_TYPE_CONTRACTED = 0;
61 public static final int VISIBLE_TYPE_EXPANDED = 1;
62 public static final int VISIBLE_TYPE_HEADSUP = 2;
Selim Cinek83bc7832015-10-22 13:26:54 -070063 private static final int VISIBLE_TYPE_SINGLELINE = 3;
Selim Cinek131f1a42017-06-05 17:50:19 -070064 public static final int VISIBLE_TYPE_AMBIENT = 4;
Adrian Roos6f6e1592017-05-02 16:22:53 -070065 private static final int VISIBLE_TYPE_AMBIENT_SINGLELINE = 5;
Selim Cinekc3179332016-03-04 14:44:56 -080066 public static final int UNDEFINED = -1;
Jorim Jaggi11298832014-05-24 16:18:38 +020067
Jorim Jaggibe565df2014-04-28 17:51:23 +020068 private final Rect mClipBounds = new Rect();
69
Selim Cinek9b49f6d2017-11-13 18:19:35 -080070 private int mMinContractedHeight;
71 private int mNotificationContentMarginEnd;
Jorim Jaggibe565df2014-04-28 17:51:23 +020072 private View mContractedChild;
73 private View mExpandedChild;
Selim Cinek8d490d42015-04-10 00:05:50 -070074 private View mHeadsUpChild;
Selim Cinek83bc7832015-10-22 13:26:54 -070075 private HybridNotificationView mSingleLineView;
Adrian Roos0aac04f2016-12-08 15:59:29 -080076 private View mAmbientChild;
Adrian Roos6f6e1592017-05-02 16:22:53 -070077 private HybridNotificationView mAmbientSingleLineChild;
Jorim Jaggibe565df2014-04-28 17:51:23 +020078
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070079 private RemoteInputView mExpandedRemoteInput;
80 private RemoteInputView mHeadsUpRemoteInput;
Petr Cermak10011fa2018-02-05 19:00:54 +000081
82 private SmartReplyConstants mSmartReplyConstants;
Milo Sredkove7cf4982018-04-09 15:08:26 +010083 private SmartReplyView mExpandedSmartReplyView;
Kenny Guy23991102018-04-05 21:18:38 +010084 private SmartReplyLogger mSmartReplyLogger;
Adrian Roos0bd8a4b2016-03-14 16:21:44 -070085
Jorim Jaggi4e857f42014-11-17 19:14:04 +010086 private NotificationViewWrapper mContractedWrapper;
Jorim Jaggibe4116a2015-05-20 20:04:08 -070087 private NotificationViewWrapper mExpandedWrapper;
88 private NotificationViewWrapper mHeadsUpWrapper;
Adrian Roos0aac04f2016-12-08 15:59:29 -080089 private NotificationViewWrapper mAmbientWrapper;
Selim Cinekc897bd32016-03-18 17:32:31 -070090 private HybridGroupManager mHybridGroupManager;
Selim Cinekc9c00ae2014-05-20 03:33:40 +020091 private int mClipTopAmount;
Selim Cinekb5605e52015-02-20 18:21:41 +010092 private int mContentHeight;
Selim Cinek684a4422015-04-15 16:18:39 -070093 private int mVisibleType = VISIBLE_TYPE_CONTRACTED;
John Spurlocke15452b2014-08-21 09:44:39 -040094 private boolean mDark;
Selim Cinekbb3d1cf2014-10-31 00:12:56 +010095 private boolean mAnimate;
Selim Cinek684a4422015-04-15 16:18:39 -070096 private boolean mIsHeadsUp;
Selim Cinek1a48bab2017-02-17 19:38:40 -080097 private boolean mLegacy;
Selim Cinek83bc7832015-10-22 13:26:54 -070098 private boolean mIsChildInGroup;
Selim Cinek816c8e42015-11-19 12:00:45 -080099 private int mSmallHeight;
Selim Cinek77019c72015-12-09 10:18:02 -0800100 private int mHeadsUpHeight;
Selim Cinekd84a5932015-12-15 11:45:36 -0800101 private int mNotificationMaxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800102 private int mNotificationAmbientHeight;
Selim Cinek83bc7832015-10-22 13:26:54 -0700103 private StatusBarNotification mStatusBarNotification;
Selim Cinek65b2e7c2015-10-26 14:11:31 -0700104 private NotificationGroupManager mGroupManager;
Adrian Roosb88b1a12015-12-09 18:51:05 -0800105 private RemoteInputController mRemoteInputController;
Adrian Roos4320e892017-01-24 12:50:34 -0800106 private Runnable mExpandedVisibleListener;
Jorim Jaggi59ec3042015-06-05 15:18:43 -0700107
Jorim Jaggibe4116a2015-05-20 20:04:08 -0700108 private final ViewTreeObserver.OnPreDrawListener mEnableAnimationPredrawListener
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100109 = new ViewTreeObserver.OnPreDrawListener() {
110 @Override
111 public boolean onPreDraw() {
Selim Cinekd1ad9ab2016-03-01 17:52:20 -0800112 // We need to post since we don't want the notification to animate on the very first
113 // frame
114 post(new Runnable() {
115 @Override
116 public void run() {
117 mAnimate = true;
118 }
119 });
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100120 getViewTreeObserver().removeOnPreDrawListener(this);
121 return true;
122 }
123 };
Jorim Jaggi11298832014-05-24 16:18:38 +0200124
Selim Cinekeaa29ca2015-11-23 13:51:13 -0800125 private OnClickListener mExpandClickListener;
Selim Cinek860b6da2015-12-16 19:02:19 -0800126 private boolean mBeforeN;
Selim Cinek98be3f32015-12-17 16:39:06 -0800127 private boolean mExpandable;
Selim Cinek4ffd6362015-12-29 15:12:23 +0100128 private boolean mClipToActualHeight = true;
Selim Cinekfa0a2d32016-01-14 13:02:21 -0800129 private ExpandableNotificationRow mContainingNotification;
Adrian Roos599be342016-06-13 14:54:39 -0700130 /** The visible type at the start of a touch driven transformation */
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800131 private int mTransformationStartVisibleType;
Adrian Roos599be342016-06-13 14:54:39 -0700132 /** The visible type at the start of an animation driven transformation */
133 private int mAnimationStartVisibleType = UNDEFINED;
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800134 private boolean mUserExpanding;
Selim Cinekc897bd32016-03-18 17:32:31 -0700135 private int mSingleLineWidthIndention;
Selim Cinek589fd3e2016-04-26 18:17:57 -0700136 private boolean mForceSelectNextLayout = true;
Adrian Roos4c1fcc82016-03-31 14:39:39 -0700137 private PendingIntent mPreviousExpandedRemoteInputIntent;
138 private PendingIntent mPreviousHeadsUpRemoteInputIntent;
Adrian Roos7813dd72016-09-23 17:12:17 -0700139 private RemoteInputView mCachedExpandedRemoteInput;
140 private RemoteInputView mCachedHeadsUpRemoteInput;
Selim Cinek98be3f32015-12-17 16:39:06 -0800141
Adrian Roos599be342016-06-13 14:54:39 -0700142 private int mContentHeightAtAnimationStart = UNDEFINED;
Selim Cineke9bad242016-06-15 11:46:37 -0700143 private boolean mFocusOnVisibilityChange;
Selim Cinekcafa87f2016-10-26 17:00:17 -0700144 private boolean mHeadsUpAnimatingAway;
Selim Cinek0242fbb2016-10-19 13:38:32 -0700145 private boolean mIconsVisible;
Selim Cineka686b2c2016-10-26 13:58:27 -0700146 private int mClipBottomAmount;
Selim Cinek6743c0b2017-01-18 18:24:01 -0800147 private boolean mIsLowPriority;
Selim Cinekc0ac4af2017-03-03 15:13:48 -0800148 private boolean mIsContentExpandable;
Selim Cineked64a142018-02-06 18:06:01 -0800149 private boolean mRemoteInputVisible;
150 private int mUnrestrictedContentHeight;
Adrian Roos599be342016-06-13 14:54:39 -0700151
152
Jorim Jaggibe565df2014-04-28 17:51:23 +0200153 public NotificationContentView(Context context, AttributeSet attrs) {
154 super(context, attrs);
Selim Cinekc897bd32016-03-18 17:32:31 -0700155 mHybridGroupManager = new HybridGroupManager(getContext(), this);
Petr Cermak10011fa2018-02-05 19:00:54 +0000156 mSmartReplyConstants = Dependency.get(SmartReplyConstants.class);
Kenny Guy23991102018-04-05 21:18:38 +0100157 mSmartReplyLogger = Dependency.get(SmartReplyLogger.class);
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800158 initView();
159 }
160
161 public void initView() {
Selim Cinek860b6da2015-12-16 19:02:19 -0800162 mMinContractedHeight = getResources().getDimensionPixelSize(
163 R.dimen.min_notification_layout_height);
Selim Cinek6ecc8102016-01-26 18:26:19 -0800164 mNotificationContentMarginEnd = getResources().getDimensionPixelSize(
165 com.android.internal.R.dimen.notification_content_margin_end);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200166 }
167
Adrian Roos0aac04f2016-12-08 15:59:29 -0800168 public void setHeights(int smallHeight, int headsUpMaxHeight, int maxHeight,
169 int ambientHeight) {
Selim Cinek816c8e42015-11-19 12:00:45 -0800170 mSmallHeight = smallHeight;
Selim Cinek77019c72015-12-09 10:18:02 -0800171 mHeadsUpHeight = headsUpMaxHeight;
Selim Cinekd84a5932015-12-15 11:45:36 -0800172 mNotificationMaxHeight = maxHeight;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800173 mNotificationAmbientHeight = ambientHeight;
Selim Cinek816c8e42015-11-19 12:00:45 -0800174 }
175
Jorim Jaggibe565df2014-04-28 17:51:23 +0200176 @Override
Selim Cinek8d490d42015-04-10 00:05:50 -0700177 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
178 int heightMode = MeasureSpec.getMode(heightMeasureSpec);
179 boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY;
180 boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST;
181 int maxSize = Integer.MAX_VALUE;
Selim Cinekc897bd32016-03-18 17:32:31 -0700182 int width = MeasureSpec.getSize(widthMeasureSpec);
Selim Cinek8d490d42015-04-10 00:05:50 -0700183 if (hasFixedHeight || isHeightLimited) {
184 maxSize = MeasureSpec.getSize(heightMeasureSpec);
185 }
186 int maxChildHeight = 0;
Selim Cinek6ecc8102016-01-26 18:26:19 -0800187 if (mExpandedChild != null) {
Milo Sredkove7cf4982018-04-09 15:08:26 +0100188 int notificationMaxHeight = mNotificationMaxHeight;
189 if (mExpandedSmartReplyView != null) {
190 notificationMaxHeight += mExpandedSmartReplyView.getHeightUpperLimit();
191 }
192 int size = Math.min(maxSize, notificationMaxHeight);
Selim Cinek6ecc8102016-01-26 18:26:19 -0800193 ViewGroup.LayoutParams layoutParams = mExpandedChild.getLayoutParams();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800194 boolean useExactly = false;
Selim Cinek6ecc8102016-01-26 18:26:19 -0800195 if (layoutParams.height >= 0) {
196 // An actual height is set
197 size = Math.min(maxSize, layoutParams.height);
Selim Cinek6743c0b2017-01-18 18:24:01 -0800198 useExactly = true;
Selim Cinek6ecc8102016-01-26 18:26:19 -0800199 }
200 int spec = size == Integer.MAX_VALUE
201 ? MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)
Selim Cinek6743c0b2017-01-18 18:24:01 -0800202 : MeasureSpec.makeMeasureSpec(size, useExactly
203 ? MeasureSpec.EXACTLY
204 : MeasureSpec.AT_MOST);
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800205 measureChildWithMargins(mExpandedChild, widthMeasureSpec, 0, spec, 0);
Selim Cinek6ecc8102016-01-26 18:26:19 -0800206 maxChildHeight = Math.max(maxChildHeight, mExpandedChild.getMeasuredHeight());
207 }
Selim Cinek8d490d42015-04-10 00:05:50 -0700208 if (mContractedChild != null) {
Selim Cinek860b6da2015-12-16 19:02:19 -0800209 int heightSpec;
Selim Cinekf619ffc2016-02-17 14:53:05 -0800210 int size = Math.min(maxSize, mSmallHeight);
Selim Cinek6743c0b2017-01-18 18:24:01 -0800211 ViewGroup.LayoutParams layoutParams = mContractedChild.getLayoutParams();
212 boolean useExactly = false;
213 if (layoutParams.height >= 0) {
214 // An actual height is set
215 size = Math.min(size, layoutParams.height);
216 useExactly = true;
217 }
218 if (shouldContractedBeFixedSize() || useExactly) {
Selim Cinek860b6da2015-12-16 19:02:19 -0800219 heightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY);
220 } else {
Selim Cinekf619ffc2016-02-17 14:53:05 -0800221 heightSpec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST);
Selim Cinek860b6da2015-12-16 19:02:19 -0800222 }
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800223 measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0);
Selim Cinek860b6da2015-12-16 19:02:19 -0800224 int measuredHeight = mContractedChild.getMeasuredHeight();
225 if (measuredHeight < mMinContractedHeight) {
226 heightSpec = MeasureSpec.makeMeasureSpec(mMinContractedHeight, MeasureSpec.EXACTLY);
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800227 measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0);
Selim Cinek860b6da2015-12-16 19:02:19 -0800228 }
229 maxChildHeight = Math.max(maxChildHeight, measuredHeight);
Selim Cinek6ecc8102016-01-26 18:26:19 -0800230 if (updateContractedHeaderWidth()) {
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800231 measureChildWithMargins(mContractedChild, widthMeasureSpec, 0, heightSpec, 0);
Selim Cinek8d490d42015-04-10 00:05:50 -0700232 }
Selim Cinek1ba41d12016-04-21 16:14:46 -0700233 if (mExpandedChild != null
234 && mContractedChild.getMeasuredHeight() > mExpandedChild.getMeasuredHeight()) {
235 // the Expanded child is smaller then the collapsed. Let's remeasure it.
236 heightSpec = MeasureSpec.makeMeasureSpec(mContractedChild.getMeasuredHeight(),
237 MeasureSpec.EXACTLY);
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800238 measureChildWithMargins(mExpandedChild, widthMeasureSpec, 0, heightSpec, 0);
Selim Cinek1ba41d12016-04-21 16:14:46 -0700239 }
Selim Cinek8d490d42015-04-10 00:05:50 -0700240 }
241 if (mHeadsUpChild != null) {
242 int size = Math.min(maxSize, mHeadsUpHeight);
243 ViewGroup.LayoutParams layoutParams = mHeadsUpChild.getLayoutParams();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800244 boolean useExactly = false;
Selim Cinek8d490d42015-04-10 00:05:50 -0700245 if (layoutParams.height >= 0) {
246 // An actual height is set
Selim Cinek77019c72015-12-09 10:18:02 -0800247 size = Math.min(size, layoutParams.height);
Selim Cinek6743c0b2017-01-18 18:24:01 -0800248 useExactly = true;
Selim Cinek8d490d42015-04-10 00:05:50 -0700249 }
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800250 measureChildWithMargins(mHeadsUpChild, widthMeasureSpec, 0,
Selim Cinek6743c0b2017-01-18 18:24:01 -0800251 MeasureSpec.makeMeasureSpec(size, useExactly ? MeasureSpec.EXACTLY
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800252 : MeasureSpec.AT_MOST), 0);
Selim Cinek8d490d42015-04-10 00:05:50 -0700253 maxChildHeight = Math.max(maxChildHeight, mHeadsUpChild.getMeasuredHeight());
254 }
Selim Cinek83bc7832015-10-22 13:26:54 -0700255 if (mSingleLineView != null) {
Selim Cinekc897bd32016-03-18 17:32:31 -0700256 int singleLineWidthSpec = widthMeasureSpec;
257 if (mSingleLineWidthIndention != 0
258 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED) {
259 singleLineWidthSpec = MeasureSpec.makeMeasureSpec(
260 width - mSingleLineWidthIndention + mSingleLineView.getPaddingEnd(),
Selim Cinek09b7dea2016-08-30 11:28:19 -0700261 MeasureSpec.EXACTLY);
Selim Cinekc897bd32016-03-18 17:32:31 -0700262 }
263 mSingleLineView.measure(singleLineWidthSpec,
Selim Cinek7b836392015-12-04 20:02:59 -0800264 MeasureSpec.makeMeasureSpec(maxSize, MeasureSpec.AT_MOST));
Selim Cinek83bc7832015-10-22 13:26:54 -0700265 maxChildHeight = Math.max(maxChildHeight, mSingleLineView.getMeasuredHeight());
266 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800267 if (mAmbientChild != null) {
268 int size = Math.min(maxSize, mNotificationAmbientHeight);
269 ViewGroup.LayoutParams layoutParams = mAmbientChild.getLayoutParams();
Selim Cinek6743c0b2017-01-18 18:24:01 -0800270 boolean useExactly = false;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800271 if (layoutParams.height >= 0) {
272 // An actual height is set
273 size = Math.min(size, layoutParams.height);
Selim Cinek6743c0b2017-01-18 18:24:01 -0800274 useExactly = true;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800275 }
276 mAmbientChild.measure(widthMeasureSpec,
Selim Cinek6743c0b2017-01-18 18:24:01 -0800277 MeasureSpec.makeMeasureSpec(size, useExactly ? MeasureSpec.EXACTLY
278 : MeasureSpec.AT_MOST));
Adrian Roos0aac04f2016-12-08 15:59:29 -0800279 maxChildHeight = Math.max(maxChildHeight, mAmbientChild.getMeasuredHeight());
280 }
Adrian Roos6f6e1592017-05-02 16:22:53 -0700281 if (mAmbientSingleLineChild != null) {
282 int size = Math.min(maxSize, mNotificationAmbientHeight);
283 ViewGroup.LayoutParams layoutParams = mAmbientSingleLineChild.getLayoutParams();
284 boolean useExactly = false;
285 if (layoutParams.height >= 0) {
286 // An actual height is set
287 size = Math.min(size, layoutParams.height);
288 useExactly = true;
289 }
290 int ambientSingleLineWidthSpec = widthMeasureSpec;
291 if (mSingleLineWidthIndention != 0
292 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED) {
293 ambientSingleLineWidthSpec = MeasureSpec.makeMeasureSpec(
294 width - mSingleLineWidthIndention + mAmbientSingleLineChild.getPaddingEnd(),
295 MeasureSpec.EXACTLY);
296 }
297 mAmbientSingleLineChild.measure(ambientSingleLineWidthSpec,
298 MeasureSpec.makeMeasureSpec(size, useExactly ? MeasureSpec.EXACTLY
299 : MeasureSpec.AT_MOST));
300 maxChildHeight = Math.max(maxChildHeight, mAmbientSingleLineChild.getMeasuredHeight());
301 }
Selim Cinek8d490d42015-04-10 00:05:50 -0700302 int ownHeight = Math.min(maxChildHeight, maxSize);
Selim Cinek8d490d42015-04-10 00:05:50 -0700303 setMeasuredDimension(width, ownHeight);
304 }
305
Selim Cineked64a142018-02-06 18:06:01 -0800306 /**
307 * Get the extra height that needs to be added to the notification height for a given
308 * {@link RemoteInputView}.
309 * This is needed when the user is inline replying in order to ensure that the reply bar has
310 * enough padding.
311 *
312 * @param remoteInput The remote input to check.
313 * @return The extra height needed.
314 */
315 private int getExtraRemoteInputHeight(RemoteInputView remoteInput) {
316 if (remoteInput != null && remoteInput.getVisibility() == VISIBLE
317 && remoteInput.isActive()) {
318 return getResources().getDimensionPixelSize(
319 com.android.internal.R.dimen.notification_content_margin);
320 }
321 return 0;
322 }
323
Selim Cinek6ecc8102016-01-26 18:26:19 -0800324 private boolean updateContractedHeaderWidth() {
325 // We need to update the expanded and the collapsed header to have exactly the same with to
326 // have the expand buttons laid out at the same location.
327 NotificationHeaderView contractedHeader = mContractedWrapper.getNotificationHeader();
328 if (contractedHeader != null) {
329 if (mExpandedChild != null
330 && mExpandedWrapper.getNotificationHeader() != null) {
331 NotificationHeaderView expandedHeader = mExpandedWrapper.getNotificationHeader();
332 int expandedSize = expandedHeader.getMeasuredWidth()
333 - expandedHeader.getPaddingEnd();
334 int collapsedSize = contractedHeader.getMeasuredWidth()
335 - expandedHeader.getPaddingEnd();
336 if (expandedSize != collapsedSize) {
337 int paddingEnd = contractedHeader.getMeasuredWidth() - expandedSize;
338 contractedHeader.setPadding(
Selim Cinekcb445682016-01-29 16:13:12 -0800339 contractedHeader.isLayoutRtl()
340 ? paddingEnd
341 : contractedHeader.getPaddingLeft(),
Selim Cinek6ecc8102016-01-26 18:26:19 -0800342 contractedHeader.getPaddingTop(),
Selim Cinekcb445682016-01-29 16:13:12 -0800343 contractedHeader.isLayoutRtl()
344 ? contractedHeader.getPaddingLeft()
345 : paddingEnd,
Selim Cinek6ecc8102016-01-26 18:26:19 -0800346 contractedHeader.getPaddingBottom());
347 contractedHeader.setShowWorkBadgeAtEnd(true);
348 return true;
349 }
350 } else {
351 int paddingEnd = mNotificationContentMarginEnd;
352 if (contractedHeader.getPaddingEnd() != paddingEnd) {
353 contractedHeader.setPadding(
Selim Cinekcb445682016-01-29 16:13:12 -0800354 contractedHeader.isLayoutRtl()
355 ? paddingEnd
356 : contractedHeader.getPaddingLeft(),
Selim Cinek6ecc8102016-01-26 18:26:19 -0800357 contractedHeader.getPaddingTop(),
Selim Cinekcb445682016-01-29 16:13:12 -0800358 contractedHeader.isLayoutRtl()
359 ? contractedHeader.getPaddingLeft()
360 : paddingEnd,
Selim Cinek6ecc8102016-01-26 18:26:19 -0800361 contractedHeader.getPaddingBottom());
362 contractedHeader.setShowWorkBadgeAtEnd(false);
363 return true;
364 }
365 }
366 }
367 return false;
368 }
369
Selim Cinek860b6da2015-12-16 19:02:19 -0800370 private boolean shouldContractedBeFixedSize() {
371 return mBeforeN && mContractedWrapper instanceof NotificationCustomViewWrapper;
372 }
373
Selim Cinek8d490d42015-04-10 00:05:50 -0700374 @Override
Jorim Jaggibe565df2014-04-28 17:51:23 +0200375 protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
Adrian Roos599be342016-06-13 14:54:39 -0700376 int previousHeight = 0;
377 if (mExpandedChild != null) {
378 previousHeight = mExpandedChild.getHeight();
379 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200380 super.onLayout(changed, left, top, right, bottom);
Adrian Roos599be342016-06-13 14:54:39 -0700381 if (previousHeight != 0 && mExpandedChild.getHeight() != previousHeight) {
382 mContentHeightAtAnimationStart = previousHeight;
383 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200384 updateClipping();
Jorim Jaggibe4116a2015-05-20 20:04:08 -0700385 invalidateOutline();
Selim Cinek589fd3e2016-04-26 18:17:57 -0700386 selectLayout(false /* animate */, mForceSelectNextLayout /* force */);
387 mForceSelectNextLayout = false;
Selim Cinek5f56d852016-05-24 16:55:13 -0700388 updateExpandButtons(mExpandable);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200389 }
390
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100391 @Override
Selim Cinek7b8157e2014-11-20 16:00:32 +0100392 protected void onAttachedToWindow() {
393 super.onAttachedToWindow();
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100394 updateVisibility();
395 }
396
Selim Cinekcab4a602014-09-03 14:47:57 +0200397 public View getContractedChild() {
398 return mContractedChild;
399 }
400
401 public View getExpandedChild() {
402 return mExpandedChild;
403 }
404
Selim Cinek8d490d42015-04-10 00:05:50 -0700405 public View getHeadsUpChild() {
406 return mHeadsUpChild;
407 }
408
Adrian Roos0aac04f2016-12-08 15:59:29 -0800409 public View getAmbientChild() {
410 return mAmbientChild;
411 }
412
Adrian Roos6f6e1592017-05-02 16:22:53 -0700413 public HybridNotificationView getAmbientSingleLineChild() {
414 return mAmbientSingleLineChild;
415 }
416
Jorim Jaggibe565df2014-04-28 17:51:23 +0200417 public void setContractedChild(View child) {
418 if (mContractedChild != null) {
Jorim Jaggi0d9f35d2014-08-20 17:06:55 +0200419 mContractedChild.animate().cancel();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200420 removeView(mContractedChild);
421 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200422 addView(child);
423 mContractedChild = child;
Selim Cinek7d1c63e2016-04-21 15:26:10 -0700424 mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child,
425 mContainingNotification);
Jorim Jaggi10ad7612014-12-08 18:41:11 +0100426 mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */);
Selim Cinek9b49f6d2017-11-13 18:19:35 -0800427 }
428
429 private NotificationViewWrapper getWrapperForView(View child) {
430 if (child == mContractedChild) {
431 return mContractedWrapper;
432 }
433 if (child == mExpandedChild) {
434 return mExpandedWrapper;
435 }
436 if (child == mHeadsUpChild) {
437 return mHeadsUpWrapper;
438 }
439 if (child == mAmbientChild) {
440 return mAmbientWrapper;
441 }
442 return null;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200443 }
444
445 public void setExpandedChild(View child) {
446 if (mExpandedChild != null) {
Selim Cinek1a48bab2017-02-17 19:38:40 -0800447 mPreviousExpandedRemoteInputIntent = null;
448 if (mExpandedRemoteInput != null) {
449 mExpandedRemoteInput.onNotificationUpdateOrReset();
450 if (mExpandedRemoteInput.isActive()) {
451 mPreviousExpandedRemoteInputIntent = mExpandedRemoteInput.getPendingIntent();
452 mCachedExpandedRemoteInput = mExpandedRemoteInput;
453 mExpandedRemoteInput.dispatchStartTemporaryDetach();
454 ((ViewGroup)mExpandedRemoteInput.getParent()).removeView(mExpandedRemoteInput);
455 }
456 }
Jorim Jaggi0d9f35d2014-08-20 17:06:55 +0200457 mExpandedChild.animate().cancel();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200458 removeView(mExpandedChild);
Selim Cinek1a48bab2017-02-17 19:38:40 -0800459 mExpandedRemoteInput = null;
460 }
461 if (child == null) {
462 mExpandedChild = null;
463 mExpandedWrapper = null;
464 if (mVisibleType == VISIBLE_TYPE_EXPANDED) {
465 mVisibleType = VISIBLE_TYPE_CONTRACTED;
466 }
467 if (mTransformationStartVisibleType == VISIBLE_TYPE_EXPANDED) {
468 mTransformationStartVisibleType = UNDEFINED;
469 }
470 return;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200471 }
472 addView(child);
473 mExpandedChild = child;
Selim Cinek7d1c63e2016-04-21 15:26:10 -0700474 mExpandedWrapper = NotificationViewWrapper.wrap(getContext(), child,
475 mContainingNotification);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200476 }
477
Selim Cinek8d490d42015-04-10 00:05:50 -0700478 public void setHeadsUpChild(View child) {
479 if (mHeadsUpChild != null) {
Selim Cinek1a48bab2017-02-17 19:38:40 -0800480 mPreviousHeadsUpRemoteInputIntent = null;
481 if (mHeadsUpRemoteInput != null) {
482 mHeadsUpRemoteInput.onNotificationUpdateOrReset();
483 if (mHeadsUpRemoteInput.isActive()) {
484 mPreviousHeadsUpRemoteInputIntent = mHeadsUpRemoteInput.getPendingIntent();
485 mCachedHeadsUpRemoteInput = mHeadsUpRemoteInput;
486 mHeadsUpRemoteInput.dispatchStartTemporaryDetach();
487 ((ViewGroup)mHeadsUpRemoteInput.getParent()).removeView(mHeadsUpRemoteInput);
488 }
489 }
Selim Cinek8d490d42015-04-10 00:05:50 -0700490 mHeadsUpChild.animate().cancel();
491 removeView(mHeadsUpChild);
Selim Cinek1a48bab2017-02-17 19:38:40 -0800492 mHeadsUpRemoteInput = null;
493 }
494 if (child == null) {
495 mHeadsUpChild = null;
496 mHeadsUpWrapper = null;
497 if (mVisibleType == VISIBLE_TYPE_HEADSUP) {
498 mVisibleType = VISIBLE_TYPE_CONTRACTED;
499 }
500 if (mTransformationStartVisibleType == VISIBLE_TYPE_HEADSUP) {
501 mTransformationStartVisibleType = UNDEFINED;
502 }
503 return;
Selim Cinek8d490d42015-04-10 00:05:50 -0700504 }
505 addView(child);
506 mHeadsUpChild = child;
Selim Cinek7d1c63e2016-04-21 15:26:10 -0700507 mHeadsUpWrapper = NotificationViewWrapper.wrap(getContext(), child,
508 mContainingNotification);
Selim Cinek8d490d42015-04-10 00:05:50 -0700509 }
510
Adrian Roos0aac04f2016-12-08 15:59:29 -0800511 public void setAmbientChild(View child) {
512 if (mAmbientChild != null) {
513 mAmbientChild.animate().cancel();
514 removeView(mAmbientChild);
515 }
Adrian Roos1a1ecfc2017-04-17 11:17:59 -0700516 if (child == null) {
517 return;
518 }
Adrian Roos0aac04f2016-12-08 15:59:29 -0800519 addView(child);
520 mAmbientChild = child;
521 mAmbientWrapper = NotificationViewWrapper.wrap(getContext(), child,
522 mContainingNotification);
523 }
524
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100525 @Override
526 protected void onVisibilityChanged(View changedView, int visibility) {
527 super.onVisibilityChanged(changedView, visibility);
528 updateVisibility();
529 }
530
531 private void updateVisibility() {
532 setVisible(isShown());
533 }
534
Jorim Jaggi38b5ec92016-04-12 01:39:49 -0700535 @Override
536 protected void onDetachedFromWindow() {
537 super.onDetachedFromWindow();
538 getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener);
539 }
540
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100541 private void setVisible(final boolean isVisible) {
542 if (isVisible) {
Selim Cinekf1614a62016-05-26 16:57:20 -0700543 // This call can happen multiple times, but removing only removes a single one.
544 // We therefore need to remove the old one.
545 getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener);
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100546 // We only animate if we are drawn at least once, otherwise the view might animate when
547 // it's shown the first time
548 getViewTreeObserver().addOnPreDrawListener(mEnableAnimationPredrawListener);
549 } else {
550 getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener);
551 mAnimate = false;
552 }
553 }
554
Selim Cineke9bad242016-06-15 11:46:37 -0700555 private void focusExpandButtonIfNecessary() {
556 if (mFocusOnVisibilityChange) {
557 NotificationHeaderView header = getVisibleNotificationHeader();
558 if (header != null) {
559 ImageView expandButton = header.getExpandButton();
560 if (expandButton != null) {
561 expandButton.requestAccessibilityFocus();
562 }
563 }
564 mFocusOnVisibilityChange = false;
565 }
566 }
567
Selim Cinekb5605e52015-02-20 18:21:41 +0100568 public void setContentHeight(int contentHeight) {
Selim Cineked64a142018-02-06 18:06:01 -0800569 mUnrestrictedContentHeight = Math.max(contentHeight, getMinHeight());
570 int maxContentHeight = mContainingNotification.getIntrinsicHeight()
571 - getExtraRemoteInputHeight(mExpandedRemoteInput)
572 - getExtraRemoteInputHeight(mHeadsUpRemoteInput);
573 mContentHeight = Math.min(mUnrestrictedContentHeight, maxContentHeight);
Selim Cinekbb3d1cf2014-10-31 00:12:56 +0100574 selectLayout(mAnimate /* animate */, false /* force */);
Adrian Roos181385c2016-05-05 17:45:44 -0400575
576 int minHeightHint = getMinContentHeightHint();
577
578 NotificationViewWrapper wrapper = getVisibleWrapper(mVisibleType);
579 if (wrapper != null) {
Selim Cineked64a142018-02-06 18:06:01 -0800580 wrapper.setContentHeight(mUnrestrictedContentHeight, minHeightHint);
Adrian Roos181385c2016-05-05 17:45:44 -0400581 }
582
583 wrapper = getVisibleWrapper(mTransformationStartVisibleType);
584 if (wrapper != null) {
Selim Cineked64a142018-02-06 18:06:01 -0800585 wrapper.setContentHeight(mUnrestrictedContentHeight, minHeightHint);
Adrian Roos181385c2016-05-05 17:45:44 -0400586 }
587
Jorim Jaggibe565df2014-04-28 17:51:23 +0200588 updateClipping();
Jorim Jaggibe4116a2015-05-20 20:04:08 -0700589 invalidateOutline();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200590 }
591
Adrian Roos181385c2016-05-05 17:45:44 -0400592 /**
593 * @return the minimum apparent height that the wrapper should allow for the purpose
594 * of aligning elements at the bottom edge. If this is larger than the content
595 * height, the notification is clipped instead of being further shrunk.
596 */
597 private int getMinContentHeightHint() {
Adrian Roos599be342016-06-13 14:54:39 -0700598 if (mIsChildInGroup && isVisibleOrTransitioning(VISIBLE_TYPE_SINGLELINE)) {
Adrian Roos181385c2016-05-05 17:45:44 -0400599 return mContext.getResources().getDimensionPixelSize(
600 com.android.internal.R.dimen.notification_action_list_height);
601 }
Adrian Roos599be342016-06-13 14:54:39 -0700602
603 // Transition between heads-up & expanded, or pinned.
604 if (mHeadsUpChild != null && mExpandedChild != null) {
605 boolean transitioningBetweenHunAndExpanded =
606 isTransitioningFromTo(VISIBLE_TYPE_HEADSUP, VISIBLE_TYPE_EXPANDED) ||
607 isTransitioningFromTo(VISIBLE_TYPE_EXPANDED, VISIBLE_TYPE_HEADSUP);
Selim Cinek73cf02a2016-06-17 13:08:00 -0700608 boolean pinned = !isVisibleOrTransitioning(VISIBLE_TYPE_CONTRACTED)
Selim Cinekc494e382017-01-31 16:09:23 -0800609 && (mIsHeadsUp || mHeadsUpAnimatingAway)
610 && !mContainingNotification.isOnKeyguard();
Adrian Roos599be342016-06-13 14:54:39 -0700611 if (transitioningBetweenHunAndExpanded || pinned) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800612 return Math.min(getViewHeight(VISIBLE_TYPE_HEADSUP),
613 getViewHeight(VISIBLE_TYPE_EXPANDED));
Adrian Roos599be342016-06-13 14:54:39 -0700614 }
615 }
616
617 // Size change of the expanded version
618 if ((mVisibleType == VISIBLE_TYPE_EXPANDED) && mContentHeightAtAnimationStart >= 0
619 && mExpandedChild != null) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800620 return Math.min(mContentHeightAtAnimationStart, getViewHeight(VISIBLE_TYPE_EXPANDED));
Adrian Roos599be342016-06-13 14:54:39 -0700621 }
622
Adrian Roosbb73e9c62016-05-26 12:06:40 -0700623 int hint;
Adrian Roos05d3d002017-01-26 15:28:07 -0800624 if (mAmbientChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_AMBIENT)) {
625 hint = mAmbientChild.getHeight();
Adrian Roos6f6e1592017-05-02 16:22:53 -0700626 } else if (mAmbientSingleLineChild != null && isVisibleOrTransitioning(
627 VISIBLE_TYPE_AMBIENT_SINGLELINE)) {
628 hint = mAmbientSingleLineChild.getHeight();
Adrian Roos05d3d002017-01-26 15:28:07 -0800629 } else if (mHeadsUpChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_HEADSUP)) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800630 hint = getViewHeight(VISIBLE_TYPE_HEADSUP);
Adrian Roos599be342016-06-13 14:54:39 -0700631 } else if (mExpandedChild != null) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800632 hint = getViewHeight(VISIBLE_TYPE_EXPANDED);
Adrian Roos181385c2016-05-05 17:45:44 -0400633 } else {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800634 hint = getViewHeight(VISIBLE_TYPE_CONTRACTED)
635 + mContext.getResources().getDimensionPixelSize(
636 com.android.internal.R.dimen.notification_action_list_height);
Adrian Roos181385c2016-05-05 17:45:44 -0400637 }
Adrian Roos599be342016-06-13 14:54:39 -0700638
639 if (mExpandedChild != null && isVisibleOrTransitioning(VISIBLE_TYPE_EXPANDED)) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800640 hint = Math.min(hint, getViewHeight(VISIBLE_TYPE_EXPANDED));
Adrian Roosbb73e9c62016-05-26 12:06:40 -0700641 }
642 return hint;
Adrian Roos181385c2016-05-05 17:45:44 -0400643 }
644
Adrian Roos599be342016-06-13 14:54:39 -0700645 private boolean isTransitioningFromTo(int from, int to) {
646 return (mTransformationStartVisibleType == from || mAnimationStartVisibleType == from)
647 && mVisibleType == to;
648 }
649
650 private boolean isVisibleOrTransitioning(int type) {
651 return mVisibleType == type || mTransformationStartVisibleType == type
652 || mAnimationStartVisibleType == type;
653 }
654
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800655 private void updateContentTransformation() {
656 int visibleType = calculateVisibleType();
657 if (visibleType != mVisibleType) {
658 // A new transformation starts
659 mTransformationStartVisibleType = mVisibleType;
660 final TransformableView shownView = getTransformableViewForVisibleType(visibleType);
661 final TransformableView hiddenView = getTransformableViewForVisibleType(
662 mTransformationStartVisibleType);
663 shownView.transformFrom(hiddenView, 0.0f);
664 getViewForVisibleType(visibleType).setVisibility(View.VISIBLE);
665 hiddenView.transformTo(shownView, 0.0f);
666 mVisibleType = visibleType;
Selim Cinekc3179332016-03-04 14:44:56 -0800667 updateBackgroundColor(true /* animate */);
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800668 }
Selim Cineke8578872016-05-03 16:42:50 -0700669 if (mForceSelectNextLayout) {
670 forceUpdateVisibilities();
671 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800672 if (mTransformationStartVisibleType != UNDEFINED
Selim Cinek589fd3e2016-04-26 18:17:57 -0700673 && mVisibleType != mTransformationStartVisibleType
674 && getViewForVisibleType(mTransformationStartVisibleType) != null) {
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800675 final TransformableView shownView = getTransformableViewForVisibleType(mVisibleType);
676 final TransformableView hiddenView = getTransformableViewForVisibleType(
677 mTransformationStartVisibleType);
678 float transformationAmount = calculateTransformationAmount();
679 shownView.transformFrom(hiddenView, transformationAmount);
680 hiddenView.transformTo(shownView, transformationAmount);
Selim Cinekc3179332016-03-04 14:44:56 -0800681 updateBackgroundTransformation(transformationAmount);
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800682 } else {
683 updateViewVisibilities(visibleType);
Selim Cinekc3179332016-03-04 14:44:56 -0800684 updateBackgroundColor(false);
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800685 }
686 }
687
Selim Cinekc3179332016-03-04 14:44:56 -0800688 private void updateBackgroundTransformation(float transformationAmount) {
689 int endColor = getBackgroundColor(mVisibleType);
690 int startColor = getBackgroundColor(mTransformationStartVisibleType);
691 if (endColor != startColor) {
692 if (startColor == 0) {
693 startColor = mContainingNotification.getBackgroundColorWithoutTint();
694 }
695 if (endColor == 0) {
696 endColor = mContainingNotification.getBackgroundColorWithoutTint();
697 }
698 endColor = NotificationUtils.interpolateColors(startColor, endColor,
699 transformationAmount);
700 }
Mady Mellorc7d65b42016-05-04 11:44:57 -0400701 mContainingNotification.updateBackgroundAlpha(transformationAmount);
Selim Cinekc3179332016-03-04 14:44:56 -0800702 mContainingNotification.setContentBackground(endColor, false, this);
703 }
704
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800705 private float calculateTransformationAmount() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800706 int startHeight = getViewHeight(mTransformationStartVisibleType);
707 int endHeight = getViewHeight(mVisibleType);
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800708 int progress = Math.abs(mContentHeight - startHeight);
709 int totalDistance = Math.abs(endHeight - startHeight);
Selim Cinek011bde92017-11-22 05:53:38 -0800710 if (totalDistance == 0) {
711 Log.wtf(TAG, "the total transformation distance is 0"
712 + "\n StartType: " + mTransformationStartVisibleType + " height: " + startHeight
713 + "\n VisibleType: " + mVisibleType + " height: " + endHeight
714 + "\n mContentHeight: " + mContentHeight);
715 return 1.0f;
716 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800717 float amount = (float) progress / (float) totalDistance;
718 return Math.min(1.0f, amount);
719 }
720
Selim Cinekb5605e52015-02-20 18:21:41 +0100721 public int getContentHeight() {
722 return mContentHeight;
723 }
724
Jorim Jaggibe565df2014-04-28 17:51:23 +0200725 public int getMaxHeight() {
Adrian Roos6f6e1592017-05-02 16:22:53 -0700726 if (mContainingNotification.isShowingAmbient()) {
727 return getShowingAmbientView().getHeight();
728 } else if (mExpandedChild != null) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800729 return getViewHeight(VISIBLE_TYPE_EXPANDED)
730 + getExtraRemoteInputHeight(mExpandedRemoteInput);
Selim Cinekc494e382017-01-31 16:09:23 -0800731 } else if (mIsHeadsUp && mHeadsUpChild != null && !mContainingNotification.isOnKeyguard()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800732 return getViewHeight(VISIBLE_TYPE_HEADSUP)
733 + getExtraRemoteInputHeight(mHeadsUpRemoteInput);
Selim Cinek8d490d42015-04-10 00:05:50 -0700734 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800735 return getViewHeight(VISIBLE_TYPE_CONTRACTED);
736 }
737
738 private int getViewHeight(int visibleType) {
739 View view = getViewForVisibleType(visibleType);
740 int height = view.getHeight();
741 NotificationViewWrapper viewWrapper = getWrapperForView(view);
742 if (viewWrapper != null) {
743 height += viewWrapper.getHeaderTranslation();
744 }
745 return height;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200746 }
747
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200748 public int getMinHeight() {
Selim Cinek42357e02016-02-24 18:48:01 -0800749 return getMinHeight(false /* likeGroupExpanded */);
750 }
751
752 public int getMinHeight(boolean likeGroupExpanded) {
Adrian Roos6f6e1592017-05-02 16:22:53 -0700753 if (mContainingNotification.isShowingAmbient()) {
754 return getShowingAmbientView().getHeight();
755 } else if (likeGroupExpanded || !mIsChildInGroup || isGroupExpanded()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800756 return getViewHeight(VISIBLE_TYPE_CONTRACTED);
Selim Cinek42357e02016-02-24 18:48:01 -0800757 } else {
758 return mSingleLineView.getHeight();
Selim Cinek83bc7832015-10-22 13:26:54 -0700759 }
760 }
761
Adrian Roos6f6e1592017-05-02 16:22:53 -0700762 public View getShowingAmbientView() {
763 View v = mIsChildInGroup ? mAmbientSingleLineChild : mAmbientChild;
764 if (v != null) {
765 return v;
766 } else {
767 return mContractedChild;
768 }
769 }
770
Selim Cinek83bc7832015-10-22 13:26:54 -0700771 private boolean isGroupExpanded() {
772 return mGroupManager.isGroupExpanded(mStatusBarNotification);
Jorim Jaggi4222d9a2014-04-23 16:13:15 +0200773 }
774
Jorim Jaggibe565df2014-04-28 17:51:23 +0200775 public void setClipTopAmount(int clipTopAmount) {
Selim Cinekc9c00ae2014-05-20 03:33:40 +0200776 mClipTopAmount = clipTopAmount;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200777 updateClipping();
778 }
779
Selim Cineka686b2c2016-10-26 13:58:27 -0700780
781 public void setClipBottomAmount(int clipBottomAmount) {
782 mClipBottomAmount = clipBottomAmount;
783 updateClipping();
784 }
785
Selim Cinek875a3a12016-11-18 17:52:16 -0800786 @Override
787 public void setTranslationY(float translationY) {
788 super.setTranslationY(translationY);
789 updateClipping();
790 }
791
Jorim Jaggibe565df2014-04-28 17:51:23 +0200792 private void updateClipping() {
Selim Cinek4ffd6362015-12-29 15:12:23 +0100793 if (mClipToActualHeight) {
Selim Cinek875a3a12016-11-18 17:52:16 -0800794 int top = (int) (mClipTopAmount - getTranslationY());
Selim Cineked64a142018-02-06 18:06:01 -0800795 int bottom = (int) (mUnrestrictedContentHeight - mClipBottomAmount - getTranslationY());
Selim Cineka686b2c2016-10-26 13:58:27 -0700796 bottom = Math.max(top, bottom);
797 mClipBounds.set(0, top, getWidth(), bottom);
Selim Cinek4ffd6362015-12-29 15:12:23 +0100798 setClipBounds(mClipBounds);
799 } else {
800 setClipBounds(null);
801 }
802 }
803
804 public void setClipToActualHeight(boolean clipToActualHeight) {
805 mClipToActualHeight = clipToActualHeight;
806 updateClipping();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200807 }
808
Jorim Jaggi11298832014-05-24 16:18:38 +0200809 private void selectLayout(boolean animate, boolean force) {
810 if (mContractedChild == null) {
811 return;
812 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -0800813 if (mUserExpanding) {
814 updateContentTransformation();
Selim Cinek589fd3e2016-04-26 18:17:57 -0700815 } else {
816 int visibleType = calculateVisibleType();
Selim Cineke9bad242016-06-15 11:46:37 -0700817 boolean changedType = visibleType != mVisibleType;
818 if (changedType || force) {
Adrian Roos181385c2016-05-05 17:45:44 -0400819 View visibleView = getViewForVisibleType(visibleType);
820 if (visibleView != null) {
821 visibleView.setVisibility(VISIBLE);
822 transferRemoteInputFocus(visibleType);
823 }
Adrian Roos4c1fcc82016-03-31 14:39:39 -0700824
Selim Cinek589fd3e2016-04-26 18:17:57 -0700825 if (animate && ((visibleType == VISIBLE_TYPE_EXPANDED && mExpandedChild != null)
826 || (visibleType == VISIBLE_TYPE_HEADSUP && mHeadsUpChild != null)
827 || (visibleType == VISIBLE_TYPE_SINGLELINE && mSingleLineView != null)
828 || visibleType == VISIBLE_TYPE_CONTRACTED)) {
829 animateToVisibleType(visibleType);
830 } else {
831 updateViewVisibilities(visibleType);
832 }
833 mVisibleType = visibleType;
Selim Cineke9bad242016-06-15 11:46:37 -0700834 if (changedType) {
835 focusExpandButtonIfNecessary();
836 }
Adrian Roos05d3d002017-01-26 15:28:07 -0800837 NotificationViewWrapper visibleWrapper = getVisibleWrapper(visibleType);
838 if (visibleWrapper != null) {
Selim Cineked64a142018-02-06 18:06:01 -0800839 visibleWrapper.setContentHeight(mUnrestrictedContentHeight,
840 getMinContentHeightHint());
Adrian Roos05d3d002017-01-26 15:28:07 -0800841 }
Selim Cinek589fd3e2016-04-26 18:17:57 -0700842 updateBackgroundColor(animate);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200843 }
Selim Cinek589fd3e2016-04-26 18:17:57 -0700844 }
Selim Cinek589fd3e2016-04-26 18:17:57 -0700845 }
846
847 private void forceUpdateVisibilities() {
Adrian Roos0aac04f2016-12-08 15:59:29 -0800848 forceUpdateVisibility(VISIBLE_TYPE_CONTRACTED, mContractedChild, mContractedWrapper);
849 forceUpdateVisibility(VISIBLE_TYPE_EXPANDED, mExpandedChild, mExpandedWrapper);
850 forceUpdateVisibility(VISIBLE_TYPE_HEADSUP, mHeadsUpChild, mHeadsUpWrapper);
851 forceUpdateVisibility(VISIBLE_TYPE_SINGLELINE, mSingleLineView, mSingleLineView);
852 forceUpdateVisibility(VISIBLE_TYPE_AMBIENT, mAmbientChild, mAmbientWrapper);
Adrian Roos6f6e1592017-05-02 16:22:53 -0700853 forceUpdateVisibility(VISIBLE_TYPE_AMBIENT_SINGLELINE, mAmbientSingleLineChild,
854 mAmbientSingleLineChild);
Adrian Roos4320e892017-01-24 12:50:34 -0800855 fireExpandedVisibleListenerIfVisible();
Adrian Roose18033c2017-01-17 15:22:49 -0800856 // forceUpdateVisibilities cancels outstanding animations without updating the
857 // mAnimationStartVisibleType. Do so here instead.
858 mAnimationStartVisibleType = UNDEFINED;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800859 }
860
Adrian Roos4320e892017-01-24 12:50:34 -0800861 private void fireExpandedVisibleListenerIfVisible() {
862 if (mExpandedVisibleListener != null && mExpandedChild != null && isShown()
863 && mExpandedChild.getVisibility() == VISIBLE) {
864 Runnable listener = mExpandedVisibleListener;
865 mExpandedVisibleListener = null;
866 listener.run();
867 }
868 }
869
Adrian Roos0aac04f2016-12-08 15:59:29 -0800870 private void forceUpdateVisibility(int type, View view, TransformableView wrapper) {
871 if (view == null) {
872 return;
873 }
874 boolean visible = mVisibleType == type
875 || mTransformationStartVisibleType == type;
876 if (!visible) {
877 view.setVisibility(INVISIBLE);
Selim Cinek589fd3e2016-04-26 18:17:57 -0700878 } else {
Adrian Roos0aac04f2016-12-08 15:59:29 -0800879 wrapper.setVisible(true);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200880 }
Jorim Jaggi11298832014-05-24 16:18:38 +0200881 }
882
Selim Cinekc3179332016-03-04 14:44:56 -0800883 public void updateBackgroundColor(boolean animate) {
884 int customBackgroundColor = getBackgroundColor(mVisibleType);
Mady Mellorc7d65b42016-05-04 11:44:57 -0400885 mContainingNotification.resetBackgroundAlpha();
Selim Cinekc3179332016-03-04 14:44:56 -0800886 mContainingNotification.setContentBackground(customBackgroundColor, animate, this);
887 }
888
Mady Mellorb0a82462016-04-30 17:31:02 -0700889 public int getVisibleType() {
890 return mVisibleType;
891 }
892
893 public int getBackgroundColorForExpansionState() {
894 // When expanding or user locked we want the new type, when collapsing we want
895 // the original type
896 final int visibleType = (mContainingNotification.isGroupExpanded()
897 || mContainingNotification.isUserLocked())
898 ? calculateVisibleType()
899 : getVisibleType();
900 return getBackgroundColor(visibleType);
901 }
902
903 public int getBackgroundColor(int visibleType) {
Selim Cinekc3179332016-03-04 14:44:56 -0800904 NotificationViewWrapper currentVisibleWrapper = getVisibleWrapper(visibleType);
905 int customBackgroundColor = 0;
906 if (currentVisibleWrapper != null) {
907 customBackgroundColor = currentVisibleWrapper.getCustomBackgroundColor();
908 }
909 return customBackgroundColor;
910 }
911
Selim Cinek684a4422015-04-15 16:18:39 -0700912 private void updateViewVisibilities(int visibleType) {
Adrian Roos0aac04f2016-12-08 15:59:29 -0800913 updateViewVisibility(visibleType, VISIBLE_TYPE_CONTRACTED,
914 mContractedChild, mContractedWrapper);
915 updateViewVisibility(visibleType, VISIBLE_TYPE_EXPANDED,
916 mExpandedChild, mExpandedWrapper);
917 updateViewVisibility(visibleType, VISIBLE_TYPE_HEADSUP,
918 mHeadsUpChild, mHeadsUpWrapper);
919 updateViewVisibility(visibleType, VISIBLE_TYPE_SINGLELINE,
920 mSingleLineView, mSingleLineView);
921 updateViewVisibility(visibleType, VISIBLE_TYPE_AMBIENT,
922 mAmbientChild, mAmbientWrapper);
Adrian Roos6f6e1592017-05-02 16:22:53 -0700923 updateViewVisibility(visibleType, VISIBLE_TYPE_AMBIENT_SINGLELINE,
924 mAmbientSingleLineChild, mAmbientSingleLineChild);
Adrian Roos4320e892017-01-24 12:50:34 -0800925 fireExpandedVisibleListenerIfVisible();
Adrian Roose18033c2017-01-17 15:22:49 -0800926 // updateViewVisibilities cancels outstanding animations without updating the
927 // mAnimationStartVisibleType. Do so here instead.
928 mAnimationStartVisibleType = UNDEFINED;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800929 }
930
931 private void updateViewVisibility(int visibleType, int type, View view,
932 TransformableView wrapper) {
933 if (view != null) {
934 wrapper.setVisible(visibleType == type);
Selim Cinek83bc7832015-10-22 13:26:54 -0700935 }
Selim Cinek8d490d42015-04-10 00:05:50 -0700936 }
937
Selim Cinek4ffd6362015-12-29 15:12:23 +0100938 private void animateToVisibleType(int visibleType) {
939 final TransformableView shownView = getTransformableViewForVisibleType(visibleType);
940 final TransformableView hiddenView = getTransformableViewForVisibleType(mVisibleType);
Selim Cinek589fd3e2016-04-26 18:17:57 -0700941 if (shownView == hiddenView || hiddenView == null) {
Selim Cinek51d94912016-03-02 15:34:28 -0800942 shownView.setVisible(true);
943 return;
944 }
Adrian Roos599be342016-06-13 14:54:39 -0700945 mAnimationStartVisibleType = mVisibleType;
Selim Cinek4ffd6362015-12-29 15:12:23 +0100946 shownView.transformFrom(hiddenView);
947 getViewForVisibleType(visibleType).setVisibility(View.VISIBLE);
948 hiddenView.transformTo(shownView, new Runnable() {
949 @Override
950 public void run() {
Selim Cinek51d94912016-03-02 15:34:28 -0800951 if (hiddenView != getTransformableViewForVisibleType(mVisibleType)) {
952 hiddenView.setVisible(false);
953 }
Adrian Roos599be342016-06-13 14:54:39 -0700954 mAnimationStartVisibleType = UNDEFINED;
Selim Cinek4ffd6362015-12-29 15:12:23 +0100955 }
956 });
Adrian Roos4320e892017-01-24 12:50:34 -0800957 fireExpandedVisibleListenerIfVisible();
Jorim Jaggi11298832014-05-24 16:18:38 +0200958 }
959
Adrian Roos4c1fcc82016-03-31 14:39:39 -0700960 private void transferRemoteInputFocus(int visibleType) {
961 if (visibleType == VISIBLE_TYPE_HEADSUP
962 && mHeadsUpRemoteInput != null
963 && (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive())) {
964 mHeadsUpRemoteInput.stealFocusFrom(mExpandedRemoteInput);
965 }
966 if (visibleType == VISIBLE_TYPE_EXPANDED
967 && mExpandedRemoteInput != null
968 && (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive())) {
969 mExpandedRemoteInput.stealFocusFrom(mHeadsUpRemoteInput);
970 }
971 }
972
Selim Cinek684a4422015-04-15 16:18:39 -0700973 /**
974 * @param visibleType one of the static enum types in this view
Selim Cinek4ffd6362015-12-29 15:12:23 +0100975 * @return the corresponding transformable view according to the given visible type
976 */
977 private TransformableView getTransformableViewForVisibleType(int visibleType) {
978 switch (visibleType) {
979 case VISIBLE_TYPE_EXPANDED:
980 return mExpandedWrapper;
981 case VISIBLE_TYPE_HEADSUP:
982 return mHeadsUpWrapper;
983 case VISIBLE_TYPE_SINGLELINE:
984 return mSingleLineView;
Adrian Roos0aac04f2016-12-08 15:59:29 -0800985 case VISIBLE_TYPE_AMBIENT:
986 return mAmbientWrapper;
Adrian Roos6f6e1592017-05-02 16:22:53 -0700987 case VISIBLE_TYPE_AMBIENT_SINGLELINE:
988 return mAmbientSingleLineChild;
Selim Cinek4ffd6362015-12-29 15:12:23 +0100989 default:
990 return mContractedWrapper;
991 }
992 }
993
994 /**
995 * @param visibleType one of the static enum types in this view
Selim Cinek684a4422015-04-15 16:18:39 -0700996 * @return the corresponding view according to the given visible type
997 */
998 private View getViewForVisibleType(int visibleType) {
999 switch (visibleType) {
1000 case VISIBLE_TYPE_EXPANDED:
Selim Cinek8d490d42015-04-10 00:05:50 -07001001 return mExpandedChild;
Selim Cinek684a4422015-04-15 16:18:39 -07001002 case VISIBLE_TYPE_HEADSUP:
Selim Cinek8d490d42015-04-10 00:05:50 -07001003 return mHeadsUpChild;
Selim Cinek83bc7832015-10-22 13:26:54 -07001004 case VISIBLE_TYPE_SINGLELINE:
1005 return mSingleLineView;
Adrian Roos0aac04f2016-12-08 15:59:29 -08001006 case VISIBLE_TYPE_AMBIENT:
1007 return mAmbientChild;
Adrian Roos6f6e1592017-05-02 16:22:53 -07001008 case VISIBLE_TYPE_AMBIENT_SINGLELINE:
1009 return mAmbientSingleLineChild;
Selim Cinek684a4422015-04-15 16:18:39 -07001010 default:
1011 return mContractedChild;
Selim Cinek8d490d42015-04-10 00:05:50 -07001012 }
Selim Cinek8d490d42015-04-10 00:05:50 -07001013 }
1014
Selim Cinek131f1a42017-06-05 17:50:19 -07001015 public NotificationViewWrapper getVisibleWrapper(int visibleType) {
Selim Cinekc3179332016-03-04 14:44:56 -08001016 switch (visibleType) {
Selim Cinek34eda5e2016-02-18 17:10:43 -08001017 case VISIBLE_TYPE_EXPANDED:
1018 return mExpandedWrapper;
1019 case VISIBLE_TYPE_HEADSUP:
1020 return mHeadsUpWrapper;
1021 case VISIBLE_TYPE_CONTRACTED:
1022 return mContractedWrapper;
Adrian Roos0aac04f2016-12-08 15:59:29 -08001023 case VISIBLE_TYPE_AMBIENT:
1024 return mAmbientWrapper;
Selim Cinek34eda5e2016-02-18 17:10:43 -08001025 default:
1026 return null;
1027 }
1028 }
1029
Selim Cinek684a4422015-04-15 16:18:39 -07001030 /**
1031 * @return one of the static enum types in this view, calculated form the current state
1032 */
Mady Mellorb0a82462016-04-30 17:31:02 -07001033 public int calculateVisibleType() {
Adrian Roos6f6e1592017-05-02 16:22:53 -07001034 if (mContainingNotification.isShowingAmbient()) {
1035 if (mIsChildInGroup && mAmbientSingleLineChild != null) {
1036 return VISIBLE_TYPE_AMBIENT_SINGLELINE;
1037 } else if (mAmbientChild != null) {
1038 return VISIBLE_TYPE_AMBIENT;
1039 } else {
1040 return VISIBLE_TYPE_CONTRACTED;
1041 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08001042 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001043 if (mUserExpanding) {
Selim Cinek42357e02016-02-24 18:48:01 -08001044 int height = !mIsChildInGroup || isGroupExpanded()
Selim Cineke81b82b2016-03-04 11:22:28 -08001045 || mContainingNotification.isExpanded(true /* allowOnKeyguard */)
Selim Cinek42357e02016-02-24 18:48:01 -08001046 ? mContainingNotification.getMaxContentHeight()
1047 : mContainingNotification.getShowingLayout().getMinHeight();
Selim Cinek51d94912016-03-02 15:34:28 -08001048 if (height == 0) {
1049 height = mContentHeight;
1050 }
Selim Cinek42357e02016-02-24 18:48:01 -08001051 int expandedVisualType = getVisualTypeForHeight(height);
Selim Cinek414ad332017-02-24 19:06:12 -08001052 int collapsedVisualType = mIsChildInGroup && !isGroupExpanded()
Selim Cinek589fd3e2016-04-26 18:17:57 -07001053 ? VISIBLE_TYPE_SINGLELINE
1054 : getVisualTypeForHeight(mContainingNotification.getCollapsedHeight());
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001055 return mTransformationStartVisibleType == collapsedVisualType
1056 ? expandedVisualType
1057 : collapsedVisualType;
1058 }
Selim Cinek51d94912016-03-02 15:34:28 -08001059 int intrinsicHeight = mContainingNotification.getIntrinsicHeight();
1060 int viewHeight = mContentHeight;
1061 if (intrinsicHeight != 0) {
1062 // the intrinsicHeight might be 0 because it was just reset.
1063 viewHeight = Math.min(mContentHeight, intrinsicHeight);
1064 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001065 return getVisualTypeForHeight(viewHeight);
1066 }
1067
1068 private int getVisualTypeForHeight(float viewHeight) {
1069 boolean noExpandedChild = mExpandedChild == null;
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001070 if (!noExpandedChild && viewHeight == getViewHeight(VISIBLE_TYPE_EXPANDED)) {
Adrian Roos777ef562015-12-01 17:37:14 -08001071 return VISIBLE_TYPE_EXPANDED;
1072 }
Selim Cinek414ad332017-02-24 19:06:12 -08001073 if (!mUserExpanding && mIsChildInGroup && !isGroupExpanded()) {
Selim Cinekd84a5932015-12-15 11:45:36 -08001074 return VISIBLE_TYPE_SINGLELINE;
1075 }
Adrian Roos777ef562015-12-01 17:37:14 -08001076
Selim Cinekc494e382017-01-31 16:09:23 -08001077 if ((mIsHeadsUp || mHeadsUpAnimatingAway) && mHeadsUpChild != null
1078 && !mContainingNotification.isOnKeyguard()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001079 if (viewHeight <= getViewHeight(VISIBLE_TYPE_HEADSUP) || noExpandedChild) {
Selim Cinek684a4422015-04-15 16:18:39 -07001080 return VISIBLE_TYPE_HEADSUP;
Selim Cinek8d490d42015-04-10 00:05:50 -07001081 } else {
Selim Cinek684a4422015-04-15 16:18:39 -07001082 return VISIBLE_TYPE_EXPANDED;
Selim Cinek8d490d42015-04-10 00:05:50 -07001083 }
1084 } else {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001085 if (noExpandedChild || (viewHeight <= getViewHeight(VISIBLE_TYPE_CONTRACTED)
Selim Cinek6ac3fa82016-05-10 17:11:54 -04001086 && (!mIsChildInGroup || isGroupExpanded()
Selim Cineke81b82b2016-03-04 11:22:28 -08001087 || !mContainingNotification.isExpanded(true /* allowOnKeyguard */)))) {
Selim Cinek684a4422015-04-15 16:18:39 -07001088 return VISIBLE_TYPE_CONTRACTED;
Selim Cinek8d490d42015-04-10 00:05:50 -07001089 } else {
Selim Cinek684a4422015-04-15 16:18:39 -07001090 return VISIBLE_TYPE_EXPANDED;
Selim Cinek8d490d42015-04-10 00:05:50 -07001091 }
1092 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001093 }
1094
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001095 public boolean isContentExpandable() {
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001096 return mIsContentExpandable;
Jorim Jaggi4222d9a2014-04-23 16:13:15 +02001097 }
John Spurlocke15452b2014-08-21 09:44:39 -04001098
Jorim Jaggi4e857f42014-11-17 19:14:04 +01001099 public void setDark(boolean dark, boolean fade, long delay) {
Selim Cinekb88b9842016-02-26 09:25:33 -08001100 if (mContractedChild == null) {
Selim Cinek0934bd92016-02-19 12:22:33 -08001101 return;
1102 }
John Spurlocke15452b2014-08-21 09:44:39 -04001103 mDark = dark;
Selim Cinek19ba7052016-01-27 20:04:27 -08001104 if (mVisibleType == VISIBLE_TYPE_CONTRACTED || !dark) {
Selim Cinek30e387d2016-01-11 18:01:47 -08001105 mContractedWrapper.setDark(dark, fade, delay);
1106 }
Selim Cinek19ba7052016-01-27 20:04:27 -08001107 if (mVisibleType == VISIBLE_TYPE_EXPANDED || (mExpandedChild != null && !dark)) {
Selim Cinek30e387d2016-01-11 18:01:47 -08001108 mExpandedWrapper.setDark(dark, fade, delay);
1109 }
Selim Cinek19ba7052016-01-27 20:04:27 -08001110 if (mVisibleType == VISIBLE_TYPE_HEADSUP || (mHeadsUpChild != null && !dark)) {
Selim Cinek30e387d2016-01-11 18:01:47 -08001111 mHeadsUpWrapper.setDark(dark, fade, delay);
1112 }
Selim Cinek19ba7052016-01-27 20:04:27 -08001113 if (mSingleLineView != null && (mVisibleType == VISIBLE_TYPE_SINGLELINE || !dark)) {
Selim Cinek9c7712d2015-12-08 19:19:48 -08001114 mSingleLineView.setDark(dark, fade, delay);
1115 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08001116 selectLayout(!dark && fade /* animate */, false /* force */);
John Spurlocke15452b2014-08-21 09:44:39 -04001117 }
1118
Selim Cinek8d490d42015-04-10 00:05:50 -07001119 public void setHeadsUp(boolean headsUp) {
1120 mIsHeadsUp = headsUp;
1121 selectLayout(false /* animate */, true /* force */);
Selim Cinek98be3f32015-12-17 16:39:06 -08001122 updateExpandButtons(mExpandable);
Selim Cinek8d490d42015-04-10 00:05:50 -07001123 }
1124
Jorim Jaggiaa92ffb2014-09-10 23:29:28 +02001125 @Override
1126 public boolean hasOverlappingRendering() {
1127
1128 // This is not really true, but good enough when fading from the contracted to the expanded
1129 // layout, and saves us some layers.
1130 return false;
1131 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001132
Selim Cinek1a48bab2017-02-17 19:38:40 -08001133 public void setLegacy(boolean legacy) {
1134 mLegacy = legacy;
1135 updateLegacy();
Selim Cinekc3179332016-03-04 14:44:56 -08001136 }
1137
Selim Cinek1a48bab2017-02-17 19:38:40 -08001138 private void updateLegacy() {
Selim Cinekc3179332016-03-04 14:44:56 -08001139 if (mContractedChild != null) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08001140 mContractedWrapper.setLegacy(mLegacy);
Selim Cinekc3179332016-03-04 14:44:56 -08001141 }
1142 if (mExpandedChild != null) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08001143 mExpandedWrapper.setLegacy(mLegacy);
Selim Cinekc3179332016-03-04 14:44:56 -08001144 }
1145 if (mHeadsUpChild != null) {
Selim Cinek1a48bab2017-02-17 19:38:40 -08001146 mHeadsUpWrapper.setLegacy(mLegacy);
Selim Cinekc3179332016-03-04 14:44:56 -08001147 }
Jorim Jaggi59ec3042015-06-05 15:18:43 -07001148 }
Selim Cinek8d6440d2015-10-22 13:00:05 -07001149
Selim Cinek83bc7832015-10-22 13:26:54 -07001150 public void setIsChildInGroup(boolean isChildInGroup) {
1151 mIsChildInGroup = isChildInGroup;
Selim Cinek414ad332017-02-24 19:06:12 -08001152 if (mContractedChild != null) {
1153 mContractedWrapper.setIsChildInGroup(mIsChildInGroup);
1154 }
1155 if (mExpandedChild != null) {
1156 mExpandedWrapper.setIsChildInGroup(mIsChildInGroup);
1157 }
1158 if (mHeadsUpChild != null) {
1159 mHeadsUpWrapper.setIsChildInGroup(mIsChildInGroup);
1160 }
1161 if (mAmbientChild != null) {
1162 mAmbientWrapper.setIsChildInGroup(mIsChildInGroup);
1163 }
Adrian Roos6f6e1592017-05-02 16:22:53 -07001164 updateAllSingleLineViews();
Selim Cinek83bc7832015-10-22 13:26:54 -07001165 }
1166
Adrian Roosb88b1a12015-12-09 18:51:05 -08001167 public void onNotificationUpdated(NotificationData.Entry entry) {
1168 mStatusBarNotification = entry.notification;
Selim Cinek860b6da2015-12-16 19:02:19 -08001169 mBeforeN = entry.targetSdk < Build.VERSION_CODES.N;
Adrian Roos6f6e1592017-05-02 16:22:53 -07001170 updateAllSingleLineViews();
Selim Cinek8fc93c92015-11-23 17:48:07 -08001171 if (mContractedChild != null) {
Selim Cinek131f1a42017-06-05 17:50:19 -07001172 mContractedWrapper.onContentUpdated(entry.row);
Selim Cinek8fc93c92015-11-23 17:48:07 -08001173 }
1174 if (mExpandedChild != null) {
Selim Cinek131f1a42017-06-05 17:50:19 -07001175 mExpandedWrapper.onContentUpdated(entry.row);
Selim Cinek8fc93c92015-11-23 17:48:07 -08001176 }
1177 if (mHeadsUpChild != null) {
Selim Cinek131f1a42017-06-05 17:50:19 -07001178 mHeadsUpWrapper.onContentUpdated(entry.row);
Selim Cinek8fc93c92015-11-23 17:48:07 -08001179 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08001180 if (mAmbientChild != null) {
Selim Cinek131f1a42017-06-05 17:50:19 -07001181 mAmbientWrapper.onContentUpdated(entry.row);
Adrian Roos0aac04f2016-12-08 15:59:29 -08001182 }
Petr Cermak7997d7a2018-01-18 15:52:10 +00001183 applyRemoteInputAndSmartReply(entry);
Selim Cinek1a48bab2017-02-17 19:38:40 -08001184 updateLegacy();
Selim Cinek589fd3e2016-04-26 18:17:57 -07001185 mForceSelectNextLayout = true;
Selim Cinekb88b9842016-02-26 09:25:33 -08001186 setDark(mDark, false /* animate */, 0 /* delay */);
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001187 mPreviousExpandedRemoteInputIntent = null;
1188 mPreviousHeadsUpRemoteInputIntent = null;
Selim Cinek83bc7832015-10-22 13:26:54 -07001189 }
1190
Adrian Roos6f6e1592017-05-02 16:22:53 -07001191 private void updateAllSingleLineViews() {
1192 updateSingleLineView();
1193 updateAmbientSingleLineView();
1194 }
Selim Cinek83bc7832015-10-22 13:26:54 -07001195 private void updateSingleLineView() {
1196 if (mIsChildInGroup) {
Selim Cinekc897bd32016-03-18 17:32:31 -07001197 mSingleLineView = mHybridGroupManager.bindFromNotification(
Selim Cinek83bc7832015-10-22 13:26:54 -07001198 mSingleLineView, mStatusBarNotification.getNotification());
Selim Cinekde33a4a2016-02-11 16:43:41 -08001199 } else if (mSingleLineView != null) {
1200 removeView(mSingleLineView);
1201 mSingleLineView = null;
Selim Cinek83bc7832015-10-22 13:26:54 -07001202 }
1203 }
1204
Adrian Roos6f6e1592017-05-02 16:22:53 -07001205 private void updateAmbientSingleLineView() {
1206 if (mIsChildInGroup) {
1207 mAmbientSingleLineChild = mHybridGroupManager.bindAmbientFromNotification(
1208 mAmbientSingleLineChild, mStatusBarNotification.getNotification());
1209 } else if (mAmbientSingleLineChild != null) {
1210 removeView(mAmbientSingleLineChild);
1211 mAmbientSingleLineChild = null;
1212 }
1213 }
1214
Petr Cermak7997d7a2018-01-18 15:52:10 +00001215 private void applyRemoteInputAndSmartReply(final NotificationData.Entry entry) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001216 if (mRemoteInputController == null) {
1217 return;
1218 }
1219
Richard Ledley4069f7a2018-02-26 10:36:00 +00001220 boolean enableSmartReplies = (mSmartReplyConstants.isEnabled()
1221 && (!mSmartReplyConstants.requiresTargetingP()
1222 || entry.targetSdk >= Build.VERSION_CODES.P));
Petr Cermak7997d7a2018-01-18 15:52:10 +00001223
Adrian Roosb88b1a12015-12-09 18:51:05 -08001224 boolean hasRemoteInput = false;
Petr Cermak7997d7a2018-01-18 15:52:10 +00001225 RemoteInput remoteInputWithChoices = null;
1226 PendingIntent pendingIntentWithChoices = null;
Adrian Roosb88b1a12015-12-09 18:51:05 -08001227
1228 Notification.Action[] actions = entry.notification.getNotification().actions;
1229 if (actions != null) {
1230 for (Notification.Action a : actions) {
1231 if (a.getRemoteInputs() != null) {
1232 for (RemoteInput ri : a.getRemoteInputs()) {
Petr Cermak7997d7a2018-01-18 15:52:10 +00001233 boolean showRemoteInputView = ri.getAllowFreeFormInput();
1234 boolean showSmartReplyView = enableSmartReplies && ri.getChoices() != null
1235 && ri.getChoices().length > 0;
1236 if (showRemoteInputView) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001237 hasRemoteInput = true;
Petr Cermak7997d7a2018-01-18 15:52:10 +00001238 }
1239 if (showSmartReplyView) {
1240 remoteInputWithChoices = ri;
1241 pendingIntentWithChoices = a.actionIntent;
1242 }
1243 if (showRemoteInputView || showSmartReplyView) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001244 break;
1245 }
1246 }
1247 }
1248 }
1249 }
1250
Petr Cermak7997d7a2018-01-18 15:52:10 +00001251 applyRemoteInput(entry, hasRemoteInput);
Kenny Guy23991102018-04-05 21:18:38 +01001252 applySmartReplyView(remoteInputWithChoices, pendingIntentWithChoices, entry);
Petr Cermak7997d7a2018-01-18 15:52:10 +00001253 }
1254
1255 private void applyRemoteInput(NotificationData.Entry entry, boolean hasRemoteInput) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001256 View bigContentView = mExpandedChild;
1257 if (bigContentView != null) {
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001258 mExpandedRemoteInput = applyRemoteInput(bigContentView, entry, hasRemoteInput,
Adrian Roos7b9ed0d2017-01-24 15:55:18 -08001259 mPreviousExpandedRemoteInputIntent, mCachedExpandedRemoteInput,
1260 mExpandedWrapper);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001261 } else {
1262 mExpandedRemoteInput = null;
Adrian Roosb88b1a12015-12-09 18:51:05 -08001263 }
Adrian Roos7813dd72016-09-23 17:12:17 -07001264 if (mCachedExpandedRemoteInput != null
1265 && mCachedExpandedRemoteInput != mExpandedRemoteInput) {
1266 // We had a cached remote input but didn't reuse it. Clean up required.
1267 mCachedExpandedRemoteInput.dispatchFinishTemporaryDetach();
1268 }
1269 mCachedExpandedRemoteInput = null;
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001270
Adrian Roosb88b1a12015-12-09 18:51:05 -08001271 View headsUpContentView = mHeadsUpChild;
1272 if (headsUpContentView != null) {
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001273 mHeadsUpRemoteInput = applyRemoteInput(headsUpContentView, entry, hasRemoteInput,
Adrian Roos7b9ed0d2017-01-24 15:55:18 -08001274 mPreviousHeadsUpRemoteInputIntent, mCachedHeadsUpRemoteInput, mHeadsUpWrapper);
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001275 } else {
1276 mHeadsUpRemoteInput = null;
Adrian Roosb88b1a12015-12-09 18:51:05 -08001277 }
Adrian Roos7813dd72016-09-23 17:12:17 -07001278 if (mCachedHeadsUpRemoteInput != null
1279 && mCachedHeadsUpRemoteInput != mHeadsUpRemoteInput) {
1280 // We had a cached remote input but didn't reuse it. Clean up required.
1281 mCachedHeadsUpRemoteInput.dispatchFinishTemporaryDetach();
1282 }
1283 mCachedHeadsUpRemoteInput = null;
Adrian Roosb88b1a12015-12-09 18:51:05 -08001284 }
1285
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001286 private RemoteInputView applyRemoteInput(View view, NotificationData.Entry entry,
Adrian Roos7813dd72016-09-23 17:12:17 -07001287 boolean hasRemoteInput, PendingIntent existingPendingIntent,
Adrian Roos7b9ed0d2017-01-24 15:55:18 -08001288 RemoteInputView cachedView, NotificationViewWrapper wrapper) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001289 View actionContainerCandidate = view.findViewById(
1290 com.android.internal.R.id.actions_container);
1291 if (actionContainerCandidate instanceof FrameLayout) {
1292 RemoteInputView existing = (RemoteInputView)
1293 view.findViewWithTag(RemoteInputView.VIEW_TAG);
1294
1295 if (existing != null) {
Adrian Roos0789ee02016-06-01 11:34:58 -07001296 existing.onNotificationUpdateOrReset();
Adrian Roosb88b1a12015-12-09 18:51:05 -08001297 }
1298
1299 if (existing == null && hasRemoteInput) {
1300 ViewGroup actionContainer = (FrameLayout) actionContainerCandidate;
Adrian Roos7813dd72016-09-23 17:12:17 -07001301 if (cachedView == null) {
1302 RemoteInputView riv = RemoteInputView.inflate(
1303 mContext, actionContainer, entry, mRemoteInputController);
Adrian Roosb88b1a12015-12-09 18:51:05 -08001304
Adrian Roos7813dd72016-09-23 17:12:17 -07001305 riv.setVisibility(View.INVISIBLE);
1306 actionContainer.addView(riv, new LayoutParams(
1307 ViewGroup.LayoutParams.MATCH_PARENT,
1308 ViewGroup.LayoutParams.MATCH_PARENT)
1309 );
1310 existing = riv;
1311 } else {
1312 actionContainer.addView(cachedView);
1313 cachedView.dispatchFinishTemporaryDetach();
1314 cachedView.requestFocus();
1315 existing = cachedView;
1316 }
Adrian Roos4ff3b122016-02-01 12:26:13 -08001317 }
1318 if (hasRemoteInput) {
Adrian Roosb88b1a12015-12-09 18:51:05 -08001319 int color = entry.notification.getNotification().color;
1320 if (color == Notification.COLOR_DEFAULT) {
1321 color = mContext.getColor(R.color.default_remote_input_background);
1322 }
Adrian Roos4ff3b122016-02-01 12:26:13 -08001323 existing.setBackgroundColor(NotificationColorUtil.ensureTextBackgroundColor(color,
Adrian Roos25ea5b82016-04-27 16:34:35 -07001324 mContext.getColor(R.color.remote_input_text_enabled),
Adrian Roos4ff3b122016-02-01 12:26:13 -08001325 mContext.getColor(R.color.remote_input_hint)));
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001326
Adrian Roos7b9ed0d2017-01-24 15:55:18 -08001327 existing.setWrapper(wrapper);
Selim Cineked64a142018-02-06 18:06:01 -08001328 existing.setOnVisibilityChangedListener(this::setRemoteInputVisible);
Adrian Roos7b9ed0d2017-01-24 15:55:18 -08001329
Adrian Roos4c1fcc82016-03-31 14:39:39 -07001330 if (existingPendingIntent != null || existing.isActive()) {
1331 // The current action could be gone, or the pending intent no longer valid.
1332 // If we find a matching action in the new notification, focus, otherwise close.
1333 Notification.Action[] actions = entry.notification.getNotification().actions;
1334 if (existingPendingIntent != null) {
1335 existing.setPendingIntent(existingPendingIntent);
1336 }
1337 if (existing.updatePendingIntentFromActions(actions)) {
1338 if (!existing.isActive()) {
1339 existing.focus();
1340 }
1341 } else {
1342 if (existing.isActive()) {
1343 existing.close();
1344 }
1345 }
1346 }
Adrian Roosb88b1a12015-12-09 18:51:05 -08001347 }
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001348 return existing;
1349 }
1350 return null;
1351 }
1352
Kenny Guy23991102018-04-05 21:18:38 +01001353 private void applySmartReplyView(RemoteInput remoteInput, PendingIntent pendingIntent,
1354 NotificationData.Entry entry) {
1355 if (mExpandedChild != null) {
Milo Sredkove7cf4982018-04-09 15:08:26 +01001356 mExpandedSmartReplyView =
Kenny Guy23991102018-04-05 21:18:38 +01001357 applySmartReplyView(mExpandedChild, remoteInput, pendingIntent, entry);
Milo Sredkove7cf4982018-04-09 15:08:26 +01001358 if (mExpandedSmartReplyView != null && remoteInput != null
1359 && remoteInput.getChoices() != null && remoteInput.getChoices().length > 0) {
Kenny Guy23991102018-04-05 21:18:38 +01001360 mSmartReplyLogger.smartRepliesAdded(entry, remoteInput.getChoices().length);
1361 }
1362 }
Petr Cermak7997d7a2018-01-18 15:52:10 +00001363 }
1364
1365 private SmartReplyView applySmartReplyView(
Kenny Guy23991102018-04-05 21:18:38 +01001366 View view, RemoteInput remoteInput, PendingIntent pendingIntent,
1367 NotificationData.Entry entry) {
Petr Cermak7997d7a2018-01-18 15:52:10 +00001368 View smartReplyContainerCandidate = view.findViewById(
1369 com.android.internal.R.id.smart_reply_container);
1370 if (!(smartReplyContainerCandidate instanceof LinearLayout)) {
1371 return null;
1372 }
1373 LinearLayout smartReplyContainer = (LinearLayout) smartReplyContainerCandidate;
1374 if (remoteInput == null || pendingIntent == null) {
1375 smartReplyContainer.setVisibility(View.GONE);
1376 return null;
1377 }
1378 SmartReplyView smartReplyView = null;
1379 if (smartReplyContainer.getChildCount() == 0) {
1380 smartReplyView = SmartReplyView.inflate(mContext, smartReplyContainer);
1381 smartReplyContainer.addView(smartReplyView);
1382 } else if (smartReplyContainer.getChildCount() == 1) {
1383 View child = smartReplyContainer.getChildAt(0);
1384 if (child instanceof SmartReplyView) {
1385 smartReplyView = (SmartReplyView) child;
1386 }
1387 }
1388 if (smartReplyView != null) {
Kenny Guy23991102018-04-05 21:18:38 +01001389 smartReplyView.setRepliesFromRemoteInput(remoteInput, pendingIntent,
1390 mSmartReplyLogger, entry);
Petr Cermak7997d7a2018-01-18 15:52:10 +00001391 smartReplyContainer.setVisibility(View.VISIBLE);
1392 }
1393 return smartReplyView;
1394 }
1395
Adrian Roos0bd8a4b2016-03-14 16:21:44 -07001396 public void closeRemoteInput() {
1397 if (mHeadsUpRemoteInput != null) {
1398 mHeadsUpRemoteInput.close();
1399 }
1400 if (mExpandedRemoteInput != null) {
1401 mExpandedRemoteInput.close();
Adrian Roosb88b1a12015-12-09 18:51:05 -08001402 }
1403 }
1404
Selim Cinek83bc7832015-10-22 13:26:54 -07001405 public void setGroupManager(NotificationGroupManager groupManager) {
1406 mGroupManager = groupManager;
1407 }
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001408
Adrian Roosb88b1a12015-12-09 18:51:05 -08001409 public void setRemoteInputController(RemoteInputController r) {
1410 mRemoteInputController = r;
1411 }
1412
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001413 public void setExpandClickListener(OnClickListener expandClickListener) {
1414 mExpandClickListener = expandClickListener;
1415 }
1416
1417 public void updateExpandButtons(boolean expandable) {
Selim Cinek98be3f32015-12-17 16:39:06 -08001418 mExpandable = expandable;
1419 // if the expanded child has the same height as the collapsed one we hide it.
Selim Cinek8ea2d5f2016-04-20 17:10:40 -07001420 if (mExpandedChild != null && mExpandedChild.getHeight() != 0) {
Selim Cinek4ca6c632017-02-23 18:03:37 -08001421 if ((!mIsHeadsUp && !mHeadsUpAnimatingAway)
1422 || mHeadsUpChild == null || mContainingNotification.isOnKeyguard()) {
Selim Cinek9635cf32017-03-03 16:59:03 -08001423 if (mExpandedChild.getHeight() <= mContractedChild.getHeight()) {
Selim Cinek8ea2d5f2016-04-20 17:10:40 -07001424 expandable = false;
1425 }
Selim Cinek9635cf32017-03-03 16:59:03 -08001426 } else if (mExpandedChild.getHeight() <= mHeadsUpChild.getHeight()) {
Selim Cinek8ea2d5f2016-04-20 17:10:40 -07001427 expandable = false;
1428 }
Selim Cinek98be3f32015-12-17 16:39:06 -08001429 }
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001430 if (mExpandedChild != null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001431 mExpandedWrapper.updateExpandability(expandable, mExpandClickListener);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001432 }
1433 if (mContractedChild != null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001434 mContractedWrapper.updateExpandability(expandable, mExpandClickListener);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001435 }
1436 if (mHeadsUpChild != null) {
Selim Cinekeaa29ca2015-11-23 13:51:13 -08001437 mHeadsUpWrapper.updateExpandability(expandable, mExpandClickListener);
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001438 }
Selim Cinekc0ac4af2017-03-03 15:13:48 -08001439 mIsContentExpandable = expandable;
Selim Cinek65b2e7c2015-10-26 14:11:31 -07001440 }
Selim Cinekea4bef72015-12-02 15:51:10 -08001441
1442 public NotificationHeaderView getNotificationHeader() {
1443 NotificationHeaderView header = null;
1444 if (mContractedChild != null) {
1445 header = mContractedWrapper.getNotificationHeader();
1446 }
1447 if (header == null && mExpandedChild != null) {
1448 header = mExpandedWrapper.getNotificationHeader();
1449 }
1450 if (header == null && mHeadsUpChild != null) {
1451 header = mHeadsUpWrapper.getNotificationHeader();
1452 }
Adrian Roos0aac04f2016-12-08 15:59:29 -08001453 if (header == null && mAmbientChild != null) {
1454 header = mAmbientWrapper.getNotificationHeader();
1455 }
Selim Cinekea4bef72015-12-02 15:51:10 -08001456 return header;
1457 }
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001458
Julia Reynoldsfc640012018-02-21 12:25:27 -05001459 public void showAppOpsIcons(ArraySet<Integer> activeOps) {
1460 if (mContractedChild != null && mContractedWrapper.getNotificationHeader() != null) {
1461 mContractedWrapper.getNotificationHeader().showAppOpsIcons(activeOps);
1462 }
1463 if (mExpandedChild != null && mExpandedWrapper.getNotificationHeader() != null) {
1464 mExpandedWrapper.getNotificationHeader().showAppOpsIcons(activeOps);
1465 }
1466 if (mHeadsUpChild != null && mHeadsUpWrapper.getNotificationHeader() != null) {
1467 mHeadsUpWrapper.getNotificationHeader().showAppOpsIcons(activeOps);
1468 }
1469 }
Selim Cinekb26afa32017-06-29 10:28:17 +02001470
1471 public NotificationHeaderView getContractedNotificationHeader() {
1472 if (mContractedChild != null) {
1473 return mContractedWrapper.getNotificationHeader();
1474 }
1475 return null;
1476 }
1477
Selim Cinek34eda5e2016-02-18 17:10:43 -08001478 public NotificationHeaderView getVisibleNotificationHeader() {
Selim Cinekc3179332016-03-04 14:44:56 -08001479 NotificationViewWrapper wrapper = getVisibleWrapper(mVisibleType);
Selim Cinek34eda5e2016-02-18 17:10:43 -08001480 return wrapper == null ? null : wrapper.getNotificationHeader();
1481 }
1482
Selim Cinekfa0a2d32016-01-14 13:02:21 -08001483 public void setContainingNotification(ExpandableNotificationRow containingNotification) {
1484 mContainingNotification = containingNotification;
1485 }
1486
1487 public void requestSelectLayout(boolean needsAnimation) {
1488 selectLayout(needsAnimation, false);
1489 }
Selim Cinekde33a4a2016-02-11 16:43:41 -08001490
1491 public void reInflateViews() {
1492 if (mIsChildInGroup && mSingleLineView != null) {
1493 removeView(mSingleLineView);
1494 mSingleLineView = null;
Adrian Roos6f6e1592017-05-02 16:22:53 -07001495 updateAllSingleLineViews();
Selim Cinekde33a4a2016-02-11 16:43:41 -08001496 }
1497 }
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001498
1499 public void setUserExpanding(boolean userExpanding) {
1500 mUserExpanding = userExpanding;
1501 if (userExpanding) {
1502 mTransformationStartVisibleType = mVisibleType;
1503 } else {
1504 mTransformationStartVisibleType = UNDEFINED;
1505 mVisibleType = calculateVisibleType();
1506 updateViewVisibilities(mVisibleType);
Selim Cinekc3179332016-03-04 14:44:56 -08001507 updateBackgroundColor(false);
Selim Cinek8f2f6a62016-02-23 19:56:31 -08001508 }
1509 }
Selim Cinekc897bd32016-03-18 17:32:31 -07001510
1511 /**
1512 * Set by how much the single line view should be indented. Used when a overflow indicator is
1513 * present and only during measuring
1514 */
1515 public void setSingleLineWidthIndention(int singleLineWidthIndention) {
1516 if (singleLineWidthIndention != mSingleLineWidthIndention) {
1517 mSingleLineWidthIndention = singleLineWidthIndention;
1518 mContainingNotification.forceLayout();
1519 forceLayout();
1520 }
1521 }
1522
1523 public HybridNotificationView getSingleLineView() {
1524 return mSingleLineView;
1525 }
Adrian Roosd009ab12016-05-20 17:58:53 -07001526
1527 public void setRemoved() {
1528 if (mExpandedRemoteInput != null) {
1529 mExpandedRemoteInput.setRemoved();
1530 }
1531 if (mHeadsUpRemoteInput != null) {
1532 mHeadsUpRemoteInput.setRemoved();
1533 }
1534 }
Adrian Roos599be342016-06-13 14:54:39 -07001535
1536 public void setContentHeightAnimating(boolean animating) {
1537 if (!animating) {
1538 mContentHeightAtAnimationStart = UNDEFINED;
1539 }
1540 }
Selim Cineke9bad242016-06-15 11:46:37 -07001541
Adrian Roose18033c2017-01-17 15:22:49 -08001542 @VisibleForTesting
1543 boolean isAnimatingVisibleType() {
1544 return mAnimationStartVisibleType != UNDEFINED;
1545 }
1546
Selim Cinekcafa87f2016-10-26 17:00:17 -07001547 public void setHeadsUpAnimatingAway(boolean headsUpAnimatingAway) {
1548 mHeadsUpAnimatingAway = headsUpAnimatingAway;
Selim Cinek73cf02a2016-06-17 13:08:00 -07001549 selectLayout(false /* animate */, true /* force */);
1550 }
1551
Selim Cineke9bad242016-06-15 11:46:37 -07001552 public void setFocusOnVisibilityChange() {
1553 mFocusOnVisibilityChange = true;
1554 }
Selim Cinek0242fbb2016-10-19 13:38:32 -07001555
1556 public void setIconsVisible(boolean iconsVisible) {
1557 mIconsVisible = iconsVisible;
1558 updateIconVisibilities();
1559 }
1560
1561 private void updateIconVisibilities() {
1562 if (mContractedWrapper != null) {
1563 NotificationHeaderView header = mContractedWrapper.getNotificationHeader();
1564 if (header != null) {
1565 header.getIcon().setForceHidden(!mIconsVisible);
1566 }
1567 }
1568 if (mHeadsUpWrapper != null) {
1569 NotificationHeaderView header = mHeadsUpWrapper.getNotificationHeader();
1570 if (header != null) {
1571 header.getIcon().setForceHidden(!mIconsVisible);
1572 }
1573 }
1574 if (mExpandedWrapper != null) {
1575 NotificationHeaderView header = mExpandedWrapper.getNotificationHeader();
1576 if (header != null) {
1577 header.getIcon().setForceHidden(!mIconsVisible);
1578 }
1579 }
1580 }
Selim Cinek6743c0b2017-01-18 18:24:01 -08001581
Adrian Roos4320e892017-01-24 12:50:34 -08001582 @Override
1583 public void onVisibilityAggregated(boolean isVisible) {
1584 super.onVisibilityAggregated(isVisible);
1585 if (isVisible) {
1586 fireExpandedVisibleListenerIfVisible();
1587 }
1588 }
1589
1590 /**
1591 * Sets a one-shot listener for when the expanded view becomes visible.
1592 *
1593 * This will fire the listener immediately if the expanded view is already visible.
1594 */
1595 public void setOnExpandedVisibleListener(Runnable r) {
1596 mExpandedVisibleListener = r;
1597 fireExpandedVisibleListenerIfVisible();
1598 }
1599
Selim Cinek6743c0b2017-01-18 18:24:01 -08001600 public void setIsLowPriority(boolean isLowPriority) {
1601 mIsLowPriority = isLowPriority;
1602 }
Selim Cinek63edaf22017-04-24 22:18:48 -07001603
1604 public boolean isDimmable() {
1605 if (!mContractedWrapper.isDimmable()) {
1606 return false;
1607 }
1608 return true;
1609 }
Selim Cinek5d6ef8d2017-05-18 22:16:00 -07001610
1611 /**
1612 * Should a single click be disallowed on this view when on the keyguard?
1613 */
1614 public boolean disallowSingleClick(float x, float y) {
1615 NotificationViewWrapper visibleWrapper = getVisibleWrapper(getVisibleType());
1616 if (visibleWrapper != null) {
1617 return visibleWrapper.disallowSingleClick(x, y);
1618 }
1619 return false;
1620 }
Selim Cinek515b2032017-11-15 10:20:19 -08001621
Selim Cinek86bfcee2018-01-17 11:00:47 -08001622 public boolean shouldClipToRounding(boolean topRounded, boolean bottomRounded) {
1623 boolean needsPaddings = shouldClipToRounding(getVisibleType(), topRounded, bottomRounded);
Selim Cinek515b2032017-11-15 10:20:19 -08001624 if (mUserExpanding) {
Selim Cinek86bfcee2018-01-17 11:00:47 -08001625 needsPaddings |= shouldClipToRounding(mTransformationStartVisibleType, topRounded,
1626 bottomRounded);
Selim Cinek515b2032017-11-15 10:20:19 -08001627 }
1628 return needsPaddings;
1629 }
1630
Selim Cinek86bfcee2018-01-17 11:00:47 -08001631 private boolean shouldClipToRounding(int visibleType, boolean topRounded,
1632 boolean bottomRounded) {
Selim Cinek515b2032017-11-15 10:20:19 -08001633 NotificationViewWrapper visibleWrapper = getVisibleWrapper(visibleType);
1634 if (visibleWrapper == null) {
1635 return false;
1636 }
Selim Cinek86bfcee2018-01-17 11:00:47 -08001637 return visibleWrapper.shouldClipToRounding(topRounded, bottomRounded);
Selim Cinek515b2032017-11-15 10:20:19 -08001638 }
Selim Cinekde4de0e2018-01-24 16:21:07 -08001639
1640 public CharSequence getActiveRemoteInputText() {
1641 if (mExpandedRemoteInput != null && mExpandedRemoteInput.isActive()) {
1642 return mExpandedRemoteInput.getText();
1643 }
1644 if (mHeadsUpRemoteInput != null && mHeadsUpRemoteInput.isActive()) {
1645 return mHeadsUpRemoteInput.getText();
1646 }
1647 return null;
1648 }
Selim Cineked64a142018-02-06 18:06:01 -08001649
Selim Cineka77d2c52018-04-09 10:44:52 -07001650 @Override
1651 public boolean dispatchTouchEvent(MotionEvent ev) {
1652 float y = ev.getY();
1653 // We still want to distribute touch events to the remote input even if it's outside the
1654 // view boundary. We're therefore manually dispatching these events to the remote view
1655 RemoteInputView riv = getRemoteInputForView(getViewForVisibleType(mVisibleType));
1656 if (riv != null && riv.getVisibility() == VISIBLE) {
1657 int inputStart = mUnrestrictedContentHeight - riv.getHeight();
1658 if (y <= mUnrestrictedContentHeight && y >= inputStart) {
1659 ev.offsetLocation(0, -inputStart);
1660 return riv.dispatchTouchEvent(ev);
1661 }
1662 }
1663 return super.dispatchTouchEvent(ev);
1664 }
1665
1666 /**
1667 * Overridden to make sure touches to the reply action bar actually go through to this view
1668 */
1669 @Override
1670 public boolean pointInView(float localX, float localY, float slop) {
1671 float top = mClipTopAmount;
1672 float bottom = mUnrestrictedContentHeight;
1673 return localX >= -slop && localY >= top - slop && localX < ((mRight - mLeft) + slop) &&
1674 localY < (bottom + slop);
1675 }
1676
1677 private RemoteInputView getRemoteInputForView(View child) {
1678 if (child == mExpandedChild) {
1679 return mExpandedRemoteInput;
1680 } else if (child == mHeadsUpChild) {
1681 return mHeadsUpRemoteInput;
1682 }
1683 return null;
1684 }
1685
Selim Cineked64a142018-02-06 18:06:01 -08001686 public int getExpandHeight() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001687 int viewType = VISIBLE_TYPE_EXPANDED;
1688 if (mExpandedChild == null) {
1689 viewType = VISIBLE_TYPE_CONTRACTED;
Selim Cineked64a142018-02-06 18:06:01 -08001690 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001691 return getViewHeight(viewType) + getExtraRemoteInputHeight(mExpandedRemoteInput);
Selim Cineked64a142018-02-06 18:06:01 -08001692 }
1693
1694 public int getHeadsUpHeight() {
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001695 int viewType = VISIBLE_TYPE_HEADSUP;
1696 if (mHeadsUpChild == null) {
1697 viewType = VISIBLE_TYPE_CONTRACTED;
Selim Cineked64a142018-02-06 18:06:01 -08001698 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001699 return getViewHeight(viewType) + getExtraRemoteInputHeight(mHeadsUpRemoteInput);
Selim Cineked64a142018-02-06 18:06:01 -08001700 }
1701
1702 public void setRemoteInputVisible(boolean remoteInputVisible) {
1703 mRemoteInputVisible = remoteInputVisible;
1704 setClipChildren(!remoteInputVisible);
1705 }
1706
1707 @Override
1708 public void setClipChildren(boolean clipChildren) {
1709 clipChildren = clipChildren && !mRemoteInputVisible;
1710 super.setClipChildren(clipChildren);
1711 }
Selim Cinekaa9db1f2018-02-27 17:35:47 -08001712
1713 public void setHeaderVisibleAmount(float headerVisibleAmount) {
1714 if (mContractedWrapper != null) {
1715 mContractedWrapper.setHeaderVisibleAmount(headerVisibleAmount);
1716 }
1717 if (mHeadsUpWrapper != null) {
1718 mHeadsUpWrapper.setHeaderVisibleAmount(headerVisibleAmount);
1719 }
1720 if (mExpandedWrapper != null) {
1721 mExpandedWrapper.setHeaderVisibleAmount(headerVisibleAmount);
1722 }
1723 }
Jorim Jaggibe565df2014-04-28 17:51:23 +02001724}