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