1717
1818package com .android .systemui ;
1919
20+ import android .animation .AnimatorSet ;
2021import android .animation .ObjectAnimator ;
2122import android .content .Context ;
2223import android .graphics .RectF ;
@@ -38,6 +39,8 @@ public interface Callback {
3839 private static final String TAG = "ExpandHelper" ;
3940 protected static final boolean DEBUG = false ;
4041 private static final long EXPAND_DURATION = 250 ;
42+ private static final long GLOW_DURATION = 150 ;
43+
4144
4245 // amount of overstretch for maximum brightness expressed in U
4346 // 2f: maximum brightness is stretching a 1U to 3U, or a 4U to 6U
@@ -60,7 +63,10 @@ public interface Callback {
6063 private Callback mCallback ;
6164 private ScaleGestureDetector mDetector ;
6265 private ViewScaler mScaler ;
63- private ObjectAnimator mAnimation ;
66+ private ObjectAnimator mScaleAnimation ;
67+ private AnimatorSet mGlowAnimationSet ;
68+ private ObjectAnimator mGlowTopAnimation ;
69+ private ObjectAnimator mGlowBottomAnimation ;
6470
6571 private int mSmallSize ;
6672 private int mLargeSize ;
@@ -110,6 +116,16 @@ public ExpandHelper(Context context, Callback callback, int small, int large) {
110116 mContext = context ;
111117 mCallback = callback ;
112118 mScaler = new ViewScaler ();
119+
120+ mScaleAnimation = ObjectAnimator .ofFloat (mScaler , "height" , 0f );
121+ mScaleAnimation .setDuration (EXPAND_DURATION );
122+
123+ mGlowTopAnimation = ObjectAnimator .ofFloat (null , "alpha" , 0f );
124+ mGlowBottomAnimation = ObjectAnimator .ofFloat (null , "alpha" , 0f );
125+ mGlowAnimationSet = new AnimatorSet ();
126+ mGlowAnimationSet .play (mGlowTopAnimation ).with (mGlowBottomAnimation );
127+ mGlowAnimationSet .setDuration (GLOW_DURATION );
128+
113129 mDetector =
114130 new ScaleGestureDetector (context ,
115131 new ScaleGestureDetector .SimpleOnScaleGestureListener () {
@@ -155,11 +171,22 @@ public void onScaleEnd(ScaleGestureDetector detector) {
155171 });
156172 }
157173 public void setGlow (float glow ) {
158- if (mCurrViewTopGlow != null ) {
159- mCurrViewTopGlow .setAlpha (glow );
160- }
161- if (mCurrViewBottomGlow != null ) {
162- mCurrViewBottomGlow .setAlpha (glow );
174+ if (!mGlowAnimationSet .isRunning ()) {
175+ if (mCurrViewTopGlow != null && mCurrViewBottomGlow != null ) {
176+ if (glow == 0f || mCurrViewTopGlow .getAlpha () == 0f ) {
177+ // animate glow in and out
178+ mGlowTopAnimation .setTarget (mCurrViewTopGlow );
179+ mGlowBottomAnimation .setTarget (mCurrViewBottomGlow );
180+ mGlowTopAnimation .setFloatValues (glow );
181+ mGlowBottomAnimation .setFloatValues (glow );
182+ mGlowAnimationSet .setupStartValues ();
183+ mGlowAnimationSet .start ();
184+ } else {
185+ // set it explicitly in reponse to touches.
186+ mCurrViewTopGlow .setAlpha (glow );
187+ mCurrViewBottomGlow .setAlpha (glow );
188+ }
189+ }
163190 }
164191 }
165192
@@ -216,8 +243,12 @@ private void finishScale(boolean force) {
216243 h = (force || h < mNaturalHeight ) ? mSmallSize : mNaturalHeight ;
217244 }
218245 if (DEBUG && mCurrView != null ) mCurrView .setBackgroundColor (0 );
219- mAnimation = ObjectAnimator .ofFloat (mScaler , "height" , h ).setDuration (EXPAND_DURATION );
220- mAnimation .start ();
246+ if (mScaleAnimation .isRunning ()) {
247+ mScaleAnimation .cancel ();
248+ }
249+ mScaleAnimation .setFloatValues (h );
250+ mScaleAnimation .setupStartValues ();
251+ mScaleAnimation .start ();
221252 mStretching = false ;
222253 setGlow (0f );
223254 clearView ();
0 commit comments