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