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