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