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