How to enable Remove Animation from Settings -> Accessibility android

710 Views Asked by At

I need to enable Remove Animation from Accessibility. By default, it has been disabled.

Below is the picture.

enter image description here

How to enable Remove Animation by default?

Here is the code where it has been disabled by default.

     private SwitchPreference mToggleDisableAnimationsPreference;

       // Settings that should be changed when toggling animations
    private static final String[] TOGGLE_ANIMATION_TARGETS = {
            Settings.Global.WINDOW_ANIMATION_SCALE, Settings.Global.TRANSITION_ANIMATION_SCALE,
            Settings.Global.ANIMATOR_DURATION_SCALE
    };
    private static final String ANIMATION_ON_VALUE = "1";
    private static final String ANIMATION_OFF_VALUE = "0";

    mToggleDisableAnimationsPreference =
                (SwitchPreference) findPreference(TOGGLE_DISABLE_ANIMATIONS);

     updateDisableAnimationsToggle();

  @Override
    public boolean onPreferenceTreeClick(Preference preference) {

     if (mToggleDisableAnimationsPreference == preference) {
            handleToggleDisableAnimations();
            return true;
        } 
     return super.onPreferenceTreeClick(preference);

} 

  private void handleToggleDisableAnimations() {
        String newAnimationValue = mToggleDisableAnimationsPreference.isChecked()
                ? ANIMATION_OFF_VALUE : ANIMATION_ON_VALUE;
        for (String animationPreference : TOGGLE_ANIMATION_TARGETS) {
            Settings.Global.putString(getContentResolver(), animationPreference, newAnimationValue);
        }
    }

 private void updateDisableAnimationsToggle() {
        boolean allAnimationsDisabled = true;
        for (String animationSetting : TOGGLE_ANIMATION_TARGETS) {
            if (!TextUtils.equals(
                    Settings.Global.getString(getContentResolver(), animationSetting),
                    ANIMATION_OFF_VALUE)) {
                allAnimationsDisabled = false;
                break;
            }
        }
        mToggleDisableAnimationsPreference.setChecked(allAnimationsDisabled);
    }

This is the code from aosp. Now where exactly I need to enable by disabling animation by default?

1

There are 1 best solutions below

2
snachmsm On

you can try to execute handleToggleDisableAnimations (a bit modified), but I doubt that common app can change this setting, afaik there is no permission for that

private void handleDisableAnimations(boolean enabled) {
    String newAnimationValue = enabled
            ? ANIMATION_ON_VALUE : ANIMATION_OFF_VALUE;
    for (String animationPreference : TOGGLE_ANIMATION_TARGETS) {
        Settings.Global.putString(getContentResolver(), animationPreference, newAnimationValue);
    }
}