*/
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;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.ScrollView;
/**
* A PagerAdapter used by PreviewSeekBarPreferenceFragment that for showing multiple preview screen
*/
public class PreviewPagerAdapter extends PagerAdapter {
- private TouchBlockingFrameLayout[] mPreviewFrames;
-
/** Duration to use when cross-fading between previews. */
private static final long CROSS_FADE_DURATION_MS = 400;
/** Interpolator to use when cross-fading between previews. */
private static final Interpolator FADE_OUT_INTERPOLATOR = new AccelerateInterpolator();
- public PreviewPagerAdapter(Context context, int[] previewSampleResIds,
- Configuration[] configurations) {
- mPreviewFrames = new TouchBlockingFrameLayout[previewSampleResIds.length];
+ private FrameLayout[] mPreviewFrames;
+
+ private boolean mIsLayoutRtl;
+
+ private Runnable mAnimationEndAction;
+
+ private int mAnimationCounter;
+
+ public PreviewPagerAdapter(Context context, boolean isLayoutRtl,
+ int[] previewSampleResIds, Configuration[] configurations) {
+ mIsLayoutRtl = isLayoutRtl;
+ mPreviewFrames = new FrameLayout[previewSampleResIds.length];
for (int i = 0; i < previewSampleResIds.length; ++i) {
- mPreviewFrames[i] = (TouchBlockingFrameLayout) LayoutInflater.from(context)
- .inflate(R.layout.preview_frame_container, null);
- mPreviewFrames[i].setContentDescription(
- context.getString(R.string.preview_page_indicator_content_description, i + 1,
- previewSampleResIds.length));
+ int p = mIsLayoutRtl ? previewSampleResIds.length - 1 - i : i;
+ mPreviewFrames[p] = new FrameLayout(context);
+ mPreviewFrames[p].setLayoutParams(new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.MATCH_PARENT,
+ LinearLayout.LayoutParams.MATCH_PARENT));
for (Configuration configuration : configurations) {
// Create a new configuration for the specified value. It won't
final LayoutInflater configInflater = LayoutInflater.from(configContext);
final View sampleView = configInflater.inflate(previewSampleResIds[i],
- mPreviewFrames[i], false);
+ mPreviewFrames[p], false);
sampleView.setAlpha(0);
sampleView.setVisibility(View.INVISIBLE);
-
- mPreviewFrames[i].addView(sampleView);
+ mPreviewFrames[p].addView(sampleView);
}
}
}
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) {
.alpha(0)
.setInterpolator(FADE_OUT_INTERPOLATOR)
.setDuration(CROSS_FADE_DURATION_MS)
+ .setListener(new PreviewFrameAnimatorListener())
.withEndAction(new Runnable() {
@Override
public void run() {
.alpha(1)
.setInterpolator(FADE_IN_INTERPOLATOR)
.setDuration(CROSS_FADE_DURATION_MS)
+ .setListener(new PreviewFrameAnimatorListener())
.withStartAction(new Runnable() {
@Override
public void run() {
}
}
}
+
+ 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.
+ }
+ }
}