1 /* 2 * Copyright (C) 2013 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.app.settings.SettingsEnums; 20 import android.content.ContentResolver; 21 import android.content.Context; 22 import android.os.Bundle; 23 import android.provider.Settings; 24 import android.view.accessibility.CaptioningManager; 25 import android.widget.Switch; 26 27 import androidx.preference.Preference; 28 import androidx.preference.Preference.OnPreferenceChangeListener; 29 30 import com.android.settings.R; 31 import com.android.settings.dashboard.DashboardFragment; 32 import com.android.settings.search.BaseSearchIndexProvider; 33 import com.android.settings.widget.SettingsMainSwitchPreference; 34 import com.android.settingslib.search.SearchIndexable; 35 import com.android.settingslib.widget.OnMainSwitchChangeListener; 36 37 import java.util.ArrayList; 38 import java.util.List; 39 40 /** Settings fragment containing captioning properties. */ 41 @SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC) 42 public class CaptionPropertiesFragment extends DashboardFragment 43 implements OnPreferenceChangeListener, OnMainSwitchChangeListener { 44 45 private static final String TAG = "CaptionPropertiesFragment"; 46 private static final String PREF_SWITCH = "captioning_preference_switch"; 47 private static final String PREF_TEXT = "captioning_caption_appearance"; 48 private static final String PREF_MORE = "captioning_more_options"; 49 50 private CaptioningManager mCaptioningManager; 51 52 private SettingsMainSwitchPreference mSwitch; 53 private Preference mTextAppearance; 54 private Preference mMoreOptions; 55 56 private final List<Preference> mPreferenceList = new ArrayList<>(); 57 58 @Override getMetricsCategory()59 public int getMetricsCategory() { 60 return SettingsEnums.ACCESSIBILITY_CAPTION_PROPERTIES; 61 } 62 63 @Override onCreatePreferences(Bundle savedInstanceState, String rootKey)64 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 65 super.onCreatePreferences(savedInstanceState, rootKey); 66 67 mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE); 68 69 initializeAllPreferences(); 70 installUpdateListeners(); 71 } 72 73 @Override onResume()74 public void onResume() { 75 super.onResume(); 76 mSwitch.setChecked(mCaptioningManager.isEnabled()); 77 } 78 79 @Override getPreferenceScreenResId()80 protected int getPreferenceScreenResId() { 81 return R.xml.captioning_settings; 82 } 83 84 @Override getLogTag()85 protected String getLogTag() { 86 return TAG; 87 } 88 initializeAllPreferences()89 private void initializeAllPreferences() { 90 mSwitch = (SettingsMainSwitchPreference) findPreference(PREF_SWITCH); 91 mTextAppearance = (Preference) findPreference(PREF_TEXT); 92 mMoreOptions = (Preference) findPreference(PREF_MORE); 93 94 mPreferenceList.add(mTextAppearance); 95 mPreferenceList.add(mMoreOptions); 96 } 97 installUpdateListeners()98 private void installUpdateListeners() { 99 mSwitch.setOnPreferenceChangeListener(this); 100 mSwitch.addOnSwitchChangeListener(this); 101 102 } 103 104 @Override onPreferenceChange(Preference preference, Object value)105 public boolean onPreferenceChange(Preference preference, Object value) { 106 final ContentResolver cr = getActivity().getContentResolver(); 107 if (mSwitch == preference) { 108 Settings.Secure.putInt( 109 cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, (boolean) value ? 1 : 0); 110 } 111 112 return true; 113 } 114 115 @Override getHelpResource()116 public int getHelpResource() { 117 return R.string.help_url_caption; 118 } 119 120 public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = 121 new BaseSearchIndexProvider(R.xml.captioning_settings); 122 123 @Override onSwitchChanged(Switch switchView, boolean isChecked)124 public void onSwitchChanged(Switch switchView, boolean isChecked) { 125 final ContentResolver cr = getActivity().getContentResolver(); 126 Settings.Secure.putInt( 127 cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, isChecked ? 1 : 0); 128 } 129 } 130