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