1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settings.accessibility; 18 19 import android.content.Context; 20 import android.provider.Settings; 21 import android.text.TextUtils; 22 23 import androidx.annotation.VisibleForTesting; 24 25 import com.android.settings.core.TogglePreferenceController; 26 27 public class DisableAnimationsPreferenceController extends TogglePreferenceController { 28 29 @VisibleForTesting 30 static final String ANIMATION_ON_VALUE = "1"; 31 @VisibleForTesting 32 static final String ANIMATION_OFF_VALUE = "0"; 33 34 // Settings that should be changed when toggling animations 35 @VisibleForTesting 36 static final String[] TOGGLE_ANIMATION_TARGETS = { 37 Settings.Global.WINDOW_ANIMATION_SCALE, Settings.Global.TRANSITION_ANIMATION_SCALE, 38 Settings.Global.ANIMATOR_DURATION_SCALE 39 }; 40 DisableAnimationsPreferenceController(Context context, String preferenceKey)41 public DisableAnimationsPreferenceController(Context context, String preferenceKey) { 42 super(context, preferenceKey); 43 } 44 45 @Override isChecked()46 public boolean isChecked() { 47 boolean allAnimationsDisabled = true; 48 for (String animationSetting : TOGGLE_ANIMATION_TARGETS) { 49 if (!TextUtils.equals( 50 Settings.Global.getString(mContext.getContentResolver(), animationSetting), 51 ANIMATION_OFF_VALUE)) { 52 allAnimationsDisabled = false; 53 break; 54 } 55 } 56 return allAnimationsDisabled; 57 } 58 59 @Override setChecked(boolean isChecked)60 public boolean setChecked(boolean isChecked) { 61 final String newAnimationValue = isChecked ? ANIMATION_OFF_VALUE : ANIMATION_ON_VALUE; 62 boolean allAnimationSet = true; 63 for (String animationPreference : TOGGLE_ANIMATION_TARGETS) { 64 allAnimationSet &= Settings.Global.putString(mContext.getContentResolver(), 65 animationPreference, newAnimationValue); 66 } 67 return allAnimationSet; 68 } 69 70 @Override getAvailabilityStatus()71 public int getAvailabilityStatus() { 72 return AVAILABLE; 73 } 74 } 75