I know, I can start the Settings-Activity with
Intent intent = new Intent(Settings.ACTION_DISPLAY_SETTINGS);
startActivityForResult(intent,1);
But how do I know if the animations are enabled in the first place?
I have an animation inside a custom view and only want to show it, if the animations are enabled in the settings. If they are disabled, I'd like to ask the user to enable them the first time he starts the application.
Settings.System.TRANSITION_ANIMATION_SCALE and Settings.System.ANIMATOR_DURATION_SCALE are deprecated from API 17.
So I use this method to find out.
private boolean areSystemAnimationsEnabled() {
float duration, transition;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
duration = Settings.Global.getFloat(
context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE, 1);
transition = Settings.Global.getFloat(
context.getContentResolver(),
Settings.Global.TRANSITION_ANIMATION_SCALE, 1);
} else {
duration = Settings.System.getFloat(
context.getContentResolver(),
Settings.System.ANIMATOR_DURATION_SCALE, 1);
transition = Settings.System.getFloat(
context.getContentResolver(),
Settings.System.TRANSITION_ANIMATION_SCALE, 1);
}
return (duration != 0 && transition != 0);
}
Or, you can check only for ANIMATOR_DURATION_SCALE...
private float checkSystemAnimationsDuration() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
return Settings.Global.getFloat(
context.getContentResolver(),
Settings.Global.ANIMATOR_DURATION_SCALE,
0);
} else {
return Settings.System.getFloat(
context.getContentResolver(),
Settings.System.ANIMATOR_DURATION_SCALE,
0);
}
}
and set your valueAnimator.setDuration() accordingly.
ValueAnimator alphaFirstItemAnimator = new ValueAnimator();
alphaFirstItemAnimator.setObjectValues(0.8F, 0F);
alphaFirstItemAnimator.setDuration((long)(DURATION_ANIMATION_MILLIS * checkSystemAnimationsDuration()));
alphaFirstItemAnimator.setInterpolator(new DecelerateInterpolator());
alphaFirstItemAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
}
});
I hope it helps someone.
Check out http://developer.android.com/reference/android/provider/Settings.System.html.
You can read the flags:
If they are 0, then animations are disabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With