Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 1 | /* |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 14 | * limitations under the License |
Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 15 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 16 | |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 19 | import android.animation.Animator; |
| 20 | import android.animation.AnimatorListenerAdapter; |
| 21 | import android.animation.ObjectAnimator; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 22 | import android.animation.TimeAnimator; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 23 | import android.animation.ValueAnimator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.content.Context; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 25 | import android.graphics.Canvas; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 26 | import android.graphics.Color; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 27 | import android.graphics.RectF; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.util.AttributeSet; |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 29 | import android.view.MotionEvent; |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 30 | import android.view.View; |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 31 | import android.view.ViewAnimationUtils; |
Selim Cinek | ae1bbbb | 2016-12-13 16:06:02 -0800 | [diff] [blame] | 32 | import android.view.accessibility.AccessibilityManager; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 33 | import android.view.animation.Interpolator; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 34 | import android.view.animation.PathInterpolator; |
ztenghui | 62f30e0 | 2014-06-05 09:55:04 -0700 | [diff] [blame] | 35 | |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 36 | import com.android.systemui.Interpolators; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 37 | import com.android.systemui.R; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 38 | import com.android.systemui.classifier.FalsingManager; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 39 | import com.android.systemui.statusbar.notification.FakeShadowView; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 40 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Adrian Roos | 28a0de9 | 2017-02-21 21:38:12 +0100 | [diff] [blame] | 41 | import com.android.systemui.statusbar.phone.DoubleTapHelper; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 42 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 43 | import com.android.systemui.statusbar.stack.StackStateAnimator; |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 44 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 45 | /** |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 46 | * Base class for both {@link ExpandableNotificationRow} and {@link NotificationShelf} |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 47 | * to implement dimming/activating on Keyguard for the double-tap gesture |
| 48 | */ |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 49 | public abstract class ActivatableNotificationView extends ExpandableOutlineView { |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 50 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 51 | private static final int BACKGROUND_ANIMATION_LENGTH_MS = 220; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 52 | private static final int ACTIVATE_ANIMATION_LENGTH = 220; |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 53 | private static final long DARK_ANIMATION_LENGTH = StackStateAnimator.ANIMATION_DURATION_WAKEUP; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 54 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 55 | /** |
| 56 | * The amount of width, which is kept in the end when performing a disappear animation (also |
| 57 | * the amount from which the horizontal appearing begins) |
| 58 | */ |
| 59 | private static final float HORIZONTAL_COLLAPSED_REST_PARTIAL = 0.05f; |
| 60 | |
| 61 | /** |
| 62 | * At which point from [0,1] does the horizontal collapse animation end (or start when |
| 63 | * expanding)? 1.0 meaning that it ends immediately and 0.0 that it is continuously animated. |
| 64 | */ |
| 65 | private static final float HORIZONTAL_ANIMATION_END = 0.2f; |
| 66 | |
| 67 | /** |
| 68 | * At which point from [0,1] does the alpha animation end (or start when |
| 69 | * expanding)? 1.0 meaning that it ends immediately and 0.0 that it is continuously animated. |
| 70 | */ |
| 71 | private static final float ALPHA_ANIMATION_END = 0.0f; |
| 72 | |
| 73 | /** |
| 74 | * At which point from [0,1] does the horizontal collapse animation start (or start when |
| 75 | * expanding)? 1.0 meaning that it starts immediately and 0.0 that it is animated at all. |
| 76 | */ |
| 77 | private static final float HORIZONTAL_ANIMATION_START = 1.0f; |
| 78 | |
| 79 | /** |
| 80 | * At which point from [0,1] does the vertical collapse animation start (or end when |
| 81 | * expanding) 1.0 meaning that it starts immediately and 0.0 that it is animated at all. |
| 82 | */ |
| 83 | private static final float VERTICAL_ANIMATION_START = 1.0f; |
| 84 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 85 | /** |
| 86 | * Scale for the background to animate from when exiting dark mode. |
| 87 | */ |
| 88 | private static final float DARK_EXIT_SCALE_START = 0.93f; |
| 89 | |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 90 | /** |
| 91 | * A sentinel value when no color should be used. Can be used with {@link #setTintColor(int)} |
| 92 | * or {@link #setOverrideTintColor(int, float)}. |
| 93 | */ |
| 94 | protected static final int NO_COLOR = 0; |
| 95 | |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 96 | private static final Interpolator ACTIVATE_INVERSE_INTERPOLATOR |
| 97 | = new PathInterpolator(0.6f, 0, 0.5f, 1); |
| 98 | private static final Interpolator ACTIVATE_INVERSE_ALPHA_INTERPOLATOR |
| 99 | = new PathInterpolator(0, 0, 0.5f, 1); |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 100 | private final int mTintedRippleColor; |
| 101 | private final int mLowPriorityRippleColor; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 102 | protected final int mNormalRippleColor; |
Selim Cinek | ae1bbbb | 2016-12-13 16:06:02 -0800 | [diff] [blame] | 103 | private final AccessibilityManager mAccessibilityManager; |
Adrian Roos | 28a0de9 | 2017-02-21 21:38:12 +0100 | [diff] [blame] | 104 | private final DoubleTapHelper mDoubleTapHelper; |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 105 | |
| 106 | private boolean mDimmed; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 107 | private boolean mDark; |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 108 | |
Selim Cinek | 9910483 | 2017-01-25 14:47:33 -0800 | [diff] [blame] | 109 | protected int mBgTint = NO_COLOR; |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 110 | private float mBgAlpha = 1f; |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 111 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 112 | /** |
| 113 | * Flag to indicate that the notification has been touched once and the second touch will |
| 114 | * click it. |
| 115 | */ |
| 116 | private boolean mActivated; |
| 117 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 118 | private OnActivatedListener mOnActivatedListener; |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 119 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 120 | private final Interpolator mSlowOutFastInInterpolator; |
| 121 | private final Interpolator mSlowOutLinearInInterpolator; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 122 | private Interpolator mCurrentAppearInterpolator; |
| 123 | private Interpolator mCurrentAlphaInterpolator; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 124 | |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 125 | protected NotificationBackgroundView mBackgroundNormal; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 126 | private NotificationBackgroundView mBackgroundDimmed; |
| 127 | private ObjectAnimator mBackgroundAnimator; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 128 | private RectF mAppearAnimationRect = new RectF(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 129 | private float mAnimationTranslationY; |
| 130 | private boolean mDrawingAppearAnimation; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 131 | private ValueAnimator mAppearAnimator; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 132 | private ValueAnimator mBackgroundColorAnimator; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 133 | private float mAppearAnimationFraction = -1.0f; |
| 134 | private float mAppearAnimationTranslation; |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 135 | private final int mNormalColor; |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 136 | private final int mLowPriorityColor; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 137 | private boolean mIsBelowSpeedBump; |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 138 | private FalsingManager mFalsingManager; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 139 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 140 | private float mNormalBackgroundVisibilityAmount; |
| 141 | private ValueAnimator mFadeInFromDarkAnimator; |
Selim Cinek | 7baaa9e | 2016-07-21 17:21:09 -0700 | [diff] [blame] | 142 | private float mDimmedBackgroundFadeInAmount = -1; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 143 | private ValueAnimator.AnimatorUpdateListener mBackgroundVisibilityUpdater |
| 144 | = new ValueAnimator.AnimatorUpdateListener() { |
| 145 | @Override |
| 146 | public void onAnimationUpdate(ValueAnimator animation) { |
| 147 | setNormalBackgroundVisibilityAmount(mBackgroundNormal.getAlpha()); |
Selim Cinek | 7baaa9e | 2016-07-21 17:21:09 -0700 | [diff] [blame] | 148 | mDimmedBackgroundFadeInAmount = mBackgroundDimmed.getAlpha(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 149 | } |
| 150 | }; |
| 151 | private AnimatorListenerAdapter mFadeInEndListener = new AnimatorListenerAdapter() { |
| 152 | @Override |
| 153 | public void onAnimationEnd(Animator animation) { |
| 154 | super.onAnimationEnd(animation); |
| 155 | mFadeInFromDarkAnimator = null; |
Selim Cinek | 7baaa9e | 2016-07-21 17:21:09 -0700 | [diff] [blame] | 156 | mDimmedBackgroundFadeInAmount = -1; |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 157 | updateBackground(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 158 | } |
| 159 | }; |
| 160 | private ValueAnimator.AnimatorUpdateListener mUpdateOutlineListener |
| 161 | = new ValueAnimator.AnimatorUpdateListener() { |
| 162 | @Override |
| 163 | public void onAnimationUpdate(ValueAnimator animation) { |
| 164 | updateOutlineAlpha(); |
| 165 | } |
| 166 | }; |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 167 | private float mShadowAlpha = 1.0f; |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 168 | private FakeShadowView mFakeShadow; |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 169 | private int mCurrentBackgroundTint; |
| 170 | private int mTargetTint; |
| 171 | private int mStartTint; |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 172 | private int mOverrideTint; |
| 173 | private float mOverrideAmount; |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 174 | private boolean mShadowHidden; |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 175 | /** |
| 176 | * Similar to mDimmed but is also true if it's not dimmable but should be |
| 177 | */ |
| 178 | private boolean mNeedsDimming; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 179 | private int mDimmedAlpha; |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 180 | private boolean mBlockNextTouch; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 181 | |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 182 | public ActivatableNotificationView(Context context, AttributeSet attrs) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | super(context, attrs); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 184 | mSlowOutFastInInterpolator = new PathInterpolator(0.8f, 0.0f, 0.6f, 1.0f); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 185 | mSlowOutLinearInInterpolator = new PathInterpolator(0.8f, 0.0f, 1.0f, 1.0f); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 186 | setClipChildren(false); |
| 187 | setClipToPadding(false); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 188 | mNormalColor = context.getColor(R.color.notification_material_background_color); |
| 189 | mLowPriorityColor = context.getColor( |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 190 | R.color.notification_material_background_low_priority_color); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 191 | mTintedRippleColor = context.getColor( |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 192 | R.color.notification_ripple_tinted_color); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 193 | mLowPriorityRippleColor = context.getColor( |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 194 | R.color.notification_ripple_color_low_priority); |
Alan Viverette | 4a357cd | 2015-03-18 18:37:18 -0700 | [diff] [blame] | 195 | mNormalRippleColor = context.getColor( |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 196 | R.color.notification_ripple_untinted_color); |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 197 | mFalsingManager = FalsingManager.getInstance(context); |
Selim Cinek | ae1bbbb | 2016-12-13 16:06:02 -0800 | [diff] [blame] | 198 | mAccessibilityManager = AccessibilityManager.getInstance(mContext); |
Adrian Roos | 28a0de9 | 2017-02-21 21:38:12 +0100 | [diff] [blame] | 199 | |
| 200 | mDoubleTapHelper = new DoubleTapHelper(this, (active) -> { |
| 201 | if (active) { |
| 202 | makeActive(); |
| 203 | } else { |
| 204 | makeInactive(true /* animate */); |
| 205 | } |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 206 | }, super::performClick, this::handleSlideBack, mFalsingManager::onNotificationDoubleTap); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | @Override |
| 210 | protected void onFinishInflate() { |
| 211 | super.onFinishInflate(); |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 212 | mBackgroundNormal = findViewById(R.id.backgroundNormal); |
| 213 | mFakeShadow = findViewById(R.id.fake_shadow); |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 214 | mShadowHidden = mFakeShadow.getVisibility() != VISIBLE; |
Alan Viverette | 51efddb | 2017-04-05 10:00:01 -0400 | [diff] [blame] | 215 | mBackgroundDimmed = findViewById(R.id.backgroundDimmed); |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 216 | mDimmedAlpha = Color.alpha(mContext.getColor( |
| 217 | R.color.notification_material_background_dimmed_color)); |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 218 | initBackground(); |
Adrian Roos | bcbb75a | 2014-05-27 16:38:11 +0200 | [diff] [blame] | 219 | updateBackground(); |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 220 | updateBackgroundTint(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 221 | updateOutlineAlpha(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | } |
| 223 | |
Anthony Chen | ad4d158 | 2017-04-10 16:07:58 -0700 | [diff] [blame] | 224 | /** |
| 225 | * Sets the custom backgrounds on {@link #mBackgroundNormal} and {@link #mBackgroundDimmed}. |
| 226 | * This method can also be used to reload the backgrounds on both of those views, which can |
| 227 | * be useful in a configuration change. |
| 228 | */ |
| 229 | protected void initBackground() { |
| 230 | mBackgroundNormal.setCustomBackground(R.drawable.notification_material_bg); |
| 231 | mBackgroundDimmed.setCustomBackground(R.drawable.notification_material_bg_dim); |
| 232 | } |
| 233 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 234 | private final Runnable mTapTimeoutRunnable = new Runnable() { |
| 235 | @Override |
| 236 | public void run() { |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 237 | makeInactive(true /* animate */); |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 238 | } |
| 239 | }; |
| 240 | |
Svetoslav Ganov | 6179ea3 | 2011-06-28 01:12:41 -0700 | [diff] [blame] | 241 | @Override |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 242 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 243 | if (mNeedsDimming && ev.getActionMasked() == MotionEvent.ACTION_DOWN |
Selim Cinek | ae1bbbb | 2016-12-13 16:06:02 -0800 | [diff] [blame] | 244 | && disallowSingleClick(ev) && !isTouchExplorationEnabled()) { |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 245 | if (!mActivated) { |
| 246 | return true; |
| 247 | } else if (!mDoubleTapHelper.isWithinDoubleTapSlop(ev)) { |
| 248 | mBlockNextTouch = true; |
| 249 | makeInactive(true /* animate */); |
| 250 | return true; |
| 251 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 252 | } |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 253 | return super.onInterceptTouchEvent(ev); |
| 254 | } |
| 255 | |
Selim Cinek | ae1bbbb | 2016-12-13 16:06:02 -0800 | [diff] [blame] | 256 | private boolean isTouchExplorationEnabled() { |
| 257 | return mAccessibilityManager.isTouchExplorationEnabled(); |
| 258 | } |
| 259 | |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 260 | protected boolean disallowSingleClick(MotionEvent ev) { |
| 261 | return false; |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 262 | } |
| 263 | |
Mady Mellor | f062580 | 2016-02-11 18:03:48 -0800 | [diff] [blame] | 264 | protected boolean handleSlideBack() { |
| 265 | return false; |
| 266 | } |
| 267 | |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 268 | @Override |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 269 | public boolean onTouchEvent(MotionEvent event) { |
| 270 | boolean result; |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 271 | if (mBlockNextTouch) { |
| 272 | mBlockNextTouch = false; |
| 273 | return false; |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 274 | } |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 275 | if (mNeedsDimming && !isTouchExplorationEnabled() && isInteractive()) { |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 276 | boolean wasActivated = mActivated; |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 277 | result = handleTouchEventDimmed(event); |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 278 | if (wasActivated && result && event.getAction() == MotionEvent.ACTION_UP) { |
Selim Cinek | 6183d12 | 2016-01-14 18:48:41 -0800 | [diff] [blame] | 279 | removeCallbacks(mTapTimeoutRunnable); |
| 280 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 281 | } else { |
| 282 | result = super.onTouchEvent(event); |
| 283 | } |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 284 | return result; |
| 285 | } |
| 286 | |
Selim Cinek | c681346 | 2017-01-13 17:10:38 -0800 | [diff] [blame] | 287 | /** |
| 288 | * @return whether this view is interactive and can be double tapped |
| 289 | */ |
| 290 | protected boolean isInteractive() { |
| 291 | return true; |
| 292 | } |
| 293 | |
Selim Cinek | 570981d | 2015-12-01 11:37:01 -0800 | [diff] [blame] | 294 | @Override |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 295 | public void drawableHotspotChanged(float x, float y) { |
| 296 | if (!mDimmed){ |
| 297 | mBackgroundNormal.drawableHotspotChanged(x, y); |
| 298 | } |
| 299 | } |
| 300 | |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 301 | @Override |
| 302 | protected void drawableStateChanged() { |
| 303 | super.drawableStateChanged(); |
| 304 | if (mDimmed) { |
| 305 | mBackgroundDimmed.setState(getDrawableState()); |
| 306 | } else { |
| 307 | mBackgroundNormal.setState(getDrawableState()); |
| 308 | } |
| 309 | } |
| 310 | |
Selim Cinek | fe24fb7 | 2018-02-13 14:34:55 -0800 | [diff] [blame] | 311 | public void setRippleAllowed(boolean allowed) { |
| 312 | mBackgroundNormal.setPressedAllowed(allowed); |
| 313 | } |
| 314 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 315 | private boolean handleTouchEventDimmed(MotionEvent event) { |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 316 | if (mNeedsDimming && !mDimmed) { |
| 317 | // We're actually dimmed, but our content isn't dimmable, let's ensure we have a ripple |
| 318 | super.onTouchEvent(event); |
| 319 | } |
Adrian Roos | 28a0de9 | 2017-02-21 21:38:12 +0100 | [diff] [blame] | 320 | return mDoubleTapHelper.onTouchEvent(event, getActualHeight()); |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 323 | @Override |
| 324 | public boolean performClick() { |
Selim Cinek | c62635e | 2017-10-24 11:29:50 -0700 | [diff] [blame] | 325 | if (!mNeedsDimming || isTouchExplorationEnabled()) { |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 326 | return super.performClick(); |
| 327 | } |
| 328 | return false; |
| 329 | } |
| 330 | |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 331 | private void makeActive() { |
Blazej Magnowski | 0e2ffbd | 2015-09-10 14:37:17 -0700 | [diff] [blame] | 332 | mFalsingManager.onNotificationActive(); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 333 | startActivateAnimation(false /* reverse */); |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 334 | mActivated = true; |
Jorim Jaggi | ecbab36 | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 335 | if (mOnActivatedListener != null) { |
| 336 | mOnActivatedListener.onActivated(this); |
| 337 | } |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 338 | } |
| 339 | |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 340 | private void startActivateAnimation(final boolean reverse) { |
Selim Cinek | f4d7fc3 | 2014-09-26 17:15:34 +0200 | [diff] [blame] | 341 | if (!isAttachedToWindow()) { |
| 342 | return; |
| 343 | } |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 344 | if (!isDimmable()) { |
| 345 | return; |
| 346 | } |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 347 | int widthHalf = mBackgroundNormal.getWidth()/2; |
| 348 | int heightHalf = mBackgroundNormal.getActualHeight()/2; |
| 349 | float radius = (float) Math.sqrt(widthHalf*widthHalf + heightHalf*heightHalf); |
Selim Cinek | 6aaf217 | 2014-08-25 19:29:49 +0200 | [diff] [blame] | 350 | Animator animator; |
| 351 | if (reverse) { |
| 352 | animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, |
| 353 | widthHalf, heightHalf, radius, 0); |
| 354 | } else { |
| 355 | animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, |
| 356 | widthHalf, heightHalf, 0, radius); |
| 357 | } |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 358 | mBackgroundNormal.setVisibility(View.VISIBLE); |
| 359 | Interpolator interpolator; |
| 360 | Interpolator alphaInterpolator; |
| 361 | if (!reverse) { |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 362 | interpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
| 363 | alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 364 | } else { |
| 365 | interpolator = ACTIVATE_INVERSE_INTERPOLATOR; |
| 366 | alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR; |
| 367 | } |
| 368 | animator.setInterpolator(interpolator); |
| 369 | animator.setDuration(ACTIVATE_ANIMATION_LENGTH); |
| 370 | if (reverse) { |
| 371 | mBackgroundNormal.setAlpha(1f); |
| 372 | animator.addListener(new AnimatorListenerAdapter() { |
| 373 | @Override |
| 374 | public void onAnimationEnd(Animator animation) { |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 375 | updateBackground(); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 376 | } |
| 377 | }); |
Selim Cinek | 6aaf217 | 2014-08-25 19:29:49 +0200 | [diff] [blame] | 378 | animator.start(); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 379 | } else { |
| 380 | mBackgroundNormal.setAlpha(0.4f); |
| 381 | animator.start(); |
| 382 | } |
| 383 | mBackgroundNormal.animate() |
| 384 | .alpha(reverse ? 0f : 1f) |
| 385 | .setInterpolator(alphaInterpolator) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 386 | .setUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 387 | @Override |
| 388 | public void onAnimationUpdate(ValueAnimator animation) { |
| 389 | float animatedFraction = animation.getAnimatedFraction(); |
| 390 | if (reverse) { |
| 391 | animatedFraction = 1.0f - animatedFraction; |
| 392 | } |
| 393 | setNormalBackgroundVisibilityAmount(animatedFraction); |
| 394 | } |
| 395 | }) |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 396 | .setDuration(ACTIVATE_ANIMATION_LENGTH); |
| 397 | } |
| 398 | |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 399 | /** |
| 400 | * Cancels the hotspot and makes the notification inactive. |
| 401 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 402 | public void makeInactive(boolean animate) { |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 403 | if (mActivated) { |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 404 | mActivated = false; |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 405 | if (mDimmed) { |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 406 | if (animate) { |
| 407 | startActivateAnimation(true /* reverse */); |
| 408 | } else { |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 409 | updateBackground(); |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 410 | } |
Jorim Jaggi | bccb912 | 2014-05-08 14:55:48 +0200 | [diff] [blame] | 411 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 412 | } |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 413 | if (mOnActivatedListener != null) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 414 | mOnActivatedListener.onActivationReset(this); |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 415 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 416 | removeCallbacks(mTapTimeoutRunnable); |
| 417 | } |
| 418 | |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 419 | public void setDimmed(boolean dimmed, boolean fade) { |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 420 | mNeedsDimming = dimmed; |
| 421 | dimmed &= isDimmable(); |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 422 | if (mDimmed != dimmed) { |
| 423 | mDimmed = dimmed; |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 424 | resetBackgroundAlpha(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 425 | if (fade) { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 426 | fadeDimmedBackground(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 427 | } else { |
Jorim Jaggi | 3c3c3fc | 2014-05-20 23:16:42 +0200 | [diff] [blame] | 428 | updateBackground(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 429 | } |
Jorim Jaggi | 251957d | 2014-04-09 04:24:09 +0200 | [diff] [blame] | 430 | } |
| 431 | } |
| 432 | |
Selim Cinek | 63edaf2 | 2017-04-24 22:18:48 -0700 | [diff] [blame] | 433 | public boolean isDimmable() { |
| 434 | return true; |
| 435 | } |
| 436 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 437 | public void setDark(boolean dark, boolean fade, long delay) { |
| 438 | super.setDark(dark, fade, delay); |
| 439 | if (mDark == dark) { |
| 440 | return; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 441 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 442 | mDark = dark; |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 443 | updateBackground(); |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 444 | updateBackgroundTint(false); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 445 | if (!dark && fade && !shouldHideBackground()) { |
Selim Cinek | c430a5b | 2014-12-10 16:29:01 +0100 | [diff] [blame] | 446 | fadeInFromDark(delay); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 447 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 448 | updateOutlineAlpha(); |
| 449 | } |
| 450 | |
| 451 | private void updateOutlineAlpha() { |
| 452 | if (mDark) { |
| 453 | setOutlineAlpha(0f); |
| 454 | return; |
| 455 | } |
| 456 | float alpha = NotificationStackScrollLayout.BACKGROUND_ALPHA_DIMMED; |
| 457 | alpha = (alpha + (1.0f - alpha) * mNormalBackgroundVisibilityAmount); |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 458 | alpha *= mShadowAlpha; |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 459 | if (mFadeInFromDarkAnimator != null) { |
| 460 | alpha *= mFadeInFromDarkAnimator.getAnimatedFraction(); |
| 461 | } |
| 462 | setOutlineAlpha(alpha); |
| 463 | } |
| 464 | |
| 465 | public void setNormalBackgroundVisibilityAmount(float normalBackgroundVisibilityAmount) { |
| 466 | mNormalBackgroundVisibilityAmount = normalBackgroundVisibilityAmount; |
| 467 | updateOutlineAlpha(); |
| 468 | } |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 469 | |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 470 | @Override |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 471 | public void setBelowSpeedBump(boolean below) { |
| 472 | super.setBelowSpeedBump(below); |
| 473 | if (below != mIsBelowSpeedBump) { |
| 474 | mIsBelowSpeedBump = below; |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 475 | updateBackgroundTint(); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 476 | onBelowSpeedBumpChanged(); |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 477 | } |
| 478 | } |
| 479 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 480 | protected void onBelowSpeedBumpChanged() { |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * @return whether we are below the speed bump |
| 485 | */ |
| 486 | public boolean isBelowSpeedBump() { |
| 487 | return mIsBelowSpeedBump; |
| 488 | } |
| 489 | |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 490 | /** |
| 491 | * Sets the tint color of the background |
| 492 | */ |
| 493 | public void setTintColor(int color) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 494 | setTintColor(color, false); |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Sets the tint color of the background |
| 499 | */ |
| 500 | public void setTintColor(int color, boolean animated) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 501 | if (color != mBgTint) { |
| 502 | mBgTint = color; |
| 503 | updateBackgroundTint(animated); |
| 504 | } |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 505 | } |
| 506 | |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 507 | /** |
| 508 | * Set an override tint color that is used for the background. |
| 509 | * |
| 510 | * @param color the color that should be used to tint the background. |
| 511 | * This can be {@link #NO_COLOR} if the tint should be normally computed. |
| 512 | * @param overrideAmount a value from 0 to 1 how much the override tint should be used. The |
| 513 | * background color will then be the interpolation between this and the |
| 514 | * regular background color, where 1 means the overrideTintColor is fully |
| 515 | * used and the background color not at all. |
| 516 | */ |
| 517 | public void setOverrideTintColor(int color, float overrideAmount) { |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 518 | if (mDark) { |
| 519 | color = NO_COLOR; |
| 520 | overrideAmount = 0; |
| 521 | } |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 522 | mOverrideTint = color; |
| 523 | mOverrideAmount = overrideAmount; |
| 524 | int newColor = calculateBgColor(); |
| 525 | setBackgroundTintColor(newColor); |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 526 | if (!isDimmable() && mNeedsDimming) { |
| 527 | mBackgroundNormal.setDrawableAlpha((int) NotificationUtils.interpolate(255, |
| 528 | mDimmedAlpha, |
| 529 | overrideAmount)); |
| 530 | } else { |
| 531 | mBackgroundNormal.setDrawableAlpha(255); |
| 532 | } |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 533 | } |
| 534 | |
Selim Cinek | a6c6bfb | 2015-10-29 16:27:08 -0700 | [diff] [blame] | 535 | protected void updateBackgroundTint() { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 536 | updateBackgroundTint(false /* animated */); |
| 537 | } |
| 538 | |
| 539 | private void updateBackgroundTint(boolean animated) { |
| 540 | if (mBackgroundColorAnimator != null) { |
| 541 | mBackgroundColorAnimator.cancel(); |
| 542 | } |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 543 | int rippleColor = getRippleColor(); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 544 | mBackgroundDimmed.setRippleColor(rippleColor); |
| 545 | mBackgroundNormal.setRippleColor(rippleColor); |
| 546 | int color = calculateBgColor(); |
| 547 | if (!animated) { |
| 548 | setBackgroundTintColor(color); |
| 549 | } else if (color != mCurrentBackgroundTint) { |
| 550 | mStartTint = mCurrentBackgroundTint; |
| 551 | mTargetTint = color; |
| 552 | mBackgroundColorAnimator = ValueAnimator.ofFloat(0.0f, 1.0f); |
| 553 | mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 554 | @Override |
| 555 | public void onAnimationUpdate(ValueAnimator animation) { |
| 556 | int newColor = NotificationUtils.interpolateColors(mStartTint, mTargetTint, |
| 557 | animation.getAnimatedFraction()); |
| 558 | setBackgroundTintColor(newColor); |
| 559 | } |
| 560 | }); |
| 561 | mBackgroundColorAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); |
| 562 | mBackgroundColorAnimator.setInterpolator(Interpolators.LINEAR); |
| 563 | mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() { |
| 564 | @Override |
| 565 | public void onAnimationEnd(Animator animation) { |
| 566 | mBackgroundColorAnimator = null; |
| 567 | } |
| 568 | }); |
| 569 | mBackgroundColorAnimator.start(); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | private void setBackgroundTintColor(int color) { |
Selim Cinek | 65d418e | 2016-11-29 15:42:34 -0800 | [diff] [blame] | 574 | if (color != mCurrentBackgroundTint) { |
| 575 | mCurrentBackgroundTint = color; |
| 576 | if (color == mNormalColor) { |
| 577 | // We don't need to tint a normal notification |
| 578 | color = 0; |
| 579 | } |
| 580 | mBackgroundDimmed.setTint(color); |
| 581 | mBackgroundNormal.setTint(color); |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 582 | } |
Dan Sandler | fe266a3 | 2014-05-15 22:28:06 -0400 | [diff] [blame] | 583 | } |
| 584 | |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 585 | /** |
Selim Cinek | c430a5b | 2014-12-10 16:29:01 +0100 | [diff] [blame] | 586 | * Fades in the background when exiting dark mode. |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 587 | */ |
Selim Cinek | c430a5b | 2014-12-10 16:29:01 +0100 | [diff] [blame] | 588 | private void fadeInFromDark(long delay) { |
| 589 | final View background = mDimmed ? mBackgroundDimmed : mBackgroundNormal; |
| 590 | background.setAlpha(0f); |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 591 | mBackgroundVisibilityUpdater.onAnimationUpdate(null); |
Selim Cinek | c430a5b | 2014-12-10 16:29:01 +0100 | [diff] [blame] | 592 | background.animate() |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 593 | .alpha(1f) |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 594 | .setDuration(DARK_ANIMATION_LENGTH) |
| 595 | .setStartDelay(delay) |
Adrian Roos | 28f90c7 | 2017-05-08 17:24:26 -0700 | [diff] [blame] | 596 | .setInterpolator(Interpolators.ALPHA_IN) |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 597 | .setListener(new AnimatorListenerAdapter() { |
| 598 | @Override |
| 599 | public void onAnimationCancel(Animator animation) { |
| 600 | // Jump state if we are cancelled |
Selim Cinek | c430a5b | 2014-12-10 16:29:01 +0100 | [diff] [blame] | 601 | background.setAlpha(1f); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 602 | } |
| 603 | }) |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 604 | .setUpdateListener(mBackgroundVisibilityUpdater) |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 605 | .start(); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 606 | mFadeInFromDarkAnimator = TimeAnimator.ofFloat(0.0f, 1.0f); |
| 607 | mFadeInFromDarkAnimator.setDuration(DARK_ANIMATION_LENGTH); |
| 608 | mFadeInFromDarkAnimator.setStartDelay(delay); |
| 609 | mFadeInFromDarkAnimator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN); |
| 610 | mFadeInFromDarkAnimator.addListener(mFadeInEndListener); |
| 611 | mFadeInFromDarkAnimator.addUpdateListener(mUpdateOutlineListener); |
| 612 | mFadeInFromDarkAnimator.start(); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Fades the background when the dimmed state changes. |
| 617 | */ |
| 618 | private void fadeDimmedBackground() { |
| 619 | mBackgroundDimmed.animate().cancel(); |
Selim Cinek | 59d9723 | 2014-10-09 15:54:40 -0700 | [diff] [blame] | 620 | mBackgroundNormal.animate().cancel(); |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 621 | if (mActivated) { |
| 622 | updateBackground(); |
| 623 | return; |
| 624 | } |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 625 | if (!shouldHideBackground()) { |
| 626 | if (mDimmed) { |
| 627 | mBackgroundDimmed.setVisibility(View.VISIBLE); |
| 628 | } else { |
| 629 | mBackgroundNormal.setVisibility(View.VISIBLE); |
| 630 | } |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 631 | } |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 632 | float startAlpha = mDimmed ? 1f : 0; |
| 633 | float endAlpha = mDimmed ? 0 : 1f; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 634 | int duration = BACKGROUND_ANIMATION_LENGTH_MS; |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 635 | // Check whether there is already a background animation running. |
| 636 | if (mBackgroundAnimator != null) { |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 637 | startAlpha = (Float) mBackgroundAnimator.getAnimatedValue(); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 638 | duration = (int) mBackgroundAnimator.getCurrentPlayTime(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 639 | mBackgroundAnimator.removeAllListeners(); |
| 640 | mBackgroundAnimator.cancel(); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 641 | if (duration <= 0) { |
Jorim Jaggi | 3c3c3fc | 2014-05-20 23:16:42 +0200 | [diff] [blame] | 642 | updateBackground(); |
Jorim Jaggi | 98fb09c | 2014-05-01 22:40:56 +0200 | [diff] [blame] | 643 | return; |
| 644 | } |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 645 | } |
| 646 | mBackgroundNormal.setAlpha(startAlpha); |
| 647 | mBackgroundAnimator = |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 648 | ObjectAnimator.ofFloat(mBackgroundNormal, View.ALPHA, startAlpha, endAlpha); |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 649 | mBackgroundAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 650 | mBackgroundAnimator.setDuration(duration); |
| 651 | mBackgroundAnimator.addListener(new AnimatorListenerAdapter() { |
| 652 | @Override |
| 653 | public void onAnimationEnd(Animator animation) { |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 654 | updateBackground(); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 655 | mBackgroundAnimator = null; |
Selim Cinek | 3334a18 | 2016-09-22 16:19:42 -0700 | [diff] [blame] | 656 | if (mFadeInFromDarkAnimator == null) { |
| 657 | mDimmedBackgroundFadeInAmount = -1; |
| 658 | } |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 659 | } |
| 660 | }); |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 661 | mBackgroundAnimator.addUpdateListener(mBackgroundVisibilityUpdater); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 662 | mBackgroundAnimator.start(); |
| 663 | } |
| 664 | |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 665 | protected void updateBackgroundAlpha(float transformationAmount) { |
Selim Cinek | 7baaa9e | 2016-07-21 17:21:09 -0700 | [diff] [blame] | 666 | mBgAlpha = isChildInGroup() && mDimmed ? transformationAmount : 1f; |
| 667 | if (mDimmedBackgroundFadeInAmount != -1) { |
| 668 | mBgAlpha *= mDimmedBackgroundFadeInAmount; |
| 669 | } |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 670 | mBackgroundDimmed.setAlpha(mBgAlpha); |
| 671 | } |
| 672 | |
| 673 | protected void resetBackgroundAlpha() { |
| 674 | updateBackgroundAlpha(0f /* transformationAmount */); |
| 675 | } |
| 676 | |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 677 | protected void updateBackground() { |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 678 | cancelFadeAnimations(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 679 | if (shouldHideBackground()) { |
Adrian Roos | 500263a | 2017-01-23 14:49:54 -0800 | [diff] [blame] | 680 | mBackgroundDimmed.setVisibility(INVISIBLE); |
| 681 | mBackgroundNormal.setVisibility(mActivated ? VISIBLE : INVISIBLE); |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 682 | } else if (mDimmed) { |
Mady Mellor | c7d65b4 | 2016-05-04 11:44:57 -0400 | [diff] [blame] | 683 | // When groups are animating to the expanded state from the lockscreen, show the |
| 684 | // normal background instead of the dimmed background |
| 685 | final boolean dontShowDimmed = isGroupExpansionChanging() && isChildInGroup(); |
| 686 | mBackgroundDimmed.setVisibility(dontShowDimmed ? View.INVISIBLE : View.VISIBLE); |
| 687 | mBackgroundNormal.setVisibility((mActivated || dontShowDimmed) |
| 688 | ? View.VISIBLE |
| 689 | : View.INVISIBLE); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 690 | } else { |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 691 | mBackgroundDimmed.setVisibility(View.INVISIBLE); |
| 692 | mBackgroundNormal.setVisibility(View.VISIBLE); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 693 | mBackgroundNormal.setAlpha(1f); |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 694 | removeCallbacks(mTapTimeoutRunnable); |
Selim Cinek | 3ac0817 | 2016-03-09 10:48:36 -0800 | [diff] [blame] | 695 | // make in inactive to avoid it sticking around active |
| 696 | makeInactive(false /* animate */); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 697 | } |
Selim Cinek | d35c279 | 2016-01-21 13:20:57 -0800 | [diff] [blame] | 698 | setNormalBackgroundVisibilityAmount( |
| 699 | mBackgroundNormal.getVisibility() == View.VISIBLE ? 1.0f : 0.0f); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 700 | } |
| 701 | |
Selim Cinek | 2871bef | 2017-11-22 08:40:00 -0800 | [diff] [blame] | 702 | protected void updateBackgroundClipping() { |
| 703 | mBackgroundNormal.setBottomAmountClips(!isChildInGroup()); |
| 704 | mBackgroundDimmed.setBottomAmountClips(!isChildInGroup()); |
| 705 | } |
| 706 | |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 707 | protected boolean shouldHideBackground() { |
| 708 | return mDark; |
| 709 | } |
| 710 | |
Selim Cinek | 59d9723 | 2014-10-09 15:54:40 -0700 | [diff] [blame] | 711 | private void cancelFadeAnimations() { |
| 712 | if (mBackgroundAnimator != null) { |
| 713 | mBackgroundAnimator.cancel(); |
| 714 | } |
Jorim Jaggi | 4e857f4 | 2014-11-17 19:14:04 +0100 | [diff] [blame] | 715 | mBackgroundDimmed.animate().cancel(); |
Selim Cinek | 59d9723 | 2014-10-09 15:54:40 -0700 | [diff] [blame] | 716 | mBackgroundNormal.animate().cancel(); |
| 717 | } |
| 718 | |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 719 | @Override |
| 720 | protected void onLayout(boolean changed, int left, int top, int right, int bottom) { |
| 721 | super.onLayout(changed, left, top, right, bottom); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 722 | setPivotX(getWidth() / 2); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | @Override |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 726 | public void setActualHeight(int actualHeight, boolean notifyListeners) { |
| 727 | super.setActualHeight(actualHeight, notifyListeners); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 728 | setPivotY(actualHeight / 2); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 729 | mBackgroundNormal.setActualHeight(actualHeight); |
| 730 | mBackgroundDimmed.setActualHeight(actualHeight); |
Jorim Jaggi | 4222d9a | 2014-04-23 16:13:15 +0200 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | @Override |
| 734 | public void setClipTopAmount(int clipTopAmount) { |
| 735 | super.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | a8b48e1 | 2014-05-19 20:26:46 +0200 | [diff] [blame] | 736 | mBackgroundNormal.setClipTopAmount(clipTopAmount); |
| 737 | mBackgroundDimmed.setClipTopAmount(clipTopAmount); |
Jorim Jaggi | 4673985 | 2014-04-15 09:58:24 +0200 | [diff] [blame] | 738 | } |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 739 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 740 | @Override |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 741 | public void setClipBottomAmount(int clipBottomAmount) { |
| 742 | super.setClipBottomAmount(clipBottomAmount); |
| 743 | mBackgroundNormal.setClipBottomAmount(clipBottomAmount); |
| 744 | mBackgroundDimmed.setClipBottomAmount(clipBottomAmount); |
| 745 | } |
| 746 | |
| 747 | @Override |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 748 | public void performRemoveAnimation(long duration, float translationDirection, |
| 749 | Runnable onFinishedRunnable) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 750 | enableAppearDrawing(true); |
| 751 | if (mDrawingAppearAnimation) { |
| 752 | startAppearAnimation(false /* isAppearing */, translationDirection, |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 753 | 0, duration, onFinishedRunnable); |
Selim Cinek | 95ed592 | 2014-08-28 14:30:12 +0200 | [diff] [blame] | 754 | } else if (onFinishedRunnable != null) { |
| 755 | onFinishedRunnable.run(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 756 | } |
| 757 | } |
| 758 | |
| 759 | @Override |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 760 | public void performAddAnimation(long delay, long duration) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 761 | enableAppearDrawing(true); |
| 762 | if (mDrawingAppearAnimation) { |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 763 | startAppearAnimation(true /* isAppearing */, -1.0f, delay, duration, null); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 767 | private void startAppearAnimation(boolean isAppearing, float translationDirection, long delay, |
| 768 | long duration, final Runnable onFinishedRunnable) { |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 769 | cancelAppearAnimation(); |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 770 | mAnimationTranslationY = translationDirection * getActualHeight(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 771 | if (mAppearAnimationFraction == -1.0f) { |
| 772 | // not initialized yet, we start anew |
| 773 | if (isAppearing) { |
| 774 | mAppearAnimationFraction = 0.0f; |
| 775 | mAppearAnimationTranslation = mAnimationTranslationY; |
| 776 | } else { |
| 777 | mAppearAnimationFraction = 1.0f; |
| 778 | mAppearAnimationTranslation = 0; |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | float targetValue; |
| 783 | if (isAppearing) { |
| 784 | mCurrentAppearInterpolator = mSlowOutFastInInterpolator; |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 785 | mCurrentAlphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 786 | targetValue = 1.0f; |
| 787 | } else { |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 788 | mCurrentAppearInterpolator = Interpolators.FAST_OUT_SLOW_IN; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 789 | mCurrentAlphaInterpolator = mSlowOutLinearInInterpolator; |
| 790 | targetValue = 0.0f; |
| 791 | } |
| 792 | mAppearAnimator = ValueAnimator.ofFloat(mAppearAnimationFraction, |
| 793 | targetValue); |
Selim Cinek | c18010f | 2016-01-20 13:41:30 -0800 | [diff] [blame] | 794 | mAppearAnimator.setInterpolator(Interpolators.LINEAR); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 795 | mAppearAnimator.setDuration( |
Jorim Jaggi | 60d07c5 | 2014-07-31 15:38:21 +0200 | [diff] [blame] | 796 | (long) (duration * Math.abs(mAppearAnimationFraction - targetValue))); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 797 | mAppearAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { |
| 798 | @Override |
| 799 | public void onAnimationUpdate(ValueAnimator animation) { |
| 800 | mAppearAnimationFraction = (float) animation.getAnimatedValue(); |
| 801 | updateAppearAnimationAlpha(); |
| 802 | updateAppearRect(); |
| 803 | invalidate(); |
| 804 | } |
| 805 | }); |
| 806 | if (delay > 0) { |
| 807 | // we need to apply the initial state already to avoid drawn frames in the wrong state |
| 808 | updateAppearAnimationAlpha(); |
| 809 | updateAppearRect(); |
| 810 | mAppearAnimator.setStartDelay(delay); |
| 811 | } |
| 812 | mAppearAnimator.addListener(new AnimatorListenerAdapter() { |
| 813 | private boolean mWasCancelled; |
| 814 | |
| 815 | @Override |
| 816 | public void onAnimationEnd(Animator animation) { |
| 817 | if (onFinishedRunnable != null) { |
| 818 | onFinishedRunnable.run(); |
| 819 | } |
| 820 | if (!mWasCancelled) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 821 | enableAppearDrawing(false); |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 822 | onAppearAnimationFinished(isAppearing); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 823 | } |
| 824 | } |
| 825 | |
| 826 | @Override |
| 827 | public void onAnimationStart(Animator animation) { |
| 828 | mWasCancelled = false; |
| 829 | } |
| 830 | |
| 831 | @Override |
| 832 | public void onAnimationCancel(Animator animation) { |
| 833 | mWasCancelled = true; |
| 834 | } |
| 835 | }); |
| 836 | mAppearAnimator.start(); |
| 837 | } |
| 838 | |
Selim Cinek | aa3901a | 2016-08-05 11:04:37 -0700 | [diff] [blame] | 839 | protected void onAppearAnimationFinished(boolean wasAppearing) { |
| 840 | } |
| 841 | |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 842 | private void cancelAppearAnimation() { |
| 843 | if (mAppearAnimator != null) { |
| 844 | mAppearAnimator.cancel(); |
Selim Cinek | b65c6db | 2015-12-28 12:48:15 +0100 | [diff] [blame] | 845 | mAppearAnimator = null; |
Selim Cinek | 2cd45df | 2015-06-09 18:00:07 -0700 | [diff] [blame] | 846 | } |
| 847 | } |
| 848 | |
| 849 | public void cancelAppearDrawing() { |
| 850 | cancelAppearAnimation(); |
| 851 | enableAppearDrawing(false); |
| 852 | } |
| 853 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 854 | private void updateAppearRect() { |
| 855 | float inverseFraction = (1.0f - mAppearAnimationFraction); |
| 856 | float translationFraction = mCurrentAppearInterpolator.getInterpolation(inverseFraction); |
| 857 | float translateYTotalAmount = translationFraction * mAnimationTranslationY; |
| 858 | mAppearAnimationTranslation = translateYTotalAmount; |
| 859 | |
| 860 | // handle width animation |
| 861 | float widthFraction = (inverseFraction - (1.0f - HORIZONTAL_ANIMATION_START)) |
| 862 | / (HORIZONTAL_ANIMATION_START - HORIZONTAL_ANIMATION_END); |
| 863 | widthFraction = Math.min(1.0f, Math.max(0.0f, widthFraction)); |
| 864 | widthFraction = mCurrentAppearInterpolator.getInterpolation(widthFraction); |
| 865 | float left = (getWidth() * (0.5f - HORIZONTAL_COLLAPSED_REST_PARTIAL / 2.0f) * |
| 866 | widthFraction); |
| 867 | float right = getWidth() - left; |
| 868 | |
| 869 | // handle top animation |
| 870 | float heightFraction = (inverseFraction - (1.0f - VERTICAL_ANIMATION_START)) / |
| 871 | VERTICAL_ANIMATION_START; |
| 872 | heightFraction = Math.max(0.0f, heightFraction); |
| 873 | heightFraction = mCurrentAppearInterpolator.getInterpolation(heightFraction); |
| 874 | |
| 875 | float top; |
| 876 | float bottom; |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 877 | final int actualHeight = getActualHeight(); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 878 | if (mAnimationTranslationY > 0.0f) { |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 879 | bottom = actualHeight - heightFraction * mAnimationTranslationY * 0.1f |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 880 | - translateYTotalAmount; |
| 881 | top = bottom * heightFraction; |
| 882 | } else { |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 883 | top = heightFraction * (actualHeight + mAnimationTranslationY) * 0.1f - |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 884 | translateYTotalAmount; |
Chris Wren | 310df31 | 2014-10-31 14:29:46 -0400 | [diff] [blame] | 885 | bottom = actualHeight * (1 - heightFraction) + top * heightFraction; |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 886 | } |
| 887 | mAppearAnimationRect.set(left, top, right, bottom); |
| 888 | setOutlineRect(left, top + mAppearAnimationTranslation, right, |
| 889 | bottom + mAppearAnimationTranslation); |
| 890 | } |
| 891 | |
| 892 | private void updateAppearAnimationAlpha() { |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 893 | float contentAlphaProgress = mAppearAnimationFraction; |
| 894 | contentAlphaProgress = contentAlphaProgress / (1.0f - ALPHA_ANIMATION_END); |
| 895 | contentAlphaProgress = Math.min(1.0f, contentAlphaProgress); |
| 896 | contentAlphaProgress = mCurrentAlphaInterpolator.getInterpolation(contentAlphaProgress); |
| 897 | setContentAlpha(contentAlphaProgress); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 898 | } |
| 899 | |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 900 | private void setContentAlpha(float contentAlpha) { |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 901 | View contentView = getContentView(); |
Jorim Jaggi | 1f98c62 | 2015-07-20 11:43:27 -0700 | [diff] [blame] | 902 | if (contentView.hasOverlappingRendering()) { |
| 903 | int layerType = contentAlpha == 0.0f || contentAlpha == 1.0f ? LAYER_TYPE_NONE |
| 904 | : LAYER_TYPE_HARDWARE; |
| 905 | int currentLayerType = contentView.getLayerType(); |
| 906 | if (currentLayerType != layerType) { |
| 907 | contentView.setLayerType(layerType, null); |
| 908 | } |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 909 | } |
| 910 | contentView.setAlpha(contentAlpha); |
| 911 | } |
| 912 | |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 913 | @Override |
| 914 | protected void applyRoundness() { |
| 915 | super.applyRoundness(); |
Selim Cinek | d9b7dd4 | 2017-11-10 17:53:47 -0800 | [diff] [blame] | 916 | applyBackgroundRoundness(getCurrentBackgroundRadiusTop(), |
| 917 | getCurrentBackgroundRadiusBottom()); |
Selim Cinek | 0fe0739 | 2017-11-09 13:26:34 -0800 | [diff] [blame] | 918 | } |
| 919 | |
| 920 | protected void applyBackgroundRoundness(float topRadius, float bottomRadius) { |
| 921 | mBackgroundDimmed.setRoundness(topRadius, bottomRadius); |
| 922 | mBackgroundNormal.setRoundness(topRadius, bottomRadius); |
| 923 | } |
| 924 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 925 | @Override |
| 926 | protected void setBackgroundTop(int backgroundTop) { |
| 927 | mBackgroundDimmed.setBackgroundTop(backgroundTop); |
| 928 | mBackgroundNormal.setBackgroundTop(backgroundTop); |
| 929 | } |
| 930 | |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 931 | protected abstract View getContentView(); |
| 932 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 933 | public int calculateBgColor() { |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 934 | return calculateBgColor(true /* withTint */, true /* withOverRide */); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 935 | } |
| 936 | |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 937 | @Override |
Selim Cinek | 515b203 | 2017-11-15 10:20:19 -0800 | [diff] [blame] | 938 | protected boolean childNeedsClipping(View child) { |
| 939 | if (child instanceof NotificationBackgroundView && isClippingNeeded()) { |
| 940 | return true; |
| 941 | } |
| 942 | return super.childNeedsClipping(child); |
| 943 | } |
| 944 | |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 945 | /** |
| 946 | * @param withTint should a possible tint be factored in? |
| 947 | * @param withOverRide should the value be interpolated with {@link #mOverrideTint} |
| 948 | * @return the calculated background color |
| 949 | */ |
| 950 | private int calculateBgColor(boolean withTint, boolean withOverRide) { |
Selim Cinek | ac5f027 | 2017-05-02 16:05:41 -0700 | [diff] [blame] | 951 | if (withTint && mDark) { |
Adrian Roos | 500263a | 2017-01-23 14:49:54 -0800 | [diff] [blame] | 952 | return getContext().getColor(R.color.notification_material_background_dark_color); |
| 953 | } |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 954 | if (withOverRide && mOverrideTint != NO_COLOR) { |
| 955 | int defaultTint = calculateBgColor(withTint, false); |
| 956 | return NotificationUtils.interpolateColors(defaultTint, mOverrideTint, mOverrideAmount); |
| 957 | } |
| 958 | if (withTint && mBgTint != NO_COLOR) { |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 959 | return mBgTint; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 960 | } else if (mIsBelowSpeedBump) { |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 961 | return mLowPriorityColor; |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 962 | } else { |
| 963 | return mNormalColor; |
| 964 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 965 | } |
| 966 | |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 967 | protected int getRippleColor() { |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 968 | if (mBgTint != 0) { |
| 969 | return mTintedRippleColor; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 970 | } else if (mIsBelowSpeedBump) { |
Selim Cinek | b2da91b | 2014-09-02 17:35:20 +0200 | [diff] [blame] | 971 | return mLowPriorityRippleColor; |
| 972 | } else { |
| 973 | return mNormalRippleColor; |
| 974 | } |
| 975 | } |
| 976 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 977 | /** |
| 978 | * When we draw the appear animation, we render the view in a bitmap and render this bitmap |
| 979 | * as a shader of a rect. This call creates the Bitmap and switches the drawing mode, |
| 980 | * such that the normal drawing of the views does not happen anymore. |
| 981 | * |
| 982 | * @param enable Should it be enabled. |
| 983 | */ |
| 984 | private void enableAppearDrawing(boolean enable) { |
| 985 | if (enable != mDrawingAppearAnimation) { |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 986 | mDrawingAppearAnimation = enable; |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 987 | if (!enable) { |
| 988 | setContentAlpha(1.0f); |
Selim Cinek | b65c6db | 2015-12-28 12:48:15 +0100 | [diff] [blame] | 989 | mAppearAnimationFraction = -1; |
| 990 | setOutlineRect(null); |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 991 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 992 | invalidate(); |
| 993 | } |
| 994 | } |
| 995 | |
Selim Cinek | f38d6c3 | 2017-06-28 15:44:02 +0200 | [diff] [blame] | 996 | public boolean isDrawingAppearAnimation() { |
| 997 | return mDrawingAppearAnimation; |
| 998 | } |
| 999 | |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1000 | @Override |
| 1001 | protected void dispatchDraw(Canvas canvas) { |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 1002 | if (mDrawingAppearAnimation) { |
| 1003 | canvas.save(); |
| 1004 | canvas.translate(0, mAppearAnimationTranslation); |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1005 | } |
Selim Cinek | 560e64d | 2015-06-09 19:58:11 -0700 | [diff] [blame] | 1006 | super.dispatchDraw(canvas); |
| 1007 | if (mDrawingAppearAnimation) { |
| 1008 | canvas.restore(); |
| 1009 | } |
Selim Cinek | 8efa6dd | 2014-05-19 16:27:37 +0200 | [diff] [blame] | 1010 | } |
| 1011 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1012 | public void setOnActivatedListener(OnActivatedListener onActivatedListener) { |
| 1013 | mOnActivatedListener = onActivatedListener; |
| 1014 | } |
| 1015 | |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 1016 | public boolean hasSameBgColor(ActivatableNotificationView otherView) { |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1017 | return calculateBgColor() == otherView.calculateBgColor(); |
Selim Cinek | 34d93b0 | 2015-10-22 12:30:38 -0700 | [diff] [blame] | 1018 | } |
| 1019 | |
Selim Cinek | 277a8aa | 2016-01-22 12:12:37 -0800 | [diff] [blame] | 1020 | @Override |
| 1021 | public float getShadowAlpha() { |
| 1022 | return mShadowAlpha; |
| 1023 | } |
| 1024 | |
| 1025 | @Override |
| 1026 | public void setShadowAlpha(float shadowAlpha) { |
| 1027 | if (shadowAlpha != mShadowAlpha) { |
| 1028 | mShadowAlpha = shadowAlpha; |
| 1029 | updateOutlineAlpha(); |
| 1030 | } |
| 1031 | } |
| 1032 | |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 1033 | @Override |
| 1034 | public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd, |
| 1035 | int outlineTranslation) { |
Selim Cinek | fb6ee6d | 2016-12-29 16:49:26 +0100 | [diff] [blame] | 1036 | boolean hiddenBefore = mShadowHidden; |
| 1037 | mShadowHidden = shadowIntensity == 0.0f; |
| 1038 | if (!mShadowHidden || !hiddenBefore) { |
| 1039 | mFakeShadow.setFakeShadowTranslationZ(shadowIntensity * (getTranslationZ() |
| 1040 | + FakeShadowView.SHADOW_SIBLING_TRESHOLD), outlineAlpha, shadowYEnd, |
| 1041 | outlineTranslation); |
| 1042 | } |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 1043 | } |
| 1044 | |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1045 | public int getBackgroundColorWithoutTint() { |
Selim Cinek | f9bba0b | 2016-11-18 15:08:21 -0800 | [diff] [blame] | 1046 | return calculateBgColor(false /* withTint */, false /* withOverride */); |
Selim Cinek | c317933 | 2016-03-04 14:44:56 -0800 | [diff] [blame] | 1047 | } |
| 1048 | |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1049 | public interface OnActivatedListener { |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 1050 | void onActivated(ActivatableNotificationView view); |
| 1051 | void onActivationReset(ActivatableNotificationView view); |
Jorim Jaggi | c5dc0d0 | 2014-04-15 15:42:55 +0200 | [diff] [blame] | 1052 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | } |