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