• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.icu.text.MessageFormat;
18 import android.os.Bundle;
19 import android.provider.Settings;
20 import android.text.TextUtils;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settings.R;
25 import com.android.settings.core.TogglePreferenceController;
26 
27 public class MagnificationGesturesPreferenceController extends TogglePreferenceController {
28 
29     private boolean mIsFromSUW = false;
30 
MagnificationGesturesPreferenceController(Context context, String key)31     public MagnificationGesturesPreferenceController(Context context, String key) {
32         super(context, key);
33     }
34 
35     @Override
isChecked()36     public boolean isChecked() {
37         return MagnificationPreferenceFragment.isChecked(mContext.getContentResolver(),
38                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
39     }
40 
41     @Override
setChecked(boolean isChecked)42     public boolean setChecked(boolean isChecked) {
43         return MagnificationPreferenceFragment.setChecked(mContext.getContentResolver(),
44                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED, isChecked);
45     }
46 
setIsFromSUW(boolean fromSUW)47     public void setIsFromSUW(boolean fromSUW) {
48         mIsFromSUW = fromSUW;
49     }
50 
51     @Override
handlePreferenceTreeClick(Preference preference)52     public boolean handlePreferenceTreeClick(Preference preference) {
53         if (getPreferenceKey().equals(preference.getKey())) {
54             Bundle extras = preference.getExtras();
55             populateMagnificationGesturesPreferenceExtras(extras, mContext);
56             extras.putBoolean(AccessibilitySettings.EXTRA_CHECKED, isChecked());
57             extras.putBoolean(AccessibilitySettings.EXTRA_LAUNCHED_FROM_SUW, mIsFromSUW);
58             return true;
59         }
60         return false;
61     }
62 
63     @Override
getAvailabilityStatus()64     public int getAvailabilityStatus() {
65         return AVAILABLE;
66     }
67 
68     @Override
isSliceable()69     public boolean isSliceable() {
70         return TextUtils.equals(getPreferenceKey(),
71                 "screen_magnification_gestures_preference_screen");
72     }
73 
74     @Override
isPublicSlice()75     public boolean isPublicSlice() {
76         return true;
77     }
78 
79     @Override
getSummary()80     public CharSequence getSummary() {
81         int resId = 0;
82         if (mIsFromSUW) {
83             resId = R.string.accessibility_screen_magnification_short_summary;
84         } else {
85             final boolean enabled = isChecked();
86             resId = (enabled ? R.string.accessibility_feature_state_on :
87                     R.string.accessibility_feature_state_off);
88         }
89         return mContext.getString(resId);
90     }
91 
populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context)92     static void populateMagnificationGesturesPreferenceExtras(Bundle extras, Context context) {
93         extras.putString(AccessibilitySettings.EXTRA_PREFERENCE_KEY,
94                 Settings.Secure.ACCESSIBILITY_DISPLAY_MAGNIFICATION_ENABLED);
95         extras.putInt(AccessibilitySettings.EXTRA_TITLE_RES,
96                 R.string.accessibility_screen_magnification_gestures_title);
97 
98         String summary =  context.getString(R.string.accessibility_screen_magnification_summary);
99         final Object[] numberArguments = {1, 2, 3, 4, 5};
100         summary = MessageFormat.format(summary, numberArguments);
101         extras.putCharSequence(AccessibilitySettings.EXTRA_HTML_DESCRIPTION, summary);
102 
103         extras.putInt(AccessibilitySettings.EXTRA_VIDEO_RAW_RESOURCE_ID,
104                 R.raw.accessibility_screen_magnification);
105     }
106 }
107