Postpone commit on PreviewSeekBarPreferenceFragment
until the cross-fade animation has completed Bug: 27142332 Change-Id: I6c11e89398bad34a3b92560cb73c667a3cfd4786
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package com.android.settings;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.Animator.AnimatorListener;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
@@ -34,8 +36,6 @@ import android.widget.ScrollView;
|
||||
*/
|
||||
public class PreviewPagerAdapter extends PagerAdapter {
|
||||
|
||||
private FrameLayout[] mPreviewFrames;
|
||||
|
||||
/** Duration to use when cross-fading between previews. */
|
||||
private static final long CROSS_FADE_DURATION_MS = 400;
|
||||
|
||||
@@ -45,6 +45,12 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
||||
/** Interpolator to use when cross-fading between previews. */
|
||||
private static final Interpolator FADE_OUT_INTERPOLATOR = new AccelerateInterpolator();
|
||||
|
||||
private final FrameLayout[] mPreviewFrames;
|
||||
|
||||
private Runnable mAnimationEndAction;
|
||||
|
||||
private int mAnimationCounter;
|
||||
|
||||
public PreviewPagerAdapter(Context context, int[] previewSampleResIds,
|
||||
Configuration[] configurations) {
|
||||
mPreviewFrames = new FrameLayout[previewSampleResIds.length];
|
||||
@@ -95,6 +101,14 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
||||
return (view == object);
|
||||
}
|
||||
|
||||
boolean isAnimating() {
|
||||
return mAnimationCounter > 0;
|
||||
}
|
||||
|
||||
void setAnimationEndAction(Runnable action) {
|
||||
mAnimationEndAction = action;
|
||||
}
|
||||
|
||||
void setPreviewLayer(int newIndex, int currentIndex, int currentItem, boolean animate) {
|
||||
for (FrameLayout previewFrame : mPreviewFrames) {
|
||||
if (currentIndex >= 0) {
|
||||
@@ -104,6 +118,7 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
||||
.alpha(0)
|
||||
.setInterpolator(FADE_OUT_INTERPOLATOR)
|
||||
.setDuration(CROSS_FADE_DURATION_MS)
|
||||
.setListener(new PreviewFrameAnimatorListener())
|
||||
.withEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -122,6 +137,7 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
||||
.alpha(1)
|
||||
.setInterpolator(FADE_IN_INTERPOLATOR)
|
||||
.setDuration(CROSS_FADE_DURATION_MS)
|
||||
.setListener(new PreviewFrameAnimatorListener())
|
||||
.withStartAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -134,4 +150,34 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void runAnimationEndAction() {
|
||||
if (mAnimationEndAction != null && !isAnimating()) {
|
||||
mAnimationEndAction.run();
|
||||
mAnimationEndAction = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class PreviewFrameAnimatorListener implements AnimatorListener {
|
||||
@Override
|
||||
public void onAnimationStart(Animator animation) {
|
||||
mAnimationCounter++;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimationCounter--;
|
||||
runAnimationEndAction();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationCancel(Animator animation) {
|
||||
// Empty method.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animator animation) {
|
||||
// Empty method.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -79,7 +79,16 @@ public abstract class PreviewSeekBarPreferenceFragment extends SettingsPreferenc
|
||||
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||
commit();
|
||||
if (mPreviewPagerAdapter.isAnimating()) {
|
||||
mPreviewPagerAdapter.setAnimationEndAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
commit();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
commit();
|
||||
}
|
||||
mSeekByTouch = false;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user