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 | |
| 19 | import android.content.Context; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 20 | import android.graphics.Outline; |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 21 | import android.graphics.Paint; |
| 22 | import android.graphics.PorterDuff; |
| 23 | import android.graphics.PorterDuffXfermode; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 24 | import android.graphics.Rect; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 25 | import android.service.notification.StatusBarNotification; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 26 | import android.util.AttributeSet; |
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; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 29 | import android.view.ViewOutlineProvider; |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 30 | import android.view.ViewTreeObserver; |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 31 | import android.view.animation.Interpolator; |
| 32 | import android.view.animation.LinearInterpolator; |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 33 | import android.widget.FrameLayout; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 34 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 35 | import com.android.systemui.R; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.HybridNotificationView; |
| 37 | import com.android.systemui.statusbar.notification.HybridNotificationViewManager; |
| 38 | import com.android.systemui.statusbar.phone.NotificationGroupManager; |
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 | |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 47 | private static final long ANIMATION_DURATION_LENGTH = 170; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 48 | private static final int VISIBLE_TYPE_CONTRACTED = 0; |
| 49 | private static final int VISIBLE_TYPE_EXPANDED = 1; |
| 50 | private static final int VISIBLE_TYPE_HEADSUP = 2; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 51 | private static final int VISIBLE_TYPE_SINGLELINE = 3; |
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 | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 54 | private final int mSingleLineHeight; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 55 | private final int mSmallHeight; |
| 56 | private final int mHeadsUpHeight; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 57 | private final int mRoundRectRadius; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 58 | private final Interpolator mLinearInterpolator = new LinearInterpolator(); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 59 | private final boolean mRoundRectClippingEnabled; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 60 | |
| 61 | private View mContractedChild; |
| 62 | private View mExpandedChild; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 63 | private View mHeadsUpChild; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 64 | private HybridNotificationView mSingleLineView; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 65 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 66 | private NotificationViewWrapper mContractedWrapper; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 67 | private NotificationViewWrapper mExpandedWrapper; |
| 68 | private NotificationViewWrapper mHeadsUpWrapper; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 69 | private HybridNotificationViewManager mHybridViewManager; |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 70 | private int mClipTopAmount; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 71 | private int mContentHeight; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 72 | private int mUnrestrictedContentHeight; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 73 | private int mVisibleType = VISIBLE_TYPE_CONTRACTED; |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 74 | private boolean mDark; |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 75 | private final Paint mFadePaint = new Paint(); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 76 | private boolean mAnimate; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 77 | private boolean mIsHeadsUp; |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 78 | private boolean mShowingLegacyBackground; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 79 | private boolean mIsChildInGroup; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame^] | 80 | private ExpandableNotificationRow mContainingNotification; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 81 | private StatusBarNotification mStatusBarNotification; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame^] | 82 | private NotificationGroupManager mGroupManager; |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 83 | |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 84 | private final ViewTreeObserver.OnPreDrawListener mEnableAnimationPredrawListener |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 85 | = new ViewTreeObserver.OnPreDrawListener() { |
| 86 | @Override |
| 87 | public boolean onPreDraw() { |
| 88 | mAnimate = true; |
| 89 | getViewTreeObserver().removeOnPreDrawListener(this); |
| 90 | return true; |
| 91 | } |
| 92 | }; |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 93 | |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 94 | private final ViewOutlineProvider mOutlineProvider = new ViewOutlineProvider() { |
| 95 | @Override |
| 96 | public void getOutline(View view, Outline outline) { |
| 97 | outline.setRoundRect(0, 0, view.getWidth(), mUnrestrictedContentHeight, |
| 98 | mRoundRectRadius); |
| 99 | } |
| 100 | }; |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame^] | 101 | private OnClickListener mExpandClickListener = new OnClickListener() { |
| 102 | @Override |
| 103 | public void onClick(View v) { |
| 104 | if (mGroupManager.isSummaryOfGroup(mStatusBarNotification)) { |
| 105 | mGroupManager.toggleGroupExpansion(mStatusBarNotification); |
| 106 | } else { |
| 107 | mContainingNotification.setUserExpanded(!mContainingNotification.isExpanded()); |
| 108 | mContainingNotification.notifyHeightChanged(true); |
| 109 | } |
| 110 | } |
| 111 | }; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 112 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 113 | public NotificationContentView(Context context, AttributeSet attrs) { |
| 114 | super(context, attrs); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 115 | mHybridViewManager = new HybridNotificationViewManager(getContext(), this); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 116 | mFadePaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.ADD)); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 117 | mSingleLineHeight = getResources().getDimensionPixelSize( |
| 118 | R.dimen.notification_single_line_height); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 119 | mSmallHeight = getResources().getDimensionPixelSize(R.dimen.notification_min_height); |
| 120 | mHeadsUpHeight = getResources().getDimensionPixelSize(R.dimen.notification_mid_height); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 121 | mRoundRectRadius = getResources().getDimensionPixelSize( |
| 122 | R.dimen.notification_material_rounded_rect_radius); |
| 123 | mRoundRectClippingEnabled = getResources().getBoolean( |
| 124 | R.bool.config_notifications_round_rect_clipping); |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 125 | reset(true); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 126 | setOutlineProvider(mOutlineProvider); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | @Override |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 130 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 131 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
| 132 | boolean hasFixedHeight = heightMode == MeasureSpec.EXACTLY; |
| 133 | boolean isHeightLimited = heightMode == MeasureSpec.AT_MOST; |
| 134 | int maxSize = Integer.MAX_VALUE; |
| 135 | if (hasFixedHeight || isHeightLimited) { |
| 136 | maxSize = MeasureSpec.getSize(heightMeasureSpec); |
| 137 | } |
| 138 | int maxChildHeight = 0; |
| 139 | if (mContractedChild != null) { |
| 140 | int size = Math.min(maxSize, mSmallHeight); |
| 141 | mContractedChild.measure(widthMeasureSpec, |
Selim Cinek | 06a24ebd | 2015-04-22 14:22:05 -0700 | [diff] [blame] | 142 | MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY)); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 143 | maxChildHeight = Math.max(maxChildHeight, mContractedChild.getMeasuredHeight()); |
| 144 | } |
| 145 | if (mExpandedChild != null) { |
| 146 | int size = maxSize; |
| 147 | ViewGroup.LayoutParams layoutParams = mExpandedChild.getLayoutParams(); |
| 148 | if (layoutParams.height >= 0) { |
| 149 | // An actual height is set |
| 150 | size = Math.min(maxSize, layoutParams.height); |
| 151 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 152 | int spec = size == Integer.MAX_VALUE |
| 153 | ? MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED) |
| 154 | : MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 155 | mExpandedChild.measure(widthMeasureSpec, spec); |
| 156 | maxChildHeight = Math.max(maxChildHeight, mExpandedChild.getMeasuredHeight()); |
| 157 | } |
| 158 | if (mHeadsUpChild != null) { |
| 159 | int size = Math.min(maxSize, mHeadsUpHeight); |
| 160 | ViewGroup.LayoutParams layoutParams = mHeadsUpChild.getLayoutParams(); |
| 161 | if (layoutParams.height >= 0) { |
| 162 | // An actual height is set |
| 163 | size = Math.min(maxSize, layoutParams.height); |
| 164 | } |
| 165 | mHeadsUpChild.measure(widthMeasureSpec, |
| 166 | MeasureSpec.makeMeasureSpec(size, MeasureSpec.AT_MOST)); |
| 167 | maxChildHeight = Math.max(maxChildHeight, mHeadsUpChild.getMeasuredHeight()); |
| 168 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 169 | if (mSingleLineView != null) { |
| 170 | int size = Math.min(maxSize, mSingleLineHeight); |
| 171 | mSingleLineView.measure(widthMeasureSpec, |
| 172 | MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY)); |
| 173 | maxChildHeight = Math.max(maxChildHeight, mSingleLineView.getMeasuredHeight()); |
| 174 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 175 | int ownHeight = Math.min(maxChildHeight, maxSize); |
| 176 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 177 | setMeasuredDimension(width, ownHeight); |
| 178 | } |
| 179 | |
| 180 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 181 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 182 | super.onLayout(changed, left, top, right, bottom); |
| 183 | updateClipping(); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 184 | invalidateOutline(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 185 | } |
| 186 | |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 187 | @Override |
Selim Cinek | 7b8157e | 2014-11-20 16:00:32 +0100 | [diff] [blame] | 188 | protected void onAttachedToWindow() { |
| 189 | super.onAttachedToWindow(); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 190 | updateVisibility(); |
| 191 | } |
| 192 | |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 193 | public void reset(boolean resetActualHeight) { |
Jorim Jaggi | 0d9f35d | 2014-08-20 17:06:55 +0200 | [diff] [blame] | 194 | if (mContractedChild != null) { |
| 195 | mContractedChild.animate().cancel(); |
| 196 | } |
| 197 | if (mExpandedChild != null) { |
| 198 | mExpandedChild.animate().cancel(); |
| 199 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 200 | if (mHeadsUpChild != null) { |
| 201 | mHeadsUpChild.animate().cancel(); |
| 202 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 203 | removeAllViews(); |
| 204 | mContractedChild = null; |
| 205 | mExpandedChild = null; |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 206 | mHeadsUpChild = null; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 207 | mVisibleType = VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 208 | if (resetActualHeight) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 209 | mContentHeight = mSmallHeight; |
Selim Cinek | 1a521f3 | 2014-11-03 17:39:29 +0100 | [diff] [blame] | 210 | } |
Christoph Studer | a7fe631 | 2014-06-27 19:32:44 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Selim Cinek | cab4a60 | 2014-09-03 14:47:57 +0200 | [diff] [blame] | 213 | public View getContractedChild() { |
| 214 | return mContractedChild; |
| 215 | } |
| 216 | |
| 217 | public View getExpandedChild() { |
| 218 | return mExpandedChild; |
| 219 | } |
| 220 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 221 | public View getHeadsUpChild() { |
| 222 | return mHeadsUpChild; |
| 223 | } |
| 224 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 225 | public void setContractedChild(View child) { |
| 226 | if (mContractedChild != null) { |
Jorim Jaggi | 0d9f35d | 2014-08-20 17:06:55 +0200 | [diff] [blame] | 227 | mContractedChild.animate().cancel(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 228 | removeView(mContractedChild); |
| 229 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 230 | addView(child); |
| 231 | mContractedChild = child; |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 232 | mContractedWrapper = NotificationViewWrapper.wrap(getContext(), child); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 233 | selectLayout(false /* animate */, true /* force */); |
Jorim Jaggi | 10ad761 | 2014-12-08 18:41:11 +0100 | [diff] [blame] | 234 | mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 235 | updateRoundRectClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | public void setExpandedChild(View child) { |
| 239 | if (mExpandedChild != null) { |
Jorim Jaggi | 0d9f35d | 2014-08-20 17:06:55 +0200 | [diff] [blame] | 240 | mExpandedChild.animate().cancel(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 241 | removeView(mExpandedChild); |
| 242 | } |
| 243 | addView(child); |
| 244 | mExpandedChild = child; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 245 | mExpandedWrapper = NotificationViewWrapper.wrap(getContext(), child); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 246 | selectLayout(false /* animate */, true /* force */); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 247 | updateRoundRectClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 250 | public void setHeadsUpChild(View child) { |
| 251 | if (mHeadsUpChild != null) { |
| 252 | mHeadsUpChild.animate().cancel(); |
| 253 | removeView(mHeadsUpChild); |
| 254 | } |
| 255 | addView(child); |
| 256 | mHeadsUpChild = child; |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 257 | mHeadsUpWrapper = NotificationViewWrapper.wrap(getContext(), child); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 258 | selectLayout(false /* animate */, true /* force */); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 259 | updateRoundRectClipping(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 262 | @Override |
| 263 | protected void onVisibilityChanged(View changedView, int visibility) { |
| 264 | super.onVisibilityChanged(changedView, visibility); |
| 265 | updateVisibility(); |
| 266 | } |
| 267 | |
| 268 | private void updateVisibility() { |
| 269 | setVisible(isShown()); |
| 270 | } |
| 271 | |
| 272 | private void setVisible(final boolean isVisible) { |
| 273 | if (isVisible) { |
| 274 | |
| 275 | // We only animate if we are drawn at least once, otherwise the view might animate when |
| 276 | // it's shown the first time |
| 277 | getViewTreeObserver().addOnPreDrawListener(mEnableAnimationPredrawListener); |
| 278 | } else { |
| 279 | getViewTreeObserver().removeOnPreDrawListener(mEnableAnimationPredrawListener); |
| 280 | mAnimate = false; |
| 281 | } |
| 282 | } |
| 283 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 284 | public void setContentHeight(int contentHeight) { |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 285 | mContentHeight = Math.max(Math.min(contentHeight, getHeight()), getMinHeight());; |
| 286 | mUnrestrictedContentHeight = Math.max(contentHeight, getMinHeight()); |
Selim Cinek | bb3d1cf | 2014-10-31 00:12:56 +0100 | [diff] [blame] | 287 | selectLayout(mAnimate /* animate */, false /* force */); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 288 | updateClipping(); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 289 | invalidateOutline(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 292 | public int getContentHeight() { |
| 293 | return mContentHeight; |
| 294 | } |
| 295 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 296 | public int getMaxHeight() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 297 | if (mIsHeadsUp && mHeadsUpChild != null) { |
| 298 | return mHeadsUpChild.getHeight(); |
| 299 | } else if (mExpandedChild != null) { |
| 300 | return mExpandedChild.getHeight(); |
| 301 | } |
| 302 | return mSmallHeight; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 303 | } |
| 304 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 305 | public int getMinHeight() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 306 | if (mIsChildInGroup && !isGroupExpanded()) { |
| 307 | return mSingleLineHeight; |
| 308 | } else { |
| 309 | return mSmallHeight; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | private boolean isGroupExpanded() { |
| 314 | return mGroupManager.isGroupExpanded(mStatusBarNotification); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 317 | public void setClipTopAmount(int clipTopAmount) { |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 318 | mClipTopAmount = clipTopAmount; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 319 | updateClipping(); |
| 320 | } |
| 321 | |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 322 | private void updateRoundRectClipping() { |
| 323 | boolean enabled = needsRoundRectClipping(); |
| 324 | setClipToOutline(enabled); |
| 325 | } |
| 326 | |
| 327 | private boolean needsRoundRectClipping() { |
| 328 | if (!mRoundRectClippingEnabled) { |
| 329 | return false; |
| 330 | } |
| 331 | boolean needsForContracted = mContractedChild != null |
| 332 | && mContractedChild.getVisibility() == View.VISIBLE |
| 333 | && mContractedWrapper.needsRoundRectClipping(); |
| 334 | boolean needsForExpanded = mExpandedChild != null |
| 335 | && mExpandedChild.getVisibility() == View.VISIBLE |
| 336 | && mExpandedWrapper.needsRoundRectClipping(); |
| 337 | boolean needsForHeadsUp = mExpandedChild != null |
| 338 | && mExpandedChild.getVisibility() == View.VISIBLE |
| 339 | && mExpandedWrapper.needsRoundRectClipping(); |
| 340 | return needsForContracted || needsForExpanded || needsForHeadsUp; |
| 341 | } |
| 342 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 343 | private void updateClipping() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 344 | mClipBounds.set(0, mClipTopAmount, getWidth(), mContentHeight); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 345 | setClipBounds(mClipBounds); |
| 346 | } |
| 347 | |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 348 | private void selectLayout(boolean animate, boolean force) { |
| 349 | if (mContractedChild == null) { |
| 350 | return; |
| 351 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 352 | int visibleType = calculateVisibleType(); |
| 353 | if (visibleType != mVisibleType || force) { |
Jorim Jaggi | 021eee5 | 2015-06-11 17:07:18 -0700 | [diff] [blame] | 354 | if (animate && ((visibleType == VISIBLE_TYPE_EXPANDED && mExpandedChild != null) |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 355 | || (visibleType == VISIBLE_TYPE_HEADSUP && mHeadsUpChild != null) |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 356 | || (visibleType == VISIBLE_TYPE_SINGLELINE && mSingleLineView != null) |
Jorim Jaggi | 021eee5 | 2015-06-11 17:07:18 -0700 | [diff] [blame] | 357 | || visibleType == VISIBLE_TYPE_CONTRACTED)) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 358 | runSwitchAnimation(visibleType); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 359 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 360 | updateViewVisibilities(visibleType); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 361 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 362 | mVisibleType = visibleType; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 363 | } |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 364 | } |
| 365 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 366 | private void updateViewVisibilities(int visibleType) { |
| 367 | boolean contractedVisible = visibleType == VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 368 | mContractedChild.setVisibility(contractedVisible ? View.VISIBLE : View.INVISIBLE); |
| 369 | mContractedChild.setAlpha(contractedVisible ? 1f : 0f); |
| 370 | mContractedChild.setLayerType(LAYER_TYPE_NONE, null); |
| 371 | if (mExpandedChild != null) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 372 | boolean expandedVisible = visibleType == VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 373 | mExpandedChild.setVisibility(expandedVisible ? View.VISIBLE : View.INVISIBLE); |
| 374 | mExpandedChild.setAlpha(expandedVisible ? 1f : 0f); |
| 375 | mExpandedChild.setLayerType(LAYER_TYPE_NONE, null); |
| 376 | } |
| 377 | if (mHeadsUpChild != null) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 378 | boolean headsUpVisible = visibleType == VISIBLE_TYPE_HEADSUP; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 379 | mHeadsUpChild.setVisibility(headsUpVisible ? View.VISIBLE : View.INVISIBLE); |
| 380 | mHeadsUpChild.setAlpha(headsUpVisible ? 1f : 0f); |
| 381 | mHeadsUpChild.setLayerType(LAYER_TYPE_NONE, null); |
| 382 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 383 | if (mSingleLineView != null) { |
| 384 | boolean singleLineVisible = visibleType == VISIBLE_TYPE_SINGLELINE; |
| 385 | mSingleLineView.setVisibility(singleLineVisible ? View.VISIBLE : View.INVISIBLE); |
| 386 | mSingleLineView.setAlpha(singleLineVisible ? 1f : 0f); |
| 387 | mSingleLineView.setLayerType(LAYER_TYPE_NONE, null); |
| 388 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 389 | setLayerType(LAYER_TYPE_NONE, null); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 390 | updateRoundRectClipping(); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 391 | } |
| 392 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 393 | private void runSwitchAnimation(int visibleType) { |
| 394 | View shownView = getViewForVisibleType(visibleType); |
| 395 | View hiddenView = getViewForVisibleType(mVisibleType); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 396 | shownView.setVisibility(View.VISIBLE); |
| 397 | hiddenView.setVisibility(View.VISIBLE); |
| 398 | shownView.setLayerType(LAYER_TYPE_HARDWARE, mFadePaint); |
| 399 | hiddenView.setLayerType(LAYER_TYPE_HARDWARE, mFadePaint); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 400 | setLayerType(LAYER_TYPE_HARDWARE, null); |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 401 | hiddenView.animate() |
| 402 | .alpha(0f) |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 403 | .setDuration(ANIMATION_DURATION_LENGTH) |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 404 | .setInterpolator(mLinearInterpolator) |
| 405 | .withEndAction(null); // In case we have multiple changes in one frame. |
| 406 | shownView.animate() |
| 407 | .alpha(1f) |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 408 | .setDuration(ANIMATION_DURATION_LENGTH) |
| 409 | .setInterpolator(mLinearInterpolator) |
| 410 | .withEndAction(new Runnable() { |
| 411 | @Override |
| 412 | public void run() { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 413 | updateViewVisibilities(mVisibleType); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 414 | } |
| 415 | }); |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 416 | updateRoundRectClipping(); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 417 | } |
| 418 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 419 | /** |
| 420 | * @param visibleType one of the static enum types in this view |
| 421 | * @return the corresponding view according to the given visible type |
| 422 | */ |
| 423 | private View getViewForVisibleType(int visibleType) { |
| 424 | switch (visibleType) { |
| 425 | case VISIBLE_TYPE_EXPANDED: |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 426 | return mExpandedChild; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 427 | case VISIBLE_TYPE_HEADSUP: |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 428 | return mHeadsUpChild; |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 429 | case VISIBLE_TYPE_SINGLELINE: |
| 430 | return mSingleLineView; |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 431 | default: |
| 432 | return mContractedChild; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 433 | } |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 436 | /** |
| 437 | * @return one of the static enum types in this view, calculated form the current state |
| 438 | */ |
| 439 | private int calculateVisibleType() { |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 440 | boolean noExpandedChild = mExpandedChild == null; |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 441 | if (mIsHeadsUp && mHeadsUpChild != null) { |
| 442 | if (mContentHeight <= mHeadsUpChild.getHeight() || noExpandedChild) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 443 | return VISIBLE_TYPE_HEADSUP; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 444 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 445 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 446 | } |
| 447 | } else { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 448 | if (mIsChildInGroup && !isGroupExpanded()) { |
| 449 | return VISIBLE_TYPE_SINGLELINE; |
| 450 | } else if (mContentHeight <= mSmallHeight || noExpandedChild) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 451 | return VISIBLE_TYPE_CONTRACTED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 452 | } else { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 453 | return VISIBLE_TYPE_EXPANDED; |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | public void notifyContentUpdated() { |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 459 | updateSingleLineView(); |
Jorim Jaggi | 1129883 | 2014-05-24 16:18:38 +0200 | [diff] [blame] | 460 | selectLayout(false /* animate */, true /* force */); |
Jorim Jaggi | 394a5d6 | 2014-11-26 23:07:13 +0100 | [diff] [blame] | 461 | if (mContractedChild != null) { |
Jorim Jaggi | dacc924 | 2014-12-08 19:21:26 +0100 | [diff] [blame] | 462 | mContractedWrapper.notifyContentUpdated(); |
Jorim Jaggi | 394a5d6 | 2014-11-26 23:07:13 +0100 | [diff] [blame] | 463 | mContractedWrapper.setDark(mDark, false /* animate */, 0 /* delay */); |
| 464 | } |
Jorim Jaggi | be4116a | 2015-05-20 20:04:08 -0700 | [diff] [blame] | 465 | if (mExpandedChild != null) { |
| 466 | mExpandedWrapper.notifyContentUpdated(); |
| 467 | } |
| 468 | updateRoundRectClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 469 | } |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 470 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 471 | public boolean isContentExpandable() { |
| 472 | return mExpandedChild != null; |
| 473 | } |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 474 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 475 | public void setDark(boolean dark, boolean fade, long delay) { |
John Spurlock | c3dfd32 | 2014-08-27 14:55:54 -0400 | [diff] [blame] | 476 | if (mDark == dark || mContractedChild == null) return; |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 477 | mDark = dark; |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 478 | mContractedWrapper.setDark(dark && !mShowingLegacyBackground, fade, delay); |
John Spurlock | e15452b | 2014-08-21 09:44:39 -0400 | [diff] [blame] | 479 | } |
| 480 | |
Selim Cinek | 8d490d4 | 2015-04-10 00:05:50 -0700 | [diff] [blame] | 481 | public void setHeadsUp(boolean headsUp) { |
| 482 | mIsHeadsUp = headsUp; |
| 483 | selectLayout(false /* animate */, true /* force */); |
| 484 | } |
| 485 | |
Jorim Jaggi | aa92ffb | 2014-09-10 23:29:28 +0200 | [diff] [blame] | 486 | @Override |
| 487 | public boolean hasOverlappingRendering() { |
| 488 | |
| 489 | // This is not really true, but good enough when fading from the contracted to the expanded |
| 490 | // layout, and saves us some layers. |
| 491 | return false; |
| 492 | } |
Jorim Jaggi | 59ec304 | 2015-06-05 15:18:43 -0700 | [diff] [blame] | 493 | |
| 494 | public void setShowingLegacyBackground(boolean showing) { |
| 495 | mShowingLegacyBackground = showing; |
| 496 | } |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 497 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 498 | public void setIsChildInGroup(boolean isChildInGroup) { |
| 499 | mIsChildInGroup = isChildInGroup; |
| 500 | updateSingleLineView(); |
| 501 | } |
| 502 | |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame^] | 503 | public void setContainingNotification(ExpandableNotificationRow notification) { |
| 504 | mContainingNotification = notification; |
| 505 | } |
| 506 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 507 | public void setStatusBarNotification(StatusBarNotification statusBarNotification) { |
| 508 | mStatusBarNotification = statusBarNotification; |
| 509 | updateSingleLineView(); |
| 510 | } |
| 511 | |
| 512 | private void updateSingleLineView() { |
| 513 | if (mIsChildInGroup) { |
| 514 | mSingleLineView = mHybridViewManager.bindFromNotification( |
| 515 | mSingleLineView, mStatusBarNotification.getNotification()); |
| 516 | } |
| 517 | } |
| 518 | |
Selim Cinek | 8d6440d | 2015-10-22 13:00:05 -0700 | [diff] [blame] | 519 | public void setSubTextVisible(boolean visible) { |
| 520 | if (mExpandedChild != null) { |
| 521 | mExpandedWrapper.setSubTextVisible(visible); |
| 522 | } |
| 523 | if (mContractedChild != null) { |
| 524 | mContractedWrapper.setSubTextVisible(visible); |
| 525 | } |
| 526 | if (mHeadsUpChild != null) { |
| 527 | mHeadsUpWrapper.setSubTextVisible(visible); |
| 528 | } |
| 529 | } |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 530 | |
| 531 | public void setGroupManager(NotificationGroupManager groupManager) { |
| 532 | mGroupManager = groupManager; |
| 533 | } |
Selim Cinek | 65b2e7c | 2015-10-26 14:11:31 -0700 | [diff] [blame^] | 534 | |
| 535 | public void updateExpandButtons() { |
| 536 | if (mExpandedChild != null) { |
| 537 | mExpandedWrapper.updateExpandability(mContainingNotification.isExpandable(), |
| 538 | mExpandClickListener); |
| 539 | } |
| 540 | if (mContractedChild != null) { |
| 541 | mContractedWrapper.updateExpandability(mContainingNotification.isExpandable(), |
| 542 | mExpandClickListener); |
| 543 | } |
| 544 | if (mHeadsUpChild != null) { |
| 545 | mHeadsUpWrapper.updateExpandability(mContainingNotification.isExpandable(), |
| 546 | mExpandClickListener); |
| 547 | } |
| 548 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 549 | } |