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