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