package com.marshalchen.ua.common.usefulModule;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.view.animation.Interpolator;
import android.widget.Scroller;
/**
* Created by cym on 14-5-8.
*/
public class FixSpeedScroller extends Scroller {
private int mDuration = 1000;
private double mScrollFactor = 1;
public FixSpeedScroller(Context context) {
super(context);
}
public FixSpeedScroller(Context context, Interpolator interpolator) {
super(context, interpolator);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public FixSpeedScroller(Context context, Interpolator interpolator, boolean flywheel) {
super(context, interpolator, flywheel);
}
@Override
public void startScroll(int startX, int startY, int dx, int dy, int duration) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, (int) (mDuration * mScrollFactor));
}
@Override
public void startScroll(int startX, int startY, int dx, int dy) {
// Ignore received duration, use fixed one instead
super.startScroll(startX, startY, dx, dy, mDuration);
}
/**
* Set the factor by which the duration will change
*/
public void setScrollDurationFactor(double scrollFactor) {
mScrollFactor = scrollFactor;
}
}