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