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