Is there a way to override animation accessibility settings for a view in Android

Viewed 323

I have a view in my app that requires animation for validation reasons.

In normal cases the animation works well. Unless when the user's device has animations disabled either from the Accessibility Options or from the Developer settings (Window animation scale, Transition animation scale, Animator duration scale).

Is there a way to display the animation for a view even if the animations are disabled for the device?

Thanks

Here is the animation code:

private ObjectAnimator translateAnimator;
private View animatedView;
...
private void startAnimation() {
    if (translateAnimator == null) {
        translateAnimator = ObjectAnimator.ofFloat(animatedView, "translationX", 0f, 300f);
        translateAnimator.setAutoCancel(true);
        translateAnimator.setDuration(2000);
        translateAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
        translateAnimator.setRepeatCount(ValueAnimator.INFINITE);
        translateAnimator.setRepeatMode(ValueAnimator.REVERSE);

        translateAnimator.start();
    } else {
        translateAnimator.resume();
    }
}
1 Answers

I still don't know how to override user's Animation settings, but at least I found a way to check if animation was disabled by a user and warn them that my application is not going to work as expected.

        try {
            val anim = Settings.Global.getFloat(root.contentResolver, Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f)
            Log.d(TAG, "ANIM = $anim")

            if (-Float.MIN_VALUE <= anim && anim <= Float.MIN_VALUE) {
                // Below is my proprietary showAlret function. You'll need to use yours
                App.app?.showAlert("Enable Animation", R.string.enableAnimation, root, true)
            }

        }
        catch (e: Exception) {
            Log.d(TAG, "ANIM: ${e.message}")
        }

In general, this is just yet another Android's shortcoming demonstrating that engineers don't think much when implement new features: on one hand they provide an API that developers rely on, on the other hand they allow a user to completely disable that API without even warning the user that some apps might not function properly after that.

Related