Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.row; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 18 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 21 | import android.content.Context; |
Julia Reynolds | 3aa969f | 2016-05-26 11:07:49 -0400 | [diff] [blame] | 22 | import android.content.res.TypedArray; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 23 | import android.graphics.Canvas; |
| 24 | import android.graphics.drawable.Drawable; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 25 | import android.os.Handler; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 26 | import android.util.AttributeSet; |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 27 | import android.util.Log; |
Julia Reynolds | a07af88 | 2015-12-17 08:32:48 -0500 | [diff] [blame] | 28 | import android.view.View; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 29 | import android.view.ViewAnimationUtils; |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 30 | import android.view.accessibility.AccessibilityEvent; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 31 | import android.widget.FrameLayout; |
Julia Reynolds | ead00aa | 2015-12-07 08:23:48 -0500 | [diff] [blame] | 32 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 33 | import androidx.annotation.Nullable; |
| 34 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 35 | import com.android.internal.annotations.VisibleForTesting; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 36 | import com.android.systemui.Dependency; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 37 | import com.android.systemui.Interpolators; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 38 | import com.android.systemui.R; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 39 | import com.android.systemui.statusbar.notification.stack.StackStateAnimator; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * The guts of a notification revealed when performing a long press. |
| 43 | */ |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 44 | public class NotificationGuts extends FrameLayout { |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 45 | private static final String TAG = "NotificationGuts"; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 46 | private static final long CLOSE_GUTS_DELAY = 8000; |
| 47 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 48 | private Drawable mBackground; |
| 49 | private int mClipTopAmount; |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 50 | private int mClipBottomAmount; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 51 | private int mActualHeight; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 52 | private boolean mExposed; |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 53 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 54 | private Handler mHandler; |
| 55 | private Runnable mFalsingCheck; |
| 56 | private boolean mNeedsFalsingProtection; |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 57 | private OnGutsClosedListener mClosedListener; |
| 58 | private OnHeightChangedListener mHeightListener; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 59 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 60 | private GutsContent mGutsContent; |
| 61 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 62 | public interface GutsContent { |
| 63 | |
| 64 | public void setGutsParent(NotificationGuts listener); |
| 65 | |
| 66 | /** |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 67 | * Return the view to be shown in the notification guts. |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 68 | */ |
| 69 | public View getContentView(); |
| 70 | |
| 71 | /** |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 72 | * Return the actual height of the content. |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 73 | */ |
| 74 | public int getActualHeight(); |
| 75 | |
| 76 | /** |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 77 | * Called when the guts view have been told to close, typically after an outside |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 78 | * interaction. |
| 79 | * |
| 80 | * @param save whether the state should be saved. |
| 81 | * @param force whether the guts view should be forced closed regardless of state. |
| 82 | * @return if closing the view has been handled. |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 83 | */ |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 84 | public boolean handleCloseControls(boolean save, boolean force); |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 85 | |
| 86 | /** |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 87 | * Return whether the notification associated with these guts is set to be removed. |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 88 | */ |
| 89 | public boolean willBeRemoved(); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 90 | |
| 91 | /** |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 92 | * Return whether these guts are a leavebehind (e.g. {@link NotificationSnooze}). |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 93 | */ |
| 94 | public default boolean isLeavebehind() { |
| 95 | return false; |
| 96 | } |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Return whether something changed and needs to be saved, possibly requiring a bouncer. |
| 100 | */ |
| 101 | boolean shouldBeSaved(); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Called when the guts view has finished its close animation. |
| 105 | */ |
| 106 | default void onFinishedClosing() {} |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 107 | } |
| 108 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 109 | public interface OnGutsClosedListener { |
| 110 | public void onGutsClosed(NotificationGuts guts); |
| 111 | } |
| 112 | |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 113 | public interface OnHeightChangedListener { |
| 114 | public void onHeightChanged(NotificationGuts guts); |
| 115 | } |
| 116 | |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 117 | private interface OnSettingsClickListener { |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 118 | void onClick(View v, int appUid); |
| 119 | } |
| 120 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 121 | public NotificationGuts(Context context, AttributeSet attrs) { |
| 122 | super(context, attrs); |
| 123 | setWillNotDraw(false); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 124 | mHandler = new Handler(); |
| 125 | mFalsingCheck = new Runnable() { |
| 126 | @Override |
| 127 | public void run() { |
| 128 | if (mNeedsFalsingProtection && mExposed) { |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 129 | closeControls(-1 /* x */, -1 /* y */, false /* save */, false /* force */); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | }; |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 133 | final TypedArray ta = context.obtainStyledAttributes(attrs, |
| 134 | com.android.internal.R.styleable.Theme, 0, 0); |
Julia Reynolds | 3aa969f | 2016-05-26 11:07:49 -0400 | [diff] [blame] | 135 | ta.recycle(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 138 | public NotificationGuts(Context context) { |
| 139 | this(context, null); |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | public void setGutsContent(GutsContent content) { |
| 143 | mGutsContent = content; |
| 144 | removeAllViews(); |
| 145 | addView(mGutsContent.getContentView()); |
| 146 | } |
| 147 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 148 | public GutsContent getGutsContent() { |
| 149 | return mGutsContent; |
| 150 | } |
| 151 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 152 | public void resetFalsingCheck() { |
| 153 | mHandler.removeCallbacks(mFalsingCheck); |
| 154 | if (mNeedsFalsingProtection && mExposed) { |
| 155 | mHandler.postDelayed(mFalsingCheck, CLOSE_GUTS_DELAY); |
| 156 | } |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | @Override |
| 160 | protected void onDraw(Canvas canvas) { |
| 161 | draw(canvas, mBackground); |
| 162 | } |
| 163 | |
| 164 | private void draw(Canvas canvas, Drawable drawable) { |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 165 | int top = mClipTopAmount; |
| 166 | int bottom = mActualHeight - mClipBottomAmount; |
| 167 | if (drawable != null && top < bottom) { |
| 168 | drawable.setBounds(0, top, getWidth(), bottom); |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 169 | drawable.draw(canvas); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | @Override |
| 174 | protected void onFinishInflate() { |
| 175 | super.onFinishInflate(); |
| 176 | mBackground = mContext.getDrawable(R.drawable.notification_guts_bg); |
| 177 | if (mBackground != null) { |
| 178 | mBackground.setCallback(this); |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | @Override |
| 183 | protected boolean verifyDrawable(Drawable who) { |
| 184 | return super.verifyDrawable(who) || who == mBackground; |
| 185 | } |
| 186 | |
| 187 | @Override |
| 188 | protected void drawableStateChanged() { |
| 189 | drawableStateChanged(mBackground); |
| 190 | } |
| 191 | |
| 192 | private void drawableStateChanged(Drawable d) { |
| 193 | if (d != null && d.isStateful()) { |
| 194 | d.setState(getDrawableState()); |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | @Override |
| 199 | public void drawableHotspotChanged(float x, float y) { |
| 200 | if (mBackground != null) { |
| 201 | mBackground.setHotspot(x, y); |
| 202 | } |
| 203 | } |
| 204 | |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 205 | public void openControls( |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 206 | boolean shouldDoCircularReveal, |
| 207 | int x, |
| 208 | int y, |
| 209 | boolean needsFalsingProtection, |
| 210 | @Nullable Runnable onAnimationEnd) { |
| 211 | animateOpen(shouldDoCircularReveal, x, y, onAnimationEnd); |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 212 | setExposed(true /* exposed */, needsFalsingProtection); |
| 213 | } |
| 214 | |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 215 | /** |
| 216 | * Hide controls if they are visible |
| 217 | * @param leavebehinds true if leavebehinds should be closed |
| 218 | * @param controls true if controls should be closed |
| 219 | * @param x x coordinate to animate the close circular reveal with |
| 220 | * @param y y coordinate to animate the close circular reveal with |
| 221 | * @param force whether the guts should be force-closed regardless of state. |
| 222 | */ |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 223 | public void closeControls(boolean leavebehinds, boolean controls, int x, int y, boolean force) { |
| 224 | if (mGutsContent != null) { |
Lucas Dupin | 9b08c01 | 2018-05-16 19:53:32 -0700 | [diff] [blame] | 225 | if ((mGutsContent.isLeavebehind() && leavebehinds) |
| 226 | || (!mGutsContent.isLeavebehind() && controls)) { |
| 227 | closeControls(x, y, mGutsContent.shouldBeSaved(), force); |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 232 | /** |
| 233 | * Closes any exposed guts/views. |
| 234 | * |
| 235 | * @param x x coordinate to animate the close circular reveal with |
| 236 | * @param y y coordinate to animate the close circular reveal with |
| 237 | * @param save whether the state should be saved |
| 238 | * @param force whether the guts should be force-closed regardless of state. |
| 239 | */ |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 240 | public void closeControls(int x, int y, boolean save, boolean force) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 241 | // First try to dismiss any blocking helper. |
| 242 | boolean wasBlockingHelperDismissed = |
| 243 | Dependency.get(NotificationBlockingHelperManager.class) |
| 244 | .dismissCurrentBlockingHelper(); |
| 245 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 246 | if (getWindowToken() == null) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 247 | if (mClosedListener != null) { |
| 248 | mClosedListener.onGutsClosed(this); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 249 | } |
| 250 | return; |
| 251 | } |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 252 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 253 | if (mGutsContent == null |
| 254 | || !mGutsContent.handleCloseControls(save, force) |
| 255 | || wasBlockingHelperDismissed) { |
| 256 | // We only want to do a circular reveal if we're not showing the blocking helper. |
| 257 | animateClose(x, y, !wasBlockingHelperDismissed /* shouldDoCircularReveal */); |
| 258 | |
Mady Mellor | c2dbe49 | 2017-03-30 13:22:03 -0700 | [diff] [blame] | 259 | setExposed(false, mNeedsFalsingProtection); |
| 260 | if (mClosedListener != null) { |
| 261 | mClosedListener.onGutsClosed(this); |
| 262 | } |
Mady Mellor | 87d7945 | 2017-01-10 11:52:52 -0800 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 266 | /** Animates in the guts view via either a fade or a circular reveal. */ |
| 267 | private void animateOpen( |
| 268 | boolean shouldDoCircularReveal, int x, int y, @Nullable Runnable onAnimationEnd) { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 269 | if (isAttachedToWindow()) { |
| 270 | if (shouldDoCircularReveal) { |
| 271 | double horz = Math.max(getWidth() - x, x); |
| 272 | double vert = Math.max(getHeight() - y, y); |
| 273 | float r = (float) Math.hypot(horz, vert); |
Evan Laird | e55c601 | 2019-03-13 12:54:37 -0400 | [diff] [blame] | 274 | // Make sure we'll be visible after the circular reveal |
| 275 | setAlpha(1f); |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 276 | // Circular reveal originating at (x, y) |
| 277 | Animator a = ViewAnimationUtils.createCircularReveal(this, x, y, 0, r); |
| 278 | a.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 279 | a.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
| 280 | a.addListener(new AnimateOpenListener(onAnimationEnd)); |
| 281 | a.start(); |
| 282 | } else { |
| 283 | // Fade in content |
| 284 | this.setAlpha(0f); |
| 285 | this.animate() |
| 286 | .alpha(1f) |
| 287 | .setDuration(StackStateAnimator.ANIMATION_DURATION_BLOCKING_HELPER_FADE) |
| 288 | .setInterpolator(Interpolators.ALPHA_IN) |
| 289 | .setListener(new AnimateOpenListener(onAnimationEnd)) |
| 290 | .start(); |
| 291 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 292 | } else { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 293 | Log.w(TAG, "Failed to animate guts open"); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 294 | } |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 295 | } |
| 296 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 297 | |
| 298 | /** Animates out the guts view via either a fade or a circular reveal. */ |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 299 | @VisibleForTesting |
| 300 | void animateClose(int x, int y, boolean shouldDoCircularReveal) { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 301 | if (isAttachedToWindow()) { |
| 302 | if (shouldDoCircularReveal) { |
| 303 | // Circular reveal originating at (x, y) |
| 304 | if (x == -1 || y == -1) { |
| 305 | x = (getLeft() + getRight()) / 2; |
| 306 | y = (getTop() + getHeight() / 2); |
| 307 | } |
| 308 | double horz = Math.max(getWidth() - x, x); |
| 309 | double vert = Math.max(getHeight() - y, y); |
| 310 | float r = (float) Math.hypot(horz, vert); |
| 311 | Animator a = ViewAnimationUtils.createCircularReveal(this, |
| 312 | x, y, r, 0); |
| 313 | a.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 314 | a.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 315 | a.addListener(new AnimateCloseListener(this /* view */, mGutsContent)); |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 316 | a.start(); |
| 317 | } else { |
| 318 | // Fade in the blocking helper. |
| 319 | this.animate() |
| 320 | .alpha(0f) |
| 321 | .setDuration(StackStateAnimator.ANIMATION_DURATION_BLOCKING_HELPER_FADE) |
| 322 | .setInterpolator(Interpolators.ALPHA_OUT) |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 323 | .setListener(new AnimateCloseListener(this, /* view */mGutsContent)) |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 324 | .start(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 325 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 326 | } else { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 327 | Log.w(TAG, "Failed to animate guts close"); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 328 | mGutsContent.onFinishedClosing(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 329 | } |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 330 | } |
| 331 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 332 | public void setActualHeight(int actualHeight) { |
| 333 | mActualHeight = actualHeight; |
| 334 | invalidate(); |
| 335 | } |
| 336 | |
| 337 | public int getActualHeight() { |
| 338 | return mActualHeight; |
| 339 | } |
| 340 | |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 341 | public int getIntrinsicHeight() { |
| 342 | return mGutsContent != null && mExposed ? mGutsContent.getActualHeight() : getHeight(); |
| 343 | } |
| 344 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 345 | public void setClipTopAmount(int clipTopAmount) { |
| 346 | mClipTopAmount = clipTopAmount; |
| 347 | invalidate(); |
| 348 | } |
| 349 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 350 | public void setClipBottomAmount(int clipBottomAmount) { |
| 351 | mClipBottomAmount = clipBottomAmount; |
| 352 | invalidate(); |
| 353 | } |
| 354 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 355 | @Override |
| 356 | public boolean hasOverlappingRendering() { |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 357 | // Prevents this view from creating a layer when alpha is animating. |
| 358 | return false; |
| 359 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 360 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 361 | public void setClosedListener(OnGutsClosedListener listener) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 362 | mClosedListener = listener; |
| 363 | } |
| 364 | |
| 365 | public void setHeightChangedListener(OnHeightChangedListener listener) { |
| 366 | mHeightListener = listener; |
| 367 | } |
| 368 | |
| 369 | protected void onHeightChanged() { |
| 370 | if (mHeightListener != null) { |
| 371 | mHeightListener.onHeightChanged(this); |
| 372 | } |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 375 | @VisibleForTesting |
| 376 | void setExposed(boolean exposed, boolean needsFalsingProtection) { |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 377 | final boolean wasExposed = mExposed; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 378 | mExposed = exposed; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 379 | mNeedsFalsingProtection = needsFalsingProtection; |
| 380 | if (mExposed && mNeedsFalsingProtection) { |
| 381 | resetFalsingCheck(); |
| 382 | } else { |
| 383 | mHandler.removeCallbacks(mFalsingCheck); |
| 384 | } |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 385 | if (wasExposed != mExposed && mGutsContent != null) { |
| 386 | final View contentView = mGutsContent.getContentView(); |
| 387 | contentView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 388 | if (mExposed) { |
| 389 | contentView.requestAccessibilityFocus(); |
| 390 | } |
| 391 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 394 | public boolean willBeRemoved() { |
| 395 | return mGutsContent != null ? mGutsContent.willBeRemoved() : false; |
| 396 | } |
| 397 | |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 398 | public boolean isExposed() { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 399 | return mExposed; |
| 400 | } |
Mady Mellor | 32343e6 | 2017-07-19 10:52:47 -0700 | [diff] [blame] | 401 | |
| 402 | public boolean isLeavebehind() { |
| 403 | return mGutsContent != null && mGutsContent.isLeavebehind(); |
| 404 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 405 | |
| 406 | /** Listener for animations executed in {@link #animateOpen(boolean, int, int, Runnable)}. */ |
| 407 | private static class AnimateOpenListener extends AnimatorListenerAdapter { |
| 408 | final Runnable mOnAnimationEnd; |
| 409 | |
| 410 | private AnimateOpenListener(Runnable onAnimationEnd) { |
| 411 | mOnAnimationEnd = onAnimationEnd; |
| 412 | } |
| 413 | |
| 414 | @Override |
| 415 | public void onAnimationEnd(Animator animation) { |
| 416 | super.onAnimationEnd(animation); |
| 417 | if (mOnAnimationEnd != null) { |
| 418 | mOnAnimationEnd.run(); |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | /** Listener for animations executed in {@link #animateClose(int, int, boolean)}. */ |
| 424 | private static class AnimateCloseListener extends AnimatorListenerAdapter { |
| 425 | final View mView; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 426 | private final GutsContent mGutsContent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 427 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 428 | private AnimateCloseListener(View view, GutsContent gutsContent) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 429 | mView = view; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 430 | mGutsContent = gutsContent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | @Override |
| 434 | public void onAnimationEnd(Animator animation) { |
| 435 | super.onAnimationEnd(animation); |
| 436 | mView.setVisibility(View.GONE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame] | 437 | mGutsContent.onFinishedClosing(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 438 | } |
| 439 | } |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 440 | } |