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;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.animation.Animator.AnimatorListener;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.support.v4.view.PagerAdapter;
|
import android.support.v4.view.PagerAdapter;
|
||||||
@@ -34,8 +36,6 @@ import android.widget.ScrollView;
|
|||||||
*/
|
*/
|
||||||
public class PreviewPagerAdapter extends PagerAdapter {
|
public class PreviewPagerAdapter extends PagerAdapter {
|
||||||
|
|
||||||
private FrameLayout[] mPreviewFrames;
|
|
||||||
|
|
||||||
/** Duration to use when cross-fading between previews. */
|
/** Duration to use when cross-fading between previews. */
|
||||||
private static final long CROSS_FADE_DURATION_MS = 400;
|
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. */
|
/** Interpolator to use when cross-fading between previews. */
|
||||||
private static final Interpolator FADE_OUT_INTERPOLATOR = new AccelerateInterpolator();
|
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,
|
public PreviewPagerAdapter(Context context, int[] previewSampleResIds,
|
||||||
Configuration[] configurations) {
|
Configuration[] configurations) {
|
||||||
mPreviewFrames = new FrameLayout[previewSampleResIds.length];
|
mPreviewFrames = new FrameLayout[previewSampleResIds.length];
|
||||||
@@ -95,6 +101,14 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
|||||||
return (view == object);
|
return (view == object);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean isAnimating() {
|
||||||
|
return mAnimationCounter > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setAnimationEndAction(Runnable action) {
|
||||||
|
mAnimationEndAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
void setPreviewLayer(int newIndex, int currentIndex, int currentItem, boolean animate) {
|
void setPreviewLayer(int newIndex, int currentIndex, int currentItem, boolean animate) {
|
||||||
for (FrameLayout previewFrame : mPreviewFrames) {
|
for (FrameLayout previewFrame : mPreviewFrames) {
|
||||||
if (currentIndex >= 0) {
|
if (currentIndex >= 0) {
|
||||||
@@ -104,6 +118,7 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
|||||||
.alpha(0)
|
.alpha(0)
|
||||||
.setInterpolator(FADE_OUT_INTERPOLATOR)
|
.setInterpolator(FADE_OUT_INTERPOLATOR)
|
||||||
.setDuration(CROSS_FADE_DURATION_MS)
|
.setDuration(CROSS_FADE_DURATION_MS)
|
||||||
|
.setListener(new PreviewFrameAnimatorListener())
|
||||||
.withEndAction(new Runnable() {
|
.withEndAction(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -122,6 +137,7 @@ public class PreviewPagerAdapter extends PagerAdapter {
|
|||||||
.alpha(1)
|
.alpha(1)
|
||||||
.setInterpolator(FADE_IN_INTERPOLATOR)
|
.setInterpolator(FADE_IN_INTERPOLATOR)
|
||||||
.setDuration(CROSS_FADE_DURATION_MS)
|
.setDuration(CROSS_FADE_DURATION_MS)
|
||||||
|
.setListener(new PreviewFrameAnimatorListener())
|
||||||
.withStartAction(new Runnable() {
|
.withStartAction(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
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
|
@Override
|
||||||
public void onStopTrackingTouch(SeekBar seekBar) {
|
public void onStopTrackingTouch(SeekBar seekBar) {
|
||||||
commit();
|
if (mPreviewPagerAdapter.isAnimating()) {
|
||||||
|
mPreviewPagerAdapter.setAnimationEndAction(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
commit();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
commit();
|
||||||
|
}
|
||||||
mSeekByTouch = false;
|
mSeekByTouch = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user