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