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