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