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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 18 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 19 | import android.animation.AnimatorListenerAdapter; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 20 | import android.content.Context; |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 21 | import android.graphics.Paint; |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 22 | import android.graphics.Rect; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
Selim Cinek | c9c00ae | 2014-05-20 03:33:40 +0200 | [diff] [blame] | 25 | import android.view.ViewGroup; |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 26 | import android.widget.FrameLayout; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 27 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 28 | import androidx.annotation.Nullable; |
| 29 | |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 30 | import com.android.systemui.Dumpable; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.stack.ExpandableViewState; |
| 32 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 33 | |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 34 | import java.io.FileDescriptor; |
| 35 | import java.io.PrintWriter; |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 36 | import java.util.ArrayList; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 37 | import java.util.List; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 38 | |
| 39 | /** |
| 40 | * An abstract view for expandable views. |
| 41 | */ |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 42 | public abstract class ExpandableView extends FrameLayout implements Dumpable { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 43 | private static final String TAG = "ExpandableView"; |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 44 | |
Selim Cinek | eccf494 | 2018-05-30 09:55:36 -0700 | [diff] [blame] | 45 | public static final float NO_ROUNDNESS = -1; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 46 | protected OnHeightChangedListener mOnHeightChangedListener; |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 47 | private int mActualHeight; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 48 | protected int mClipTopAmount; |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 49 | protected int mClipBottomAmount; |
Selim Cinek | 5332849 | 2018-12-05 14:58:44 -0800 | [diff] [blame] | 50 | protected int mMinimumHeightForClipping = 0; |
| 51 | protected float mExtraWidthForClipping = 0; |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 52 | private ArrayList<View> mMatchParentViews = new ArrayList<View>(); |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 53 | private static Rect mClipRect = new Rect(); |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 54 | private boolean mWillBeGone; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 55 | private int mMinClipTopAmount = 0; |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 56 | private boolean mClipToActualHeight = true; |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 57 | private boolean mChangingPosition = false; |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 58 | private ViewGroup mTransientContainer; |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 59 | private boolean mInShelf; |
| 60 | private boolean mTransformingInShelf; |
Dave Mankoff | c56db33 | 2018-12-10 11:31:49 -0500 | [diff] [blame] | 61 | private final ExpandableViewState mViewState; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 62 | |
| 63 | public ExpandableView(Context context, AttributeSet attrs) { |
| 64 | super(context, attrs); |
Dave Mankoff | c56db33 | 2018-12-10 11:31:49 -0500 | [diff] [blame] | 65 | mViewState = createExpandableViewState(); |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | @Override |
| 69 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 70 | final int givenSize = MeasureSpec.getSize(heightMeasureSpec); |
felkachang | 79ca96d | 2018-04-27 16:55:40 +0800 | [diff] [blame] | 71 | final int viewHorizontalPadding = getPaddingStart() + getPaddingEnd(); |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 72 | int ownMaxHeight = Integer.MAX_VALUE; |
Selim Cinek | 6f145cf | 2015-05-18 15:16:08 -0700 | [diff] [blame] | 73 | int heightMode = MeasureSpec.getMode(heightMeasureSpec); |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 74 | if (heightMode != MeasureSpec.UNSPECIFIED && givenSize != 0) { |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 75 | ownMaxHeight = Math.min(givenSize, ownMaxHeight); |
Selim Cinek | 6f145cf | 2015-05-18 15:16:08 -0700 | [diff] [blame] | 76 | } |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 77 | int newHeightSpec = MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.AT_MOST); |
| 78 | int maxChildHeight = 0; |
| 79 | int childCount = getChildCount(); |
| 80 | for (int i = 0; i < childCount; i++) { |
| 81 | View child = getChildAt(i); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 82 | if (child.getVisibility() == GONE) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 83 | continue; |
| 84 | } |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 85 | int childHeightSpec = newHeightSpec; |
| 86 | ViewGroup.LayoutParams layoutParams = child.getLayoutParams(); |
| 87 | if (layoutParams.height != ViewGroup.LayoutParams.MATCH_PARENT) { |
| 88 | if (layoutParams.height >= 0) { |
| 89 | // An actual height is set |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 90 | childHeightSpec = layoutParams.height > ownMaxHeight |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 91 | ? MeasureSpec.makeMeasureSpec(ownMaxHeight, MeasureSpec.EXACTLY) |
| 92 | : MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY); |
| 93 | } |
felkachang | 79ca96d | 2018-04-27 16:55:40 +0800 | [diff] [blame] | 94 | child.measure(getChildMeasureSpec( |
| 95 | widthMeasureSpec, viewHorizontalPadding, layoutParams.width), |
Jorim Jaggi | b741f05 | 2014-06-03 19:57:26 +0200 | [diff] [blame] | 96 | childHeightSpec); |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 97 | int childHeight = child.getMeasuredHeight(); |
| 98 | maxChildHeight = Math.max(maxChildHeight, childHeight); |
| 99 | } else { |
| 100 | mMatchParentViews.add(child); |
| 101 | } |
| 102 | } |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 103 | int ownHeight = heightMode == MeasureSpec.EXACTLY |
| 104 | ? givenSize : Math.min(ownMaxHeight, maxChildHeight); |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 105 | newHeightSpec = MeasureSpec.makeMeasureSpec(ownHeight, MeasureSpec.EXACTLY); |
| 106 | for (View child : mMatchParentViews) { |
Jorim Jaggi | b741f05 | 2014-06-03 19:57:26 +0200 | [diff] [blame] | 107 | child.measure(getChildMeasureSpec( |
felkachang | 79ca96d | 2018-04-27 16:55:40 +0800 | [diff] [blame] | 108 | widthMeasureSpec, viewHorizontalPadding, child.getLayoutParams().width), |
Jorim Jaggi | b741f05 | 2014-06-03 19:57:26 +0200 | [diff] [blame] | 109 | newHeightSpec); |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 110 | } |
| 111 | mMatchParentViews.clear(); |
| 112 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 113 | setMeasuredDimension(width, ownHeight); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | @Override |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 117 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
Selim Cinek | 24d7cfa | 2014-05-20 13:50:57 +0200 | [diff] [blame] | 118 | super.onLayout(changed, left, top, right, bottom); |
Selim Cinek | ba67acf | 2015-04-10 17:00:42 -0700 | [diff] [blame] | 119 | updateClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Jorim Jaggi | 00ebdfe | 2014-05-02 17:29:56 +0200 | [diff] [blame] | 122 | @Override |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 123 | public boolean pointInView(float localX, float localY, float slop) { |
| 124 | float top = mClipTopAmount; |
| 125 | float bottom = mActualHeight; |
| 126 | return localX >= -slop && localY >= top - slop && localX < ((mRight - mLeft) + slop) && |
| 127 | localY < (bottom + slop); |
Jorim Jaggi | 00ebdfe | 2014-05-02 17:29:56 +0200 | [diff] [blame] | 128 | } |
| 129 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 130 | /** |
| 131 | * Sets the actual height of this notification. This is different than the laid out |
| 132 | * {@link View#getHeight()}, as we want to avoid layouting during scrolling and expanding. |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 133 | * |
| 134 | * @param actualHeight The height of this notification. |
| 135 | * @param notifyListeners Whether the listener should be informed about the change. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 136 | */ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 137 | public void setActualHeight(int actualHeight, boolean notifyListeners) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 138 | mActualHeight = actualHeight; |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 139 | updateClipping(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 140 | if (notifyListeners) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 141 | notifyHeightChanged(false /* needsAnimation */); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
Selim Cinek | b0ee18f | 2017-12-21 16:15:53 -0800 | [diff] [blame] | 145 | /** |
| 146 | * Set the distance to the top roundness, from where we should start clipping a value above |
| 147 | * or equal to 0 is the effective distance, and if a value below 0 is received, there should |
| 148 | * be no clipping. |
| 149 | */ |
| 150 | public void setDistanceToTopRoundness(float distanceToTopRoundness) { |
| 151 | } |
| 152 | |
Selim Cinek | eef8428 | 2015-10-30 16:28:00 -0700 | [diff] [blame] | 153 | public void setActualHeight(int actualHeight) { |
| 154 | setActualHeight(actualHeight, true /* notifyListeners */); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /** |
| 158 | * See {@link #setActualHeight}. |
| 159 | * |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 160 | * @return The current actual height of this notification. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 161 | */ |
| 162 | public int getActualHeight() { |
| 163 | return mActualHeight; |
| 164 | } |
| 165 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 166 | public boolean isExpandAnimationRunning() { |
| 167 | return false; |
| 168 | } |
| 169 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 170 | /** |
| 171 | * @return The maximum height of this notification. |
| 172 | */ |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 173 | public int getMaxContentHeight() { |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 174 | return getHeight(); |
| 175 | } |
| 176 | |
| 177 | /** |
Selim Cinek | eb3fc3d | 2017-09-15 13:37:14 -0700 | [diff] [blame] | 178 | * @return The minimum content height of this notification. This also respects the temporary |
| 179 | * states of the view. |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 180 | */ |
| 181 | public int getMinHeight() { |
Selim Cinek | eb3fc3d | 2017-09-15 13:37:14 -0700 | [diff] [blame] | 182 | return getMinHeight(false /* ignoreTemporaryStates */); |
| 183 | } |
| 184 | |
| 185 | /** |
| 186 | * Get the minimum height of this view. |
| 187 | * |
| 188 | * @param ignoreTemporaryStates should temporary states be ignored like the guts or heads-up. |
| 189 | * |
| 190 | * @return The minimum height that this view needs. |
| 191 | */ |
| 192 | public int getMinHeight(boolean ignoreTemporaryStates) { |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 193 | return getHeight(); |
| 194 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 195 | |
| 196 | /** |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 197 | * @return The collapsed height of this view. Note that this might be different |
| 198 | * than {@link #getMinHeight()} because some elements like groups may have different sizes when |
| 199 | * they are system expanded. |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 200 | */ |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 201 | public int getCollapsedHeight() { |
Selim Cinek | 816c8e4 | 2015-11-19 12:00:45 -0800 | [diff] [blame] | 202 | return getHeight(); |
| 203 | } |
| 204 | |
| 205 | /** |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 206 | * Sets the notification as dimmed. The default implementation does nothing. |
| 207 | * |
| 208 | * @param dimmed Whether the notification should be dimmed. |
| 209 | * @param fade Whether an animation should be played to change the state. |
| 210 | */ |
| 211 | public void setDimmed(boolean dimmed, boolean fade) { |
| 212 | } |
| 213 | |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 214 | public boolean isRemoved() { |
| 215 | return false; |
| 216 | } |
| 217 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 218 | /** |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 219 | * See {@link #setHideSensitive}. This is a variant which notifies this view in advance about |
| 220 | * the upcoming state of hiding sensitive notifications. It gets called at the very beginning |
| 221 | * of a stack scroller update such that the updated intrinsic height (which is dependent on |
| 222 | * whether private or public layout is showing) gets taken into account into all layout |
| 223 | * calculations. |
| 224 | */ |
| 225 | public void setHideSensitiveForIntrinsicHeight(boolean hideSensitive) { |
| 226 | } |
| 227 | |
| 228 | /** |
| 229 | * Sets whether the notification should hide its private contents if it is sensitive. |
| 230 | */ |
| 231 | public void setHideSensitive(boolean hideSensitive, boolean animated, long delay, |
| 232 | long duration) { |
| 233 | } |
| 234 | |
| 235 | /** |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 236 | * @return The desired notification height. |
| 237 | */ |
| 238 | public int getIntrinsicHeight() { |
Selim Cinek | a5eaa60 | 2014-05-12 21:27:47 +0200 | [diff] [blame] | 239 | return getHeight(); |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | /** |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 243 | * Sets the amount this view should be clipped from the top. This is used when an expanded |
| 244 | * notification is scrolling in the top or bottom stack. |
| 245 | * |
| 246 | * @param clipTopAmount The amount of pixels this view should be clipped from top. |
| 247 | */ |
| 248 | public void setClipTopAmount(int clipTopAmount) { |
| 249 | mClipTopAmount = clipTopAmount; |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 250 | updateClipping(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 251 | } |
| 252 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 253 | /** |
| 254 | * Set the amount the the notification is clipped on the bottom in addition to the regular |
| 255 | * clipping. This is mainly used to clip something in a non-animated way without changing the |
| 256 | * actual height of the notification and is purely visual. |
| 257 | * |
| 258 | * @param clipBottomAmount the amount to clip. |
| 259 | */ |
| 260 | public void setClipBottomAmount(int clipBottomAmount) { |
| 261 | mClipBottomAmount = clipBottomAmount; |
| 262 | updateClipping(); |
| 263 | } |
| 264 | |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 265 | public int getClipTopAmount() { |
| 266 | return mClipTopAmount; |
| 267 | } |
| 268 | |
Selim Cinek | b3dadcc | 2016-11-21 17:21:13 -0800 | [diff] [blame] | 269 | public int getClipBottomAmount() { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 270 | return mClipBottomAmount; |
| 271 | } |
| 272 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 273 | public void setOnHeightChangedListener(OnHeightChangedListener listener) { |
| 274 | mOnHeightChangedListener = listener; |
| 275 | } |
| 276 | |
| 277 | /** |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 278 | * @return Whether we can expand this views content. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 279 | */ |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 280 | public boolean isContentExpandable() { |
| 281 | return false; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 284 | public void notifyHeightChanged(boolean needsAnimation) { |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 285 | if (mOnHeightChangedListener != null) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 286 | mOnHeightChangedListener.onHeightChanged(this, needsAnimation); |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 290 | public boolean isTransparent() { |
| 291 | return false; |
| 292 | } |
| 293 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 294 | /** |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 295 | * Perform a remove animation on this view. |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 296 | * @param duration The duration of the remove animation. |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 297 | * @param delay The delay of the animation |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 298 | * @param translationDirection The direction value from [-1 ... 1] indicating in which the |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 299 | * animation should be performed. A value of -1 means that The |
| 300 | * remove animation should be performed upwards, |
| 301 | * such that the child appears to be going away to the top. 1 |
| 302 | * Should mean the opposite. |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 303 | * @param isHeadsUpAnimation Is this a headsUp animation. |
| 304 | * @param endLocation The location where the horizonal heads up disappear animation should end. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 305 | * @param onFinishedRunnable A runnable which should be run when the animation is finished. |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 306 | * @param animationListener An animation listener to add to the animation. |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 307 | * |
| 308 | * @return The additional delay, in milliseconds, that this view needs to add before the |
| 309 | * animation starts. |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 310 | */ |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 311 | public abstract long performRemoveAnimation(long duration, |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 312 | long delay, float translationDirection, boolean isHeadsUpAnimation, float endLocation, |
| 313 | Runnable onFinishedRunnable, |
| 314 | AnimatorListenerAdapter animationListener); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 315 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 316 | public abstract void performAddAnimation(long delay, long duration, boolean isHeadsUpAppear); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 317 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 318 | /** |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 319 | * Set the notification appearance to be below the speed bump. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 320 | * @param below true if it is below. |
| 321 | */ |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 322 | public void setBelowSpeedBump(boolean below) { |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 325 | public int getPinnedHeadsUpHeight() { |
| 326 | return getIntrinsicHeight(); |
| 327 | } |
| 328 | |
| 329 | |
Mady Mellor | 34958fa | 2016-02-23 09:52:17 -0800 | [diff] [blame] | 330 | /** |
| 331 | * Sets the translation of the view. |
| 332 | */ |
| 333 | public void setTranslation(float translation) { |
| 334 | setTranslationX(translation); |
| 335 | } |
| 336 | |
| 337 | /** |
| 338 | * Gets the translation of the view. |
| 339 | */ |
| 340 | public float getTranslation() { |
| 341 | return getTranslationX(); |
| 342 | } |
| 343 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 344 | public void onHeightReset() { |
Selim Cinek | e34c651 | 2014-08-14 11:19:41 +0200 | [diff] [blame] | 345 | if (mOnHeightChangedListener != null) { |
| 346 | mOnHeightChangedListener.onReset(this); |
| 347 | } |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 348 | } |
| 349 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 350 | /** |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 351 | * This method returns the drawing rect for the view which is different from the regular |
| 352 | * drawing rect, since we layout all children in the {@link NotificationStackScrollLayout} at |
| 353 | * position 0 and usually the translation is neglected. Since we are manually clipping this |
| 354 | * view,we also need to subtract the clipTopAmount from the top. This is needed in order to |
| 355 | * ensure that accessibility and focusing work correctly. |
| 356 | * |
| 357 | * @param outRect The (scrolled) drawing bounds of the view. |
| 358 | */ |
| 359 | @Override |
| 360 | public void getDrawingRect(Rect outRect) { |
| 361 | super.getDrawingRect(outRect); |
| 362 | outRect.left += getTranslationX(); |
| 363 | outRect.right += getTranslationX(); |
| 364 | outRect.bottom = (int) (outRect.top + getTranslationY() + getActualHeight()); |
| 365 | outRect.top += getTranslationY() + getClipTopAmount(); |
| 366 | } |
| 367 | |
Adrian Roos | cd55f43 | 2015-06-10 16:42:53 -0700 | [diff] [blame] | 368 | @Override |
| 369 | public void getBoundsOnScreen(Rect outRect, boolean clipToParent) { |
| 370 | super.getBoundsOnScreen(outRect, clipToParent); |
Adrian Roos | 98dd7f1 | 2016-06-14 15:51:40 -0700 | [diff] [blame] | 371 | if (getTop() + getTranslationY() < 0) { |
| 372 | // We got clipped to the parent here - make sure we undo that. |
| 373 | outRect.top += getTop() + getTranslationY(); |
| 374 | } |
Adrian Roos | b44f548 | 2015-06-11 12:19:16 -0700 | [diff] [blame] | 375 | outRect.bottom = outRect.top + getActualHeight(); |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 376 | outRect.top += getClipTopAmount(); |
Adrian Roos | cd55f43 | 2015-06-10 16:42:53 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 379 | public boolean isSummaryWithChildren() { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 380 | return false; |
| 381 | } |
| 382 | |
| 383 | public boolean areChildrenExpanded() { |
| 384 | return false; |
| 385 | } |
| 386 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 387 | protected void updateClipping() { |
| 388 | if (mClipToActualHeight && shouldClipToActualHeight()) { |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 389 | int top = getClipTopAmount(); |
Selim Cinek | 5332849 | 2018-12-05 14:58:44 -0800 | [diff] [blame] | 390 | int bottom = Math.max(Math.max(getActualHeight() + getExtraBottomPadding() |
| 391 | - mClipBottomAmount, top), mMinimumHeightForClipping); |
| 392 | int halfExtraWidth = (int) (mExtraWidthForClipping / 2.0f); |
| 393 | mClipRect.set(-halfExtraWidth, top, getWidth() + halfExtraWidth, bottom); |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 394 | setClipBounds(mClipRect); |
| 395 | } else { |
| 396 | setClipBounds(null); |
Selim Cinek | f92a1fd | 2015-07-31 16:10:32 -0700 | [diff] [blame] | 397 | } |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 398 | } |
| 399 | |
Selim Cinek | 5332849 | 2018-12-05 14:58:44 -0800 | [diff] [blame] | 400 | public void setMinimumHeightForClipping(int minimumHeightForClipping) { |
| 401 | mMinimumHeightForClipping = minimumHeightForClipping; |
| 402 | updateClipping(); |
| 403 | } |
| 404 | |
| 405 | public void setExtraWidthForClipping(float extraWidthForClipping) { |
| 406 | mExtraWidthForClipping = extraWidthForClipping; |
| 407 | updateClipping(); |
| 408 | } |
| 409 | |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 410 | public float getHeaderVisibleAmount() { |
| 411 | return 1.0f; |
| 412 | } |
| 413 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 414 | protected boolean shouldClipToActualHeight() { |
| 415 | return true; |
| 416 | } |
| 417 | |
Selim Cinek | 4ffd636 | 2015-12-29 15:12:23 +0100 | [diff] [blame] | 418 | public void setClipToActualHeight(boolean clipToActualHeight) { |
| 419 | mClipToActualHeight = clipToActualHeight; |
| 420 | updateClipping(); |
Selim Cinek | a272dfe | 2015-02-20 18:12:28 +0100 | [diff] [blame] | 421 | } |
| 422 | |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 423 | public boolean willBeGone() { |
| 424 | return mWillBeGone; |
| 425 | } |
| 426 | |
| 427 | public void setWillBeGone(boolean willBeGone) { |
| 428 | mWillBeGone = willBeGone; |
| 429 | } |
| 430 | |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 431 | public int getMinClipTopAmount() { |
| 432 | return mMinClipTopAmount; |
| 433 | } |
| 434 | |
| 435 | public void setMinClipTopAmount(int minClipTopAmount) { |
| 436 | mMinClipTopAmount = minClipTopAmount; |
| 437 | } |
| 438 | |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 439 | @Override |
| 440 | public void setLayerType(int layerType, Paint paint) { |
| 441 | if (hasOverlappingRendering()) { |
| 442 | super.setLayerType(layerType, paint); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public boolean hasOverlappingRendering() { |
Selim Cinek | a69f2a6 | 2015-12-11 17:28:12 -0800 | [diff] [blame] | 448 | // Otherwise it will be clipped |
| 449 | return super.hasOverlappingRendering() && getActualHeight() <= getHeight(); |
Selim Cinek | 471e31a | 2015-12-11 13:39:48 -0800 | [diff] [blame] | 450 | } |
| 451 | |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 452 | /** |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 453 | * @return an amount between -1 and 1 of increased padding that this child needs. 1 means it |
| 454 | * needs a full increased padding while -1 means it needs no padding at all. For 0.0f the normal |
| 455 | * padding is applied. |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 456 | */ |
| 457 | public float getIncreasedPaddingAmount() { |
| 458 | return 0.0f; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 461 | public boolean mustStayOnScreen() { |
| 462 | return false; |
| 463 | } |
| 464 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 465 | public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd, |
| 466 | int outlineTranslation) { |
| 467 | } |
| 468 | |
| 469 | public float getOutlineAlpha() { |
| 470 | return 0.0f; |
| 471 | } |
| 472 | |
| 473 | public int getOutlineTranslation() { |
| 474 | return 0; |
| 475 | } |
| 476 | |
Adrian Roos | 14503e2 | 2016-03-09 14:01:24 -0800 | [diff] [blame] | 477 | public void setChangingPosition(boolean changingPosition) { |
| 478 | mChangingPosition = changingPosition; |
| 479 | } |
| 480 | |
| 481 | public boolean isChangingPosition() { |
| 482 | return mChangingPosition; |
| 483 | } |
| 484 | |
Selim Cinek | d139564 | 2016-04-28 12:22:42 -0700 | [diff] [blame] | 485 | public void setTransientContainer(ViewGroup transientContainer) { |
| 486 | mTransientContainer = transientContainer; |
| 487 | } |
| 488 | |
| 489 | public ViewGroup getTransientContainer() { |
| 490 | return mTransientContainer; |
| 491 | } |
| 492 | |
Selim Cinek | e32010a | 2014-08-20 23:50:41 +0200 | [diff] [blame] | 493 | /** |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 494 | * @return padding used to alter how much of the view is clipped. |
| 495 | */ |
| 496 | public int getExtraBottomPadding() { |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /** |
| 501 | * @return true if the group's expansion state is changing, false otherwise. |
| 502 | */ |
| 503 | public boolean isGroupExpansionChanging() { |
| 504 | return false; |
| 505 | } |
| 506 | |
| 507 | public boolean isGroupExpanded() { |
| 508 | return false; |
| 509 | } |
| 510 | |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 511 | public void setHeadsUpIsVisible() { |
| 512 | } |
| 513 | |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 514 | public boolean showingPulsing() { |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 515 | return false; |
| 516 | } |
| 517 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 518 | public boolean isChildInGroup() { |
| 519 | return false; |
| 520 | } |
| 521 | |
Adrian Roos | 599be34 | 2016-06-13 14:54:39 -0700 | [diff] [blame] | 522 | public void setActualHeightAnimating(boolean animating) {} |
| 523 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 524 | protected ExpandableViewState createExpandableViewState() { |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 525 | return new ExpandableViewState(); |
| 526 | } |
| 527 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 528 | /** Sets {@link ExpandableViewState} to default state. */ |
| 529 | public ExpandableViewState resetViewState() { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 530 | // initialize with the default values of the view |
| 531 | mViewState.height = getIntrinsicHeight(); |
| 532 | mViewState.gone = getVisibility() == View.GONE; |
| 533 | mViewState.alpha = 1f; |
| 534 | mViewState.notGoneIndex = -1; |
| 535 | mViewState.xTranslation = getTranslationX(); |
| 536 | mViewState.hidden = false; |
| 537 | mViewState.scaleX = getScaleX(); |
| 538 | mViewState.scaleY = getScaleY(); |
| 539 | mViewState.inShelf = false; |
| 540 | mViewState.headsUpIsVisible = false; |
| 541 | |
| 542 | // handling reset for child notifications |
| 543 | if (this instanceof ExpandableNotificationRow) { |
| 544 | ExpandableNotificationRow row = (ExpandableNotificationRow) this; |
| 545 | List<ExpandableNotificationRow> children = row.getNotificationChildren(); |
| 546 | if (row.isSummaryWithChildren() && children != null) { |
| 547 | for (ExpandableNotificationRow childRow : children) { |
| 548 | childRow.resetViewState(); |
| 549 | } |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | return mViewState; |
| 554 | } |
| 555 | |
| 556 | @Nullable public ExpandableViewState getViewState() { |
| 557 | return mViewState; |
| 558 | } |
| 559 | |
| 560 | /** Applies internal {@link ExpandableViewState} to this view. */ |
| 561 | public void applyViewState() { |
Dave Mankoff | c56db33 | 2018-12-10 11:31:49 -0500 | [diff] [blame] | 562 | if (!mViewState.gone) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 563 | mViewState.applyToView(this); |
| 564 | } |
| 565 | } |
| 566 | |
Mady Mellor | b0a8246 | 2016-04-30 17:31:02 -0700 | [diff] [blame] | 567 | /** |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 568 | * @return whether the current view doesn't add height to the overall content. This means that |
| 569 | * if it is added to a list of items, it's content will still have the same height. |
| 570 | * An example is the notification shelf, that is always placed on top of another view. |
| 571 | */ |
| 572 | public boolean hasNoContentHeight() { |
| 573 | return false; |
| 574 | } |
| 575 | |
| 576 | /** |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 577 | * @param inShelf whether the view is currently fully in the notification shelf. |
| 578 | */ |
| 579 | public void setInShelf(boolean inShelf) { |
| 580 | mInShelf = inShelf; |
| 581 | } |
| 582 | |
| 583 | public boolean isInShelf() { |
| 584 | return mInShelf; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * @param transformingInShelf whether the view is currently transforming into the shelf in an |
| 589 | * animated way |
| 590 | */ |
| 591 | public void setTransformingInShelf(boolean transformingInShelf) { |
| 592 | mTransformingInShelf = transformingInShelf; |
| 593 | } |
| 594 | |
| 595 | public boolean isTransformingIntoShelf() { |
| 596 | return mTransformingInShelf; |
| 597 | } |
| 598 | |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 599 | public boolean isAboveShelf() { |
| 600 | return false; |
| 601 | } |
| 602 | |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 603 | public boolean hasExpandingChild() { |
| 604 | return false; |
| 605 | } |
| 606 | |
Selim Cinek | 3088766 | 2018-10-15 17:37:21 -0700 | [diff] [blame] | 607 | @Override |
| 608 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 609 | } |
| 610 | |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 611 | /** |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 612 | * A listener notifying when {@link #getActualHeight} changes. |
| 613 | */ |
| 614 | public interface OnHeightChangedListener { |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 615 | |
| 616 | /** |
| 617 | * @param view the view for which the height changed, or {@code null} if just the top |
| 618 | * padding or the padding between the elements changed |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 619 | * @param needsAnimation whether the view height needs to be animated |
Jorim Jaggi | 30c305c | 2014-07-01 23:34:41 +0200 | [diff] [blame] | 620 | */ |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 621 | void onHeightChanged(ExpandableView view, boolean needsAnimation); |
Selim Cinek | a5e211b | 2014-08-11 17:35:48 +0200 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * Called when the view is reset and therefore the height will change abruptly |
| 625 | * |
| 626 | * @param view The view which was reset. |
| 627 | */ |
| 628 | void onReset(ExpandableView view); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 629 | } |
| 630 | } |