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