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