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