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