Skip to content

Instantly share code, notes, and snippets.

@jsonfry
Last active October 12, 2016 13:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsonfry/374c3eb5b8eb88d2a674100d6bfecd92 to your computer and use it in GitHub Desktop.
Save jsonfry/374c3eb5b8eb88d2a674100d6bfecd92 to your computer and use it in GitHub Desktop.
package co.blah.ui.widget;
import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.provider.Settings;
import android.util.AttributeSet;
import android.widget.ProgressBar;
public class TestableIndeterminateProgressBar extends ProgressBar {
public TestableIndeterminateProgressBar(Context context) {
super(context);
}
public TestableIndeterminateProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public TestableIndeterminateProgressBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@TargetApi(21)
public TestableIndeterminateProgressBar(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
@Override
public void setIndeterminateDrawable(Drawable drawable) {
super.setIndeterminateDrawable(hideIndeterminateDrawable() ? null : drawable);
}
private boolean hideIndeterminateDrawable() {
return android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP &&
Settings.Global.getFloat(getContext().getContentResolver(), Settings.Global.ANIMATOR_DURATION_SCALE, 1) == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment