Skip to content

Commit 70009e4

Browse files
author
Adam Cohen
committed
Making the reordering play nice with the 3D widget carousel
-> Ensuring that transforms, hidden side pages, alphas all transition and fade seamlessly to and from the carousel Change-Id: I6197f17899135a9e551ff1691c63ad5a2bb1d0f7
1 parent 33384ed commit 70009e4

File tree

5 files changed

+201
-24
lines changed

5 files changed

+201
-24
lines changed

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ protected void onFinishInflate() {
162162

163163
addDefaultWidgets();
164164
addWidgetsFromSettings();
165+
mSwitchPageRunnable.run();
165166

166167
mViewStateManager = new KeyguardViewStateManager();
167168
SlidingChallengeLayout slider =
@@ -217,7 +218,6 @@ void setLockPatternUtils(LockPatternUtils utils) {
217218
protected void onAttachedToWindow() {
218219
super.onAttachedToWindow();
219220
mAppWidgetHost.startListening();
220-
post(mSwitchPageRunnable);
221221
}
222222

223223
@Override

policy/src/com/android/internal/policy/impl/keyguard/KeyguardViewStateManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@ public void showBouncer(boolean show) {
8686
mChallengeLayout.showBouncer();
8787
}
8888

89+
public void fadeOutSecurity(int duration) {
90+
((View) mKeyguardSecurityContainer).animate().alpha(0).setDuration(duration);
91+
}
92+
93+
public void fadeInSecurity(int duration) {
94+
((View) mKeyguardSecurityContainer).animate().alpha(1f).setDuration(duration);
95+
}
96+
8997
public void onPageSwitch(View newPage, int newPageIndex) {
9098
// Reset the previous page size and ensure the current page is sized appropriately.
9199
// We only modify the page state if it is not currently under control by the slider.

policy/src/com/android/internal/policy/impl/keyguard/KeyguardWidgetCarousel.java

Lines changed: 153 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@
1515
*/
1616
package 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;
1823
import android.content.Context;
1924
import android.util.AttributeSet;
2025
import 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

2232
import 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

Comments
 (0)