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