1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file 5 * except in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the 10 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 11 * KIND, either express or implied. See the License for the specific language governing 12 * permissions and limitations under the License. 13 */ 14 package com.android.settings.accessibility; 15 16 import android.content.Context; 17 import android.os.Bundle; 18 import android.provider.Settings; 19 import android.text.TextUtils; 20 21 import androidx.preference.Preference; 22 23 import com.android.settings.R; 24 import com.android.settings.core.TogglePreferenceController; 25 26 public class MagnificationGesturesPreferenceController extends TogglePreferenceController { 27 28 private boolean mIsFromSUW = false; 29 MagnificationGesturesPreferenceController(Context context, String key)30 public MagnificationGesturesPreferenceController(Context context, String key) { 31 super(context, key); 32 } 33 34 @Override isChecked()35 public boolean isChecked() { 36 return MagnificationPreferenceFragment.isChecked(mContext.getContentResolver(), 37 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); 38 } 39 40 @Override setChecked(boolean isChecked)41 public boolean setChecked(boolean isChecked) { 42 return MagnificationPreferenceFragment.setChecked(mContext.getContentResolver(), 43 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, isChecked); 44 } 45 setIsFromSUW(boolean fromSUW)46 public void setIsFromSUW(boolean fromSUW) { 47 mIsFromSUW = fromSUW; 48 } 49 50 @Override handlePreferenceTreeClick(Preference preference)51 public boolean handlePreferenceTreeClick(Preference preference) { 52 if (getPreferenceKey().equals(preference.getKey())) { 53 Bundle extras = preference.getExtras(); 54 populateMagnificationGesturesPreferenceExtras(extras, mContext); 55 extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked()); 56 extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW); 57 return true; 58 } 59 return false; 60 } 61 62 @Override getAvailabilityStatus()63 public int getAvailabilityStatus() { 64 return AVAILABLE; 65 } 66 67 @Override isSliceable()68 public boolean isSliceable() { 69 return TextUtils.equals(getPreferenceKey(), 70 "screen_magnification_gestures_preference_screen"); 71 } 72 73 @Override isPublicSlice()74 public boolean isPublicSlice() { 75 return true; 76 } 77 78 @Override getSummary()79 public CharSequence getSummary() { 80 int resId = 0; 81 if (mIsFromSUW) { 82 resId = R.string.accessibility_screen_magnification_short_summary; 83 } else { 84 final boolean enabled = isChecked(); 85 resId = (enabled ? R.string.accessibility_feature_state_on : 86 R.string.accessibility_feature_state_off); 87 } 88 return mContext.getString(resId); 89 } 90 populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context)91 static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) { 92 extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY, 93 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED); 94 extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES, 95 R.string.accessibility_screen_magnification_gestures_title); 96 extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, 97 context.getText(R.string.accessibility_screen_magnification_summary)); 98 extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID, 99 R.raw.accessibility_screen_magnification); 100 } 101 } 102