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 | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 478 | private NotificationViewWrapper getCurrentVisibleWrapper() { |
| 479 | switch (mVisibleType) { |
| 480 | case VISIBLE_TYPE_EXPANDED: |
| 481 | return mExpandedWrapper; |
| 482 | case VISIBLE_TYPE_HEADSUP: |
| 483 | return mHeadsUpWrapper; |
| 484 | case VISIBLE_TYPE_CONTRACTED: |
| 485 | return mContractedWrapper; |
| 486 | default: |
| 487 | return null; |
| 488 | } |
| 489 | } |
| 490 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 491 | /** |
| 492 | * @return one of the static enum types in this view, calculated form the current state |
| 493 | */ |
| 494 | private int calculateVisibleType() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 495 | boolean noExpandedChild = mExpandedChild == null; |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 496 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 497 | int viewHeight = Math.min(mContentHeight, mContainingNotification.getIntrinsicHeight()); |
| 498 | if (!noExpandedChild && viewHeight == mExpandedChild.getHeight()) { |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 499 | return VISIBLE_TYPE_EXPANDED; |
| 500 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 501 | if (mIsChildInGroup && !isGroupExpanded()) { |
| 502 | return VISIBLE_TYPE_SINGLELINE; |
| 503 | } |
Adrian Roos | 777ef56 | 2015-12-01 17:37:14 -0800 | [diff] [blame] | 504 | |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 505 | if (mIsHeadsUp && mHeadsUpChild != null) { |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 506 | if (viewHeight <= mHeadsUpChild.getHeight() || noExpandedChild) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 507 | return VISIBLE_TYPE_HEADSUP; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 508 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 509 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 510 | } |
| 511 | } else { |
Selim Cinek | a409150 | 2016-02-11 17:21:16 -0800 | [diff] [blame] | 512 | if (noExpandedChild || (viewHeight <= mContractedChild.getHeight() |
| 513 | && (!mIsChildInGroup || !mContainingNotification.isExpanded()))) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 514 | return VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 515 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 516 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 519 | } |
| 520 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 521 | public boolean isContentExpandable() { |
| 522 | return mExpandedChild != null; |
| 523 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 524 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 525 | public void setDark(boolean dark, boolean fade, long delay) { |
John Spurlock | c3dfd32 | 2014-08-27 14:55:54 -0400 | [diff] [blame] | 526 | if (mDark == dark || mContractedChild == null) return; |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 527 | mDark = dark; |
Selim Cinek | 30e387d | 2016-01-11 18:01:47 -0800 | [diff] [blame] | 528 | dark = dark && !mShowingLegacyBackground; |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 529 | if (mVisibleType == VISIBLE_TYPE_CONTRACTED || !dark) { |
Selim Cinek | 30e387d | 2016-01-11 18:01:47 -0800 | [diff] [blame] | 530 | mContractedWrapper.setDark(dark, fade, delay); |
| 531 | } |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 532 | if (mVisibleType == VISIBLE_TYPE_EXPANDED || (mExpandedChild != null && !dark)) { |
Selim Cinek | 30e387d | 2016-01-11 18:01:47 -0800 | [diff] [blame] | 533 | mExpandedWrapper.setDark(dark, fade, delay); |
| 534 | } |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 535 | if (mVisibleType == VISIBLE_TYPE_HEADSUP || (mHeadsUpChild != null && !dark)) { |
Selim Cinek | 30e387d | 2016-01-11 18:01:47 -0800 | [diff] [blame] | 536 | mHeadsUpWrapper.setDark(dark, fade, delay); |
| 537 | } |
Selim Cinek | 19ba705 | 2016-01-27 20:04:27 -0800 | [diff] [blame] | 538 | if (mSingleLineView != null && (mVisibleType == VISIBLE_TYPE_SINGLELINE || !dark)) { |
Selim Cinek | 9c7712d | 2015-12-08 19:19:48 -0800 | [diff] [blame] | 539 | mSingleLineView.setDark(dark, fade, delay); |
| 540 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 541 | } |
| 542 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 543 | public void setHeadsUp(boolean headsUp) { |
| 544 | mIsHeadsUp = headsUp; |
| 545 | selectLayout(false /* animate */, true /* force */); |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 546 | updateExpandButtons(mExpandable); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jorim Jaggi | aa92ffb | 2014-09-10 23:29:28 +0200 | [diff] [blame] | 549 | @Override |
| 550 | public boolean hasOverlappingRendering() { |
| 551 | |
| 552 | // This is not really true, but good enough when fading from the contracted to the expanded |
| 553 | // layout, and saves us some layers. |
| 554 | return false; |
| 555 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 556 | |
| 557 | public void setShowingLegacyBackground(boolean showing) { |
| 558 | mShowingLegacyBackground = showing; |
| 559 | } |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 560 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 561 | public void setIsChildInGroup(boolean isChildInGroup) { |
| 562 | mIsChildInGroup = isChildInGroup; |
| 563 | updateSingleLineView(); |
| 564 | } |
| 565 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 566 | public void onNotificationUpdated(NotificationData.Entry entry) { |
| 567 | mStatusBarNotification = entry.notification; |
Selim Cinek | 860b6da | 2015-12-16 19:02:19 -0800 | [diff] [blame] | 568 | mBeforeN = entry.targetSdk < Build.VERSION_CODES.N; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 569 | updateSingleLineView(); |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 570 | applyRemoteInput(entry); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 571 | selectLayout(false /* animate */, true /* force */); |
| 572 | if (mContractedChild != null) { |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 573 | mContractedWrapper.notifyContentUpdated(entry.notification); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 574 | mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */); |
| 575 | } |
| 576 | if (mExpandedChild != null) { |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 577 | mExpandedWrapper.notifyContentUpdated(entry.notification); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 578 | } |
| 579 | if (mHeadsUpChild != null) { |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 580 | mHeadsUpWrapper.notifyContentUpdated(entry.notification); |
Selim Cinek | 8fc93c9 | 2015-11-23 17:48:07 -0800 | [diff] [blame] | 581 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | private void updateSingleLineView() { |
| 585 | if (mIsChildInGroup) { |
| 586 | mSingleLineView = mHybridViewManager.bindFromNotification( |
| 587 | mSingleLineView, mStatusBarNotification.getNotification()); |
Selim Cinek | de33a4a | 2016-02-11 16:43:41 -0800 | [diff] [blame] | 588 | } else if (mSingleLineView != null) { |
| 589 | removeView(mSingleLineView); |
| 590 | mSingleLineView = null; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 591 | } |
| 592 | } |
| 593 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 594 | private void applyRemoteInput(final NotificationData.Entry entry) { |
| 595 | if (mRemoteInputController == null) { |
| 596 | return; |
| 597 | } |
| 598 | |
| 599 | boolean hasRemoteInput = false; |
| 600 | |
| 601 | Notification.Action[] actions = entry.notification.getNotification().actions; |
| 602 | if (actions != null) { |
| 603 | for (Notification.Action a : actions) { |
| 604 | if (a.getRemoteInputs() != null) { |
| 605 | for (RemoteInput ri : a.getRemoteInputs()) { |
| 606 | if (ri.getAllowFreeFormInput()) { |
| 607 | hasRemoteInput = true; |
| 608 | break; |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | View bigContentView = mExpandedChild; |
| 616 | if (bigContentView != null) { |
| 617 | applyRemoteInput(bigContentView, entry, hasRemoteInput); |
| 618 | } |
| 619 | View headsUpContentView = mHeadsUpChild; |
| 620 | if (headsUpContentView != null) { |
| 621 | applyRemoteInput(headsUpContentView, entry, hasRemoteInput); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | private void applyRemoteInput(View view, NotificationData.Entry entry, boolean hasRemoteInput) { |
| 626 | View actionContainerCandidate = view.findViewById( |
| 627 | com.android.internal.R.id.actions_container); |
| 628 | if (actionContainerCandidate instanceof FrameLayout) { |
| 629 | RemoteInputView existing = (RemoteInputView) |
| 630 | view.findViewWithTag(RemoteInputView.VIEW_TAG); |
| 631 | |
| 632 | if (existing != null) { |
| 633 | existing.onNotificationUpdate(); |
| 634 | } |
| 635 | |
| 636 | if (existing == null && hasRemoteInput) { |
| 637 | ViewGroup actionContainer = (FrameLayout) actionContainerCandidate; |
| 638 | RemoteInputView riv = RemoteInputView.inflate( |
| 639 | mContext, actionContainer, entry, mRemoteInputController); |
| 640 | |
| 641 | riv.setVisibility(View.INVISIBLE); |
| 642 | actionContainer.addView(riv, new LayoutParams( |
| 643 | ViewGroup.LayoutParams.MATCH_PARENT, |
| 644 | ViewGroup.LayoutParams.MATCH_PARENT) |
| 645 | ); |
| 646 | int color = entry.notification.getNotification().color; |
| 647 | if (color == Notification.COLOR_DEFAULT) { |
| 648 | color = mContext.getColor(R.color.default_remote_input_background); |
| 649 | } |
| 650 | riv.setBackgroundColor(color); |
| 651 | } |
| 652 | } |
| 653 | } |
| 654 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 655 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 656 | mGroupManager = groupManager; |
| 657 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 658 | |
Adrian Roos | b88b1a1 | 2015-12-09 18:51:05 -0800 | [diff] [blame] | 659 | public void setRemoteInputController(RemoteInputController r) { |
| 660 | mRemoteInputController = r; |
| 661 | } |
| 662 | |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 663 | public void setExpandClickListener(OnClickListener expandClickListener) { |
| 664 | mExpandClickListener = expandClickListener; |
| 665 | } |
| 666 | |
| 667 | public void updateExpandButtons(boolean expandable) { |
Selim Cinek | 98be3f3 | 2015-12-17 16:39:06 -0800 | [diff] [blame] | 668 | mExpandable = expandable; |
| 669 | // if the expanded child has the same height as the collapsed one we hide it. |
| 670 | if (mExpandedChild != null && mExpandedChild.getHeight() != 0 && |
| 671 | ((mIsHeadsUp && mExpandedChild.getHeight() == mHeadsUpChild.getHeight()) || |
| 672 | (!mIsHeadsUp && mExpandedChild.getHeight() == mContractedChild.getHeight()))) { |
| 673 | expandable = false; |
| 674 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 675 | if (mExpandedChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 676 | mExpandedWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 677 | } |
| 678 | if (mContractedChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 679 | mContractedWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 680 | } |
| 681 | if (mHeadsUpChild != null) { |
Selim Cinek | eaa29ca | 2015-11-23 13:51:13 -0800 | [diff] [blame] | 682 | mHeadsUpWrapper.updateExpandability(expandable, mExpandClickListener); |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame] | 683 | } |
| 684 | } |
Selim Cinek | ea4bef7 | 2015-12-02 15:51:10 -0800 | [diff] [blame] | 685 | |
| 686 | public NotificationHeaderView getNotificationHeader() { |
| 687 | NotificationHeaderView header = null; |
| 688 | if (mContractedChild != null) { |
| 689 | header = mContractedWrapper.getNotificationHeader(); |
| 690 | } |
| 691 | if (header == null && mExpandedChild != null) { |
| 692 | header = mExpandedWrapper.getNotificationHeader(); |
| 693 | } |
| 694 | if (header == null && mHeadsUpChild != null) { |
| 695 | header = mHeadsUpWrapper.getNotificationHeader(); |
| 696 | } |
| 697 | return header; |
| 698 | } |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 699 | |
Selim Cinek | 34eda5e | 2016-02-18 17:10:43 -0800 | [diff] [blame] | 700 | public NotificationHeaderView getVisibleNotificationHeader() { |
| 701 | NotificationViewWrapper wrapper = getCurrentVisibleWrapper(); |
| 702 | return wrapper == null ? null : wrapper.getNotificationHeader(); |
| 703 | } |
| 704 | |
Selim Cinek | fa0a2d3 | 2016-01-14 13:02:21 -0800 | [diff] [blame] | 705 | public void setContainingNotification(ExpandableNotificationRow containingNotification) { |
| 706 | mContainingNotification = containingNotification; |
| 707 | } |
| 708 | |
| 709 | public void requestSelectLayout(boolean needsAnimation) { |
| 710 | selectLayout(needsAnimation, false); |
| 711 | } |
Selim Cinek | de33a4a | 2016-02-11 16:43:41 -0800 | [diff] [blame] | 712 | |
| 713 | public void reInflateViews() { |
| 714 | if (mIsChildInGroup && mSingleLineView != null) { |
| 715 | removeView(mSingleLineView); |
| 716 | mSingleLineView = null; |
| 717 | updateSingleLineView(); |
| 718 | } |
| 719 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 720 | } |