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