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 | |
Mady Mellor | 95d743c | 2017-01-10 12:05:27 -0800 | [diff] [blame] | 117 | interface OnSettingsClickListener { |
| 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); |
| 274 | // Circular reveal originating at (x, y) |
| 275 | Animator a = ViewAnimationUtils.createCircularReveal(this, x, y, 0, r); |
| 276 | a.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 277 | a.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
| 278 | a.addListener(new AnimateOpenListener(onAnimationEnd)); |
| 279 | a.start(); |
| 280 | } else { |
| 281 | // Fade in content |
| 282 | this.setAlpha(0f); |
| 283 | this.animate() |
| 284 | .alpha(1f) |
| 285 | .setDuration(StackStateAnimator.ANIMATION_DURATION_BLOCKING_HELPER_FADE) |
| 286 | .setInterpolator(Interpolators.ALPHA_IN) |
| 287 | .setListener(new AnimateOpenListener(onAnimationEnd)) |
| 288 | .start(); |
| 289 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 290 | } else { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 291 | Log.w(TAG, "Failed to animate guts open"); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 292 | } |
yoshiki iguchi | a85c2a0 | 2018-01-12 11:28:06 +0900 | [diff] [blame] | 293 | } |
| 294 | |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 295 | |
| 296 | /** 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] | 297 | @VisibleForTesting |
| 298 | void animateClose(int x, int y, boolean shouldDoCircularReveal) { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 299 | if (isAttachedToWindow()) { |
| 300 | if (shouldDoCircularReveal) { |
| 301 | // Circular reveal originating at (x, y) |
| 302 | if (x == -1 || y == -1) { |
| 303 | x = (getLeft() + getRight()) / 2; |
| 304 | y = (getTop() + getHeight() / 2); |
| 305 | } |
| 306 | double horz = Math.max(getWidth() - x, x); |
| 307 | double vert = Math.max(getHeight() - y, y); |
| 308 | float r = (float) Math.hypot(horz, vert); |
| 309 | Animator a = ViewAnimationUtils.createCircularReveal(this, |
| 310 | x, y, r, 0); |
| 311 | a.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 312 | a.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 313 | a.addListener(new AnimateCloseListener(this /* view */, mGutsContent)); |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 314 | a.start(); |
| 315 | } else { |
| 316 | // Fade in the blocking helper. |
| 317 | this.animate() |
| 318 | .alpha(0f) |
| 319 | .setDuration(StackStateAnimator.ANIMATION_DURATION_BLOCKING_HELPER_FADE) |
| 320 | .setInterpolator(Interpolators.ALPHA_OUT) |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 321 | .setListener(new AnimateCloseListener(this, /* view */mGutsContent)) |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 322 | .start(); |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 323 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 324 | } else { |
Rohan Shah | 08f5858 | 2018-05-04 16:31:43 -0700 | [diff] [blame] | 325 | Log.w(TAG, "Failed to animate guts close"); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 326 | mGutsContent.onFinishedClosing(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 327 | } |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 330 | public void setActualHeight(int actualHeight) { |
| 331 | mActualHeight = actualHeight; |
| 332 | invalidate(); |
| 333 | } |
| 334 | |
| 335 | public int getActualHeight() { |
| 336 | return mActualHeight; |
| 337 | } |
| 338 | |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 339 | public int getIntrinsicHeight() { |
| 340 | return mGutsContent != null && mExposed ? mGutsContent.getActualHeight() : getHeight(); |
| 341 | } |
| 342 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 343 | public void setClipTopAmount(int clipTopAmount) { |
| 344 | mClipTopAmount = clipTopAmount; |
| 345 | invalidate(); |
| 346 | } |
| 347 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 348 | public void setClipBottomAmount(int clipBottomAmount) { |
| 349 | mClipBottomAmount = clipBottomAmount; |
| 350 | invalidate(); |
| 351 | } |
| 352 | |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 353 | @Override |
| 354 | public boolean hasOverlappingRendering() { |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 355 | // Prevents this view from creating a layer when alpha is animating. |
| 356 | return false; |
| 357 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 358 | |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 359 | public void setClosedListener(OnGutsClosedListener listener) { |
Mady Mellor | e09fb70 | 2017-03-30 13:23:29 -0700 | [diff] [blame] | 360 | mClosedListener = listener; |
| 361 | } |
| 362 | |
| 363 | public void setHeightChangedListener(OnHeightChangedListener listener) { |
| 364 | mHeightListener = listener; |
| 365 | } |
| 366 | |
| 367 | protected void onHeightChanged() { |
| 368 | if (mHeightListener != null) { |
| 369 | mHeightListener.onHeightChanged(this); |
| 370 | } |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Rohan Shah | da5dcdd | 2018-04-27 17:21:50 -0700 | [diff] [blame] | 373 | @VisibleForTesting |
| 374 | void setExposed(boolean exposed, boolean needsFalsingProtection) { |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 375 | final boolean wasExposed = mExposed; |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 376 | mExposed = exposed; |
Mady Mellor | 97c8df4 | 2016-03-22 18:09:39 -0700 | [diff] [blame] | 377 | mNeedsFalsingProtection = needsFalsingProtection; |
| 378 | if (mExposed && mNeedsFalsingProtection) { |
| 379 | resetFalsingCheck(); |
| 380 | } else { |
| 381 | mHandler.removeCallbacks(mFalsingCheck); |
| 382 | } |
Geoffrey Pitsch | d94e788 | 2017-04-06 09:52:11 -0400 | [diff] [blame] | 383 | if (wasExposed != mExposed && mGutsContent != null) { |
| 384 | final View contentView = mGutsContent.getContentView(); |
| 385 | contentView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED); |
| 386 | if (mExposed) { |
| 387 | contentView.requestAccessibilityFocus(); |
| 388 | } |
| 389 | } |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 390 | } |
| 391 | |
Mady Mellor | 434180c | 2017-02-13 11:29:42 -0800 | [diff] [blame] | 392 | public boolean willBeRemoved() { |
| 393 | return mGutsContent != null ? mGutsContent.willBeRemoved() : false; |
| 394 | } |
| 395 | |
Geoffrey Pitsch | 4dd5006 | 2016-12-06 16:41:22 -0500 | [diff] [blame] | 396 | public boolean isExposed() { |
Selim Cinek | d84a593 | 2015-12-15 11:45:36 -0800 | [diff] [blame] | 397 | return mExposed; |
| 398 | } |
Mady Mellor | 32343e6 | 2017-07-19 10:52:47 -0700 | [diff] [blame] | 399 | |
| 400 | public boolean isLeavebehind() { |
| 401 | return mGutsContent != null && mGutsContent.isLeavebehind(); |
| 402 | } |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 403 | |
| 404 | /** Listener for animations executed in {@link #animateOpen(boolean, int, int, Runnable)}. */ |
| 405 | private static class AnimateOpenListener extends AnimatorListenerAdapter { |
| 406 | final Runnable mOnAnimationEnd; |
| 407 | |
| 408 | private AnimateOpenListener(Runnable onAnimationEnd) { |
| 409 | mOnAnimationEnd = onAnimationEnd; |
| 410 | } |
| 411 | |
| 412 | @Override |
| 413 | public void onAnimationEnd(Animator animation) { |
| 414 | super.onAnimationEnd(animation); |
| 415 | if (mOnAnimationEnd != null) { |
| 416 | mOnAnimationEnd.run(); |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | /** Listener for animations executed in {@link #animateClose(int, int, boolean)}. */ |
| 422 | private static class AnimateCloseListener extends AnimatorListenerAdapter { |
| 423 | final View mView; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 424 | private final GutsContent mGutsContent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 425 | |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 426 | private AnimateCloseListener(View view, GutsContent gutsContent) { |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 427 | mView = view; |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 428 | mGutsContent = gutsContent; |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | @Override |
| 432 | public void onAnimationEnd(Animator animation) { |
| 433 | super.onAnimationEnd(animation); |
| 434 | mView.setVisibility(View.GONE); |
Gus Prevas | 9abc506 | 2018-10-31 16:11:04 -0400 | [diff] [blame^] | 435 | mGutsContent.onFinishedClosing(); |
Rohan Shah | 524cf7b | 2018-03-15 14:40:02 -0700 | [diff] [blame] | 436 | } |
| 437 | } |
Selim Cinek | 024ca59 | 2014-09-01 15:11:28 +0200 | [diff] [blame] | 438 | } |