1cc0e782871eb6b946ded880e391866f27953654bAlan Viverette/* 2cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Copyright (C) 2013 The Android Open Source Project 3cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * 4cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Licensed under the Apache License, Version 2.0 (the "License"); 5cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * you may not use this file except in compliance with the License. 6cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * You may obtain a copy of the License at 7cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * 8cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * http://www.apache.org/licenses/LICENSE-2.0 9cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * 10cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Unless required by applicable law or agreed to in writing, software 11cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * distributed under the License is distributed on an "AS IS" BASIS, 12cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * See the License for the specific language governing permissions and 14cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * limitations under the License. 15cc0e782871eb6b946ded880e391866f27953654bAlan Viverette */ 16cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 17cc0e782871eb6b946ded880e391866f27953654bAlan Viverettepackage com.android.settings.accessibility; 18cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 19cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.content.ContentResolver; 205ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viveretteimport android.content.Context; 21cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.content.res.Resources; 22cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.graphics.Color; 23cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.os.Bundle; 24cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.preference.ListPreference; 25cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.preference.Preference; 26660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viveretteimport android.preference.PreferenceCategory; 274098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.preference.PreferenceFrameLayout; 28cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.preference.Preference.OnPreferenceChangeListener; 29cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.provider.Settings; 304098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.view.LayoutInflater; 314098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.view.View; 32a83a532dde44341319810958d67aabb02ff7aea6Alan Viveretteimport android.view.View.OnLayoutChangeListener; 334098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.view.ViewGroup; 344098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.view.ViewGroup.LayoutParams; 35cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.view.accessibility.CaptioningManager; 36cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.view.accessibility.CaptioningManager.CaptionStyle; 37cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 384098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport com.android.internal.widget.SubtitleView; 39cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.R; 406220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglioimport com.android.settings.SettingsActivity; 41cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.SettingsPreferenceFragment; 42cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener; 436220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglioimport com.android.settings.widget.SwitchBar; 445160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch; 455160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener; 464098dba2535453a89ba74022de47578f2556bd41Alan Viverette 474098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport java.util.Locale; 48cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 49cc0e782871eb6b946ded880e391866f27953654bAlan Viverette/** 50cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Settings fragment containing captioning properties. 51cc0e782871eb6b946ded880e391866f27953654bAlan Viverette */ 52cc0e782871eb6b946ded880e391866f27953654bAlan Viverettepublic class CaptionPropertiesFragment extends SettingsPreferenceFragment 53cc0e782871eb6b946ded880e391866f27953654bAlan Viverette implements OnPreferenceChangeListener, OnValueChangedListener { 54205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_BACKGROUND_COLOR = "captioning_background_color"; 55205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity"; 56205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color"; 57205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FOREGROUND_OPACITY = "captioning_foreground_opacity"; 58d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private static final String PREF_WINDOW_COLOR = "captioning_window_color"; 59d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private static final String PREF_WINDOW_OPACITY = "captioning_window_opacity"; 60205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_EDGE_COLOR = "captioning_edge_color"; 61205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_EDGE_TYPE = "captioning_edge_type"; 62205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FONT_SIZE = "captioning_font_size"; 63205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_TYPEFACE = "captioning_typeface"; 64205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_LOCALE = "captioning_locale"; 65205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_PRESET = "captioning_preset"; 66205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_CUSTOM = "custom"; 67205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 68a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette /** WebVtt specifies line height as 5.3% of the viewport height. */ 69a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette private static final float LINE_HEIGHT_RATIO = 0.0533f; 704098dba2535453a89ba74022de47578f2556bd41Alan Viverette 715ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette private CaptioningManager mCaptioningManager; 724098dba2535453a89ba74022de47578f2556bd41Alan Viverette private SubtitleView mPreviewText; 73d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private View mPreviewWindow; 74a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette private View mPreviewViewport; 756220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private SwitchBar mSwitchBar; 76061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette private ToggleSwitch mToggleSwitch; 77cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 78cc0e782871eb6b946ded880e391866f27953654bAlan Viverette // Standard options. 79cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private LocalePreference mLocale; 80cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ListPreference mFontSize; 81cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private PresetPreference mPreset; 82cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 83cc0e782871eb6b946ded880e391866f27953654bAlan Viverette // Custom options. 84cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ListPreference mTypeface; 85cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mForegroundColor; 86205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private ColorPreference mForegroundOpacity; 87cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private EdgeTypePreference mEdgeType; 88cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mEdgeColor; 89cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mBackgroundColor; 90cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mBackgroundOpacity; 91d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private ColorPreference mWindowColor; 92d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private ColorPreference mWindowOpacity; 93660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private PreferenceCategory mCustom; 94660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 95660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private boolean mShowingCustom; 96cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 97cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 98cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public void onCreate(Bundle icicle) { 99cc0e782871eb6b946ded880e391866f27953654bAlan Viverette super.onCreate(icicle); 1005ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette 1015ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE); 1025ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette 103cc0e782871eb6b946ded880e391866f27953654bAlan Viverette addPreferencesFromResource(R.xml.captioning_settings); 104cc0e782871eb6b946ded880e391866f27953654bAlan Viverette initializeAllPreferences(); 105cc0e782871eb6b946ded880e391866f27953654bAlan Viverette updateAllPreferences(); 106660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette refreshShowingCustom(); 107cc0e782871eb6b946ded880e391866f27953654bAlan Viverette installUpdateListeners(); 108cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 109cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 1104098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 1114098dba2535453a89ba74022de47578f2556bd41Alan Viverette public View onCreateView( 1124098dba2535453a89ba74022de47578f2556bd41Alan Viverette LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 1134098dba2535453a89ba74022de47578f2556bd41Alan Viverette final View rootView = inflater.inflate(R.layout.captioning_preview, container, false); 1144098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1154098dba2535453a89ba74022de47578f2556bd41Alan Viverette // We have to do this now because PreferenceFrameLayout looks at it 1164098dba2535453a89ba74022de47578f2556bd41Alan Viverette // only when the view is added. 1174098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (container instanceof PreferenceFrameLayout) { 1184098dba2535453a89ba74022de47578f2556bd41Alan Viverette ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true; 1194098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1204098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1214098dba2535453a89ba74022de47578f2556bd41Alan Viverette final View content = super.onCreateView(inflater, container, savedInstanceState); 1224098dba2535453a89ba74022de47578f2556bd41Alan Viverette ((ViewGroup) rootView.findViewById(R.id.properties_fragment)).addView( 1234098dba2535453a89ba74022de47578f2556bd41Alan Viverette content, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1244098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1254098dba2535453a89ba74022de47578f2556bd41Alan Viverette return rootView; 1264098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1274098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1284098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 1294098dba2535453a89ba74022de47578f2556bd41Alan Viverette public void onViewCreated(View view, Bundle savedInstanceState) { 1304098dba2535453a89ba74022de47578f2556bd41Alan Viverette super.onViewCreated(view, savedInstanceState); 1314098dba2535453a89ba74022de47578f2556bd41Alan Viverette 132061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette final boolean enabled = mCaptioningManager.isEnabled(); 1334098dba2535453a89ba74022de47578f2556bd41Alan Viverette mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); 134061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 135061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 136a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow = view.findViewById(R.id.preview_window); 137a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewViewport = view.findViewById(R.id.preview_viewport); 138a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewViewport.addOnLayoutChangeListener(new OnLayoutChangeListener() { 139a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette @Override 140a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette public void onLayoutChange(View v, int left, int top, int right, int bottom, 141a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette int oldLeft, int oldTop, int oldRight, int oldBottom) { 142a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette refreshPreviewText(); 143a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 144a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette }); 145138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio } 146138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio 147138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio @Override 148138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio public void onActivityCreated(Bundle savedInstanceState) { 149138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio super.onActivityCreated(savedInstanceState); 150a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette 151138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio final boolean enabled = mCaptioningManager.isEnabled(); 1526220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio SettingsActivity activity = (SettingsActivity) getActivity(); 1536220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar = activity.getSwitchBar(); 154006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio mSwitchBar.setCheckedInternal(enabled); 1556220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mToggleSwitch = mSwitchBar.getSwitch(); 156061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 157061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette getPreferenceScreen().setEnabled(enabled); 158061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 1594098dba2535453a89ba74022de47578f2556bd41Alan Viverette refreshPreviewText(); 1604098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1616220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio installSwitchBarToggleSwitch(); 162061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 163061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 164061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette @Override 165138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio public void onDestroyView() { 166138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio super.onDestroyView(); 1676220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio removeSwitchBarToggleSwitch(); 168061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 169061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 1704098dba2535453a89ba74022de47578f2556bd41Alan Viverette private void refreshPreviewText() { 1714098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Context context = getActivity(); 1724098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (context == null) { 1734098dba2535453a89ba74022de47578f2556bd41Alan Viverette // We've been destroyed, abort! 1744098dba2535453a89ba74022de47578f2556bd41Alan Viverette return; 1754098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1764098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1774098dba2535453a89ba74022de47578f2556bd41Alan Viverette final SubtitleView preview = mPreviewText; 1784098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (preview != null) { 1794098dba2535453a89ba74022de47578f2556bd41Alan Viverette final int styleId = mCaptioningManager.getRawUserStyle(); 180a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette applyCaptionProperties(mCaptioningManager, preview, mPreviewViewport, styleId); 1814098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1824098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Locale locale = mCaptioningManager.getLocale(); 1834098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (locale != null) { 1844098dba2535453a89ba74022de47578f2556bd41Alan Viverette final CharSequence localizedText = AccessibilityUtils.getTextForLocale( 1854098dba2535453a89ba74022de47578f2556bd41Alan Viverette context, locale, R.string.captioning_preview_text); 1864098dba2535453a89ba74022de47578f2556bd41Alan Viverette preview.setText(localizedText); 1874098dba2535453a89ba74022de47578f2556bd41Alan Viverette } else { 1884098dba2535453a89ba74022de47578f2556bd41Alan Viverette preview.setText(R.string.captioning_preview_text); 1894098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 190d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 191d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette final CaptionStyle style = mCaptioningManager.getUserStyle(); 192a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette if (style.hasWindowColor()) { 193a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow.setBackgroundColor(style.windowColor); 194a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } else { 195a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette final CaptionStyle defStyle = CaptionStyle.DEFAULT; 196a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow.setBackgroundColor(defStyle.windowColor); 197a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 1984098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1994098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2004098dba2535453a89ba74022de47578f2556bd41Alan Viverette 201a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette public static void applyCaptionProperties(CaptioningManager manager, SubtitleView previewText, 202a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette View previewWindow, int styleId) { 2034098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setStyle(styleId); 2044098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2054098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Context context = previewText.getContext(); 2064098dba2535453a89ba74022de47578f2556bd41Alan Viverette final ContentResolver cr = context.getContentResolver(); 2074098dba2535453a89ba74022de47578f2556bd41Alan Viverette final float fontScale = manager.getFontScale(); 208a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette if (previewWindow != null) { 209389287e5f8a1fe137de959034de39608830878d1Alan Viverette // Assume the viewport is clipped with a 16:9 aspect ratio. 210389287e5f8a1fe137de959034de39608830878d1Alan Viverette final float virtualHeight = Math.max(9 * previewWindow.getWidth(), 211389287e5f8a1fe137de959034de39608830878d1Alan Viverette 16 * previewWindow.getHeight()) / 16.0f; 212389287e5f8a1fe137de959034de39608830878d1Alan Viverette previewText.setTextSize(virtualHeight * LINE_HEIGHT_RATIO * fontScale); 213a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } else { 214a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette final float textSize = context.getResources().getDimension( 215a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette R.dimen.caption_preview_text_size); 216a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette previewText.setTextSize(textSize * fontScale); 217a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 2184098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2194098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Locale locale = manager.getLocale(); 2204098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (locale != null) { 2214098dba2535453a89ba74022de47578f2556bd41Alan Viverette final CharSequence localizedText = AccessibilityUtils.getTextForLocale( 2224098dba2535453a89ba74022de47578f2556bd41Alan Viverette context, locale, R.string.captioning_preview_characters); 2234098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setText(localizedText); 2244098dba2535453a89ba74022de47578f2556bd41Alan Viverette } else { 2254098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setText(R.string.captioning_preview_characters); 2264098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2274098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2284098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2296220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio protected void onInstallSwitchBarToggleSwitch() { 230061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { 2314098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 2324098dba2535453a89ba74022de47578f2556bd41Alan Viverette public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { 233006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio mSwitchBar.setCheckedInternal(checked); 2344098dba2535453a89ba74022de47578f2556bd41Alan Viverette Settings.Secure.putInt(getActivity().getContentResolver(), 2354098dba2535453a89ba74022de47578f2556bd41Alan Viverette Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0); 2364098dba2535453a89ba74022de47578f2556bd41Alan Viverette getPreferenceScreen().setEnabled(checked); 237061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette if (mPreviewText != null) { 238061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mPreviewText.setVisibility(checked ? View.VISIBLE : View.INVISIBLE); 239061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 2404098dba2535453a89ba74022de47578f2556bd41Alan Viverette return false; 2414098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2424098dba2535453a89ba74022de47578f2556bd41Alan Viverette }); 243cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 244cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 2456220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private void installSwitchBarToggleSwitch() { 2466220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio onInstallSwitchBarToggleSwitch(); 2476220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar.show(); 248061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 249061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 2506220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private void removeSwitchBarToggleSwitch() { 2516220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar.hide(); 252061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mToggleSwitch.setOnBeforeCheckedChangeListener(null); 253061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 254061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 255cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void initializeAllPreferences() { 256205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mLocale = (LocalePreference) findPreference(PREF_LOCALE); 257205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE); 258660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 259cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final Resources res = getResources(); 260cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values); 261cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String[] presetTitles = res.getStringArray(R.array.captioning_preset_selector_titles); 262205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mPreset = (PresetPreference) findPreference(PREF_PRESET); 263cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setValues(presetValues); 264cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setTitles(presetTitles); 265cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 266205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mCustom = (PreferenceCategory) findPreference(PREF_CUSTOM); 267660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = true; 268660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 269cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final int[] colorValues = res.getIntArray(R.array.captioning_color_selector_values); 270cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String[] colorTitles = res.getStringArray(R.array.captioning_color_selector_titles); 271205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundColor = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_COLOR); 272cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setTitles(colorTitles); 273cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setValues(colorValues); 274205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 275205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int[] opacityValues = res.getIntArray(R.array.captioning_opacity_selector_values); 276205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final String[] opacityTitles = res.getStringArray( 277205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette R.array.captioning_opacity_selector_titles); 278205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_OPACITY); 279205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setTitles(opacityTitles); 280205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setValues(opacityValues); 281205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 282205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mEdgeColor = (ColorPreference) mCustom.findPreference(PREF_EDGE_COLOR); 283cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setTitles(colorTitles); 284cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setValues(colorValues); 285cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 286660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette // Add "none" as an additional option for backgrounds. 287660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final int[] bgColorValues = new int[colorValues.length + 1]; 288660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final String[] bgColorTitles = new String[colorTitles.length + 1]; 289660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette System.arraycopy(colorValues, 0, bgColorValues, 1, colorValues.length); 290660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette System.arraycopy(colorTitles, 0, bgColorTitles, 1, colorTitles.length); 291660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette bgColorValues[0] = Color.TRANSPARENT; 292660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette bgColorTitles[0] = getString(R.string.color_none); 293205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mBackgroundColor = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_COLOR); 294cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setTitles(bgColorTitles); 295cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setValues(bgColorValues); 296cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 297205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mBackgroundOpacity = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_OPACITY); 298cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setTitles(opacityTitles); 299cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setValues(opacityValues); 300cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 301d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor = (ColorPreference) mCustom.findPreference(PREF_WINDOW_COLOR); 302d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setTitles(bgColorTitles); 303d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setValues(bgColorValues); 304d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 305d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity = (ColorPreference) mCustom.findPreference(PREF_WINDOW_OPACITY); 306d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setTitles(opacityTitles); 307d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setValues(opacityValues); 308d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 309205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mEdgeType = (EdgeTypePreference) mCustom.findPreference(PREF_EDGE_TYPE); 310205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mTypeface = (ListPreference) mCustom.findPreference(PREF_TYPEFACE); 311cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 312cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 313cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void installUpdateListeners() { 314cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setOnValueChangedListener(this); 315cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setOnValueChangedListener(this); 316205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setOnValueChangedListener(this); 317cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setOnValueChangedListener(this); 318cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setOnValueChangedListener(this); 319cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setOnValueChangedListener(this); 320d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setOnValueChangedListener(this); 321d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setOnValueChangedListener(this); 322cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeType.setOnValueChangedListener(this); 323cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 324cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mTypeface.setOnPreferenceChangeListener(this); 325cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mFontSize.setOnPreferenceChangeListener(this); 326cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mLocale.setOnPreferenceChangeListener(this); 327cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 328cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 329cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void updateAllPreferences() { 3305ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final int preset = mCaptioningManager.getRawUserStyle(); 331cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setValue(preset); 332cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3335ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final float fontSize = mCaptioningManager.getFontScale(); 334cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mFontSize.setValue(Float.toString(fontSize)); 335cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3365ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final ContentResolver cr = getContentResolver(); 337cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final CaptionStyle attrs = CaptionStyle.getCustomStyle(cr); 338cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeType.setValue(attrs.edgeType); 339cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setValue(attrs.edgeColor); 340cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 341205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette parseColorOpacity(mForegroundColor, mForegroundOpacity, attrs.foregroundColor); 342205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette parseColorOpacity(mBackgroundColor, mBackgroundOpacity, attrs.backgroundColor); 343d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette parseColorOpacity(mWindowColor, mWindowOpacity, attrs.windowColor); 344cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 345cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String rawTypeface = attrs.mRawTypeface; 346cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mTypeface.setValue(rawTypeface == null ? "" : rawTypeface); 347cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3485ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final String rawLocale = mCaptioningManager.getRawLocale(); 349cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mLocale.setValue(rawLocale == null ? "" : rawLocale); 350cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 351cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 352205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) { 353205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int colorValue; 354205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int opacityValue; 355205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette if (Color.alpha(value) == 0) { 356205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette colorValue = Color.TRANSPARENT; 357205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacityValue = (value & 0xFF) << 24; 358205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } else { 359205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette colorValue = value | 0xFF000000; 360205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacityValue = value & 0xFF000000; 361205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 362205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette color.setValue(colorValue); 363205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacity.setValue(opacityValue | 0xFFFFFF); 364205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 365205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 366205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private int mergeColorOpacity(ColorPreference color, ColorPreference opacity) { 367205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int colorValue = color.getValue(); 368205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int opacityValue = opacity.getValue(); 369205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int value; 370205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette if (Color.alpha(colorValue) == 0) { 371a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette value = colorValue & 0x00FFFF00 | Color.alpha(opacityValue); 372205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } else { 373205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette value = colorValue & 0x00FFFFFF | opacityValue & 0xFF000000; 374205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 375205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette return value; 376205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 377205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 378660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private void refreshShowingCustom() { 379660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final boolean customPreset = mPreset.getValue() == CaptionStyle.PRESET_CUSTOM; 380660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette if (!customPreset && mShowingCustom) { 381660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette getPreferenceScreen().removePreference(mCustom); 382660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = false; 383660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } else if (customPreset && !mShowingCustom) { 384660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette getPreferenceScreen().addPreference(mCustom); 385660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = true; 386660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } 387660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } 388660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 389cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 390cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public void onValueChanged(ListDialogPreference preference, int value) { 391cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final ContentResolver cr = getActivity().getContentResolver(); 392205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette if (mForegroundColor == preference || mForegroundOpacity == preference) { 393205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int merged = mergeColorOpacity(mForegroundColor, mForegroundOpacity); 394cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt( 395205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, merged); 396cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mBackgroundColor == preference || mBackgroundOpacity == preference) { 397205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int merged = mergeColorOpacity(mBackgroundColor, mBackgroundOpacity); 398cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt( 399205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, merged); 400d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette } else if (mWindowColor == preference || mWindowOpacity == preference) { 401d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette final int merged = mergeColorOpacity(mWindowColor, mWindowOpacity); 402d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette Settings.Secure.putInt( 403d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, merged); 404cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mEdgeColor == preference) { 405cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, value); 406cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mPreset == preference) { 407cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET, value); 408660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette refreshShowingCustom(); 409cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mEdgeType == preference) { 410cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, value); 411cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 412cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 413cc0e782871eb6b946ded880e391866f27953654bAlan Viverette refreshPreviewText(); 414cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 415cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 416cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 417cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public boolean onPreferenceChange(Preference preference, Object value) { 418cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final ContentResolver cr = getActivity().getContentResolver(); 419cc0e782871eb6b946ded880e391866f27953654bAlan Viverette if (mTypeface == preference) { 420cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putString( 421cc0e782871eb6b946ded880e391866f27953654bAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE, (String) value); 422cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mFontSize == preference) { 423cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putFloat( 4245ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE, 425cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Float.parseFloat((String) value)); 426cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mLocale == preference) { 427cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putString( 428cc0e782871eb6b946ded880e391866f27953654bAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_LOCALE, (String) value); 429cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 430cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 431cc0e782871eb6b946ded880e391866f27953654bAlan Viverette refreshPreviewText(); 432cc0e782871eb6b946ded880e391866f27953654bAlan Viverette return true; 433cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 434cc0e782871eb6b946ded880e391866f27953654bAlan Viverette} 435