1515 */
1616package com .android .internal .policy .impl .keyguard ;
1717
18+ import android .animation .Animator ;
19+ import android .animation .AnimatorListenerAdapter ;
20+ import android .animation .AnimatorSet ;
21+ import android .animation .ObjectAnimator ;
22+ import android .animation .PropertyValuesHolder ;
1823import android .content .Context ;
1924import android .util .AttributeSet ;
2025import android .view .View ;
26+ import android .view .animation .AccelerateInterpolator ;
27+ import android .view .animation .DecelerateInterpolator ;
28+ import android .view .animation .Interpolator ;
29+
30+ import java .util .ArrayList ;
2131
2232import com .android .internal .R ;
2333
@@ -26,6 +36,8 @@ public class KeyguardWidgetCarousel extends KeyguardWidgetPager {
2636 private float mAdjacentPagesAngle ;
2737 private static float MAX_SCROLL_PROGRESS = 1.3f ;
2838 private static float CAMERA_DISTANCE = 10000 ;
39+ protected AnimatorSet mChildrenTransformsAnimator ;
40+ float [] mTmpTransform = new float [3 ];
2941
3042 public KeyguardWidgetCarousel (Context context , AttributeSet attrs ) {
3143 this (context , attrs , 0 );
@@ -48,13 +60,15 @@ public float getAlphaForPage(int screenCenter, int index) {
4860 View child = getChildAt (index );
4961 if (child == null ) return 0f ;
5062
63+ float maxAlpha = KeyguardWidgetFrame .OUTLINE_ALPHA_MULTIPLIER ;
64+
5165 float scrollProgress = getScrollProgress (screenCenter , child , index );
5266 if (!isOverScrollChild (index , scrollProgress )) {
5367 scrollProgress = getBoundedScrollProgress (screenCenter , child , index );
54- float alpha = 1 - Math .abs (scrollProgress / MAX_SCROLL_PROGRESS );
68+ float alpha = maxAlpha - maxAlpha * Math .abs (scrollProgress / MAX_SCROLL_PROGRESS );
5569 return alpha ;
5670 } else {
57- return 1f ;
71+ return maxAlpha ;
5872 }
5973 }
6074
@@ -73,34 +87,33 @@ private void updatePageAlphaValues(int screenCenter) {
7387 }
7488 }
7589 }
76-
7790 }
7891
7992 @ Override
8093 protected void screenScrolled (int screenCenter ) {
8194 mScreenCenter = screenCenter ;
8295 updatePageAlphaValues (screenCenter );
96+ if (isReordering (false )) return ;
8397 for (int i = 0 ; i < getChildCount (); i ++) {
8498 KeyguardWidgetFrame v = getWidgetPageAt (i );
8599 float scrollProgress = getScrollProgress (screenCenter , v , i );
100+ float boundedProgress = getBoundedScrollProgress (screenCenter , v , i );
86101 if (v == mDragView || v == null ) continue ;
87102 v .setCameraDistance (CAMERA_DISTANCE );
88103
89104 if (isOverScrollChild (i , scrollProgress )) {
90105 v .setRotationY (- OVERSCROLL_MAX_ROTATION * scrollProgress );
91106 v .setOverScrollAmount (Math .abs (scrollProgress ), scrollProgress < 0 );
92107 } else {
93- scrollProgress = getBoundedScrollProgress (screenCenter , v , i );
94108 int width = v .getMeasuredWidth ();
95- float pivotX = (width / 2f ) + scrollProgress * (width / 2f );
109+ float pivotX = (width / 2f ) + boundedProgress * (width / 2f );
96110 float pivotY = v .getMeasuredHeight () / 2 ;
97- float rotationY = - mAdjacentPagesAngle * scrollProgress ;
111+ float rotationY = - mAdjacentPagesAngle * boundedProgress ;
98112 v .setPivotX (pivotX );
99113 v .setPivotY (pivotY );
100114 v .setRotationY (rotationY );
101115 v .setOverScrollAmount (0f , false );
102116 }
103-
104117 float alpha = v .getAlpha ();
105118 // If the view has 0 alpha, we set it to be invisible so as to prevent
106119 // it from accepting touches
@@ -111,4 +124,137 @@ protected void screenScrolled(int screenCenter) {
111124 }
112125 }
113126 }
127+
128+ void animatePagesToNeutral () {
129+ if (mChildrenTransformsAnimator != null ) {
130+ mChildrenTransformsAnimator .cancel ();
131+ mChildrenTransformsAnimator = null ;
132+ }
133+
134+ int count = getChildCount ();
135+ PropertyValuesHolder alpha ;
136+ PropertyValuesHolder outlineAlpha ;
137+ PropertyValuesHolder rotationY ;
138+ ArrayList <Animator > anims = new ArrayList <Animator >();
139+
140+ for (int i = 0 ; i < count ; i ++) {
141+ KeyguardWidgetFrame child = getWidgetPageAt (i );
142+ boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1 );
143+ if (!inVisibleRange ) {
144+ child .setRotationY (0f );
145+ }
146+ alpha = PropertyValuesHolder .ofFloat ("contentAlpha" , 1.0f );
147+ outlineAlpha = PropertyValuesHolder .ofFloat ("backgroundAlpha" , 1.0f );
148+ rotationY = PropertyValuesHolder .ofFloat ("rotationY" , 0f );
149+ ObjectAnimator a = ObjectAnimator .ofPropertyValuesHolder (child , alpha , outlineAlpha , rotationY );
150+ child .setVisibility (VISIBLE );
151+ if (!inVisibleRange ) {
152+ a .setInterpolator (mSlowFadeInterpolator );
153+ }
154+ anims .add (a );
155+ }
156+
157+ int duration = REORDERING_ZOOM_IN_OUT_DURATION ;
158+ mChildrenTransformsAnimator = new AnimatorSet ();
159+ mChildrenTransformsAnimator .playTogether (anims );
160+
161+ mChildrenTransformsAnimator .setDuration (duration );
162+ mChildrenTransformsAnimator .start ();
163+ }
164+
165+ private void getTransformForPage (int screenCenter , int index , float [] transform ) {
166+ View child = getChildAt (index );
167+ float boundedProgress = getBoundedScrollProgress (screenCenter , child , index );
168+ float rotationY = - mAdjacentPagesAngle * boundedProgress ;
169+ int width = child .getMeasuredWidth ();
170+ float pivotX = (width / 2f ) + boundedProgress * (width / 2f );
171+ float pivotY = child .getMeasuredHeight () / 2 ;
172+
173+ transform [0 ] = pivotX ;
174+ transform [1 ] = pivotY ;
175+ transform [2 ] = rotationY ;
176+ }
177+
178+ Interpolator mFastFadeInterpolator = new Interpolator () {
179+ Interpolator mInternal = new DecelerateInterpolator (1.5f );
180+ float mFactor = 2.5f ;
181+ @ Override
182+ public float getInterpolation (float input ) {
183+ return mInternal .getInterpolation (Math .min (mFactor * input , 1f ));
184+ }
185+ };
186+
187+ Interpolator mSlowFadeInterpolator = new Interpolator () {
188+ Interpolator mInternal = new AccelerateInterpolator (1.5f );
189+ float mFactor = 1.3f ;
190+ @ Override
191+ public float getInterpolation (float input ) {
192+ input -= (1 - 1 / mFactor );
193+ input = mFactor * Math .max (input , 0f );
194+ return mInternal .getInterpolation (input );
195+ }
196+ };
197+
198+ void animatePagesToCarousel () {
199+ if (mChildrenTransformsAnimator != null ) {
200+ mChildrenTransformsAnimator .cancel ();
201+ mChildrenTransformsAnimator = null ;
202+ }
203+
204+ int count = getChildCount ();
205+ PropertyValuesHolder alpha ;
206+ PropertyValuesHolder outlineAlpha ;
207+ PropertyValuesHolder rotationY ;
208+ PropertyValuesHolder pivotX ;
209+ PropertyValuesHolder pivotY ;
210+ ArrayList <Animator > anims = new ArrayList <Animator >();
211+
212+ for (int i = 0 ; i < count ; i ++) {
213+ KeyguardWidgetFrame child = getWidgetPageAt (i );
214+ float finalAlpha = getAlphaForPage (mScreenCenter , i );
215+ getTransformForPage (mScreenCenter , i , mTmpTransform );
216+
217+ boolean inVisibleRange = (i >= mCurrentPage - 1 && i <= mCurrentPage + 1 );
218+
219+ ObjectAnimator a ;
220+ alpha = PropertyValuesHolder .ofFloat ("contentAlpha" , finalAlpha );
221+ outlineAlpha = PropertyValuesHolder .ofFloat ("backgroundAlpha" , finalAlpha );
222+ pivotX = PropertyValuesHolder .ofFloat ("pivotX" , mTmpTransform [0 ]);
223+ pivotY = PropertyValuesHolder .ofFloat ("pivotY" , mTmpTransform [1 ]);
224+ rotationY = PropertyValuesHolder .ofFloat ("rotationY" , mTmpTransform [2 ]);
225+
226+ if (inVisibleRange ) {
227+ // for the central pages we animate into a rotated state
228+ a = ObjectAnimator .ofPropertyValuesHolder (child , alpha , outlineAlpha ,
229+ pivotX , pivotY , rotationY );
230+ } else {
231+ a = ObjectAnimator .ofPropertyValuesHolder (child , alpha , outlineAlpha );
232+ a .setInterpolator (mFastFadeInterpolator );
233+ }
234+ anims .add (a );
235+ }
236+
237+ int duration = REORDERING_ZOOM_IN_OUT_DURATION ;
238+ mChildrenTransformsAnimator = new AnimatorSet ();
239+ mChildrenTransformsAnimator .playTogether (anims );
240+
241+ mChildrenTransformsAnimator .setDuration (duration );
242+ mChildrenTransformsAnimator .start ();
243+ }
244+
245+ protected void reorderStarting () {
246+ mViewStateManager .fadeOutSecurity (REORDERING_ZOOM_IN_OUT_DURATION );
247+ animatePagesToNeutral ();
248+ }
249+
250+ protected boolean zoomIn (final Runnable onCompleteRunnable ) {
251+ animatePagesToCarousel ();
252+ return super .zoomIn (onCompleteRunnable );
253+ }
254+
255+ @ Override
256+ protected void onEndReordering () {
257+ super .onEndReordering ();
258+ mViewStateManager .fadeInSecurity (REORDERING_ZOOM_IN_OUT_DURATION );
259+ }
114260}
0 commit comments