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