CaptionPropertiesFragment.java revision 39b467482d1bf256a111c757e9b7621c6f523271
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; 244098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport android.preference.PreferenceFrameLayout; 25cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport android.provider.Settings; 2639b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.ListPreference; 2739b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.Preference; 2839b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.Preference.OnPreferenceChangeListener; 2939b467482d1bf256a111c757e9b7621c6f523271Jason Monkimport android.support.v7.preference.PreferenceCategory; 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 388a963babe2e36b7a41f77b8d2598c97658196e58Chris Wrenimport com.android.internal.logging.MetricsLogger; 394098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport com.android.internal.widget.SubtitleView; 40cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.R; 416220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglioimport com.android.settings.SettingsActivity; 42cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.SettingsPreferenceFragment; 43cc0e782871eb6b946ded880e391866f27953654bAlan Viveretteimport com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener; 446220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglioimport com.android.settings.widget.SwitchBar; 455160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch; 465160536df91bb9daa6cac9a878ce406deda791c6Fabrice Di Meglioimport com.android.settings.widget.ToggleSwitch.OnBeforeCheckedChangeListener; 474098dba2535453a89ba74022de47578f2556bd41Alan Viverette 484098dba2535453a89ba74022de47578f2556bd41Alan Viveretteimport java.util.Locale; 49cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 50cc0e782871eb6b946ded880e391866f27953654bAlan Viverette/** 51cc0e782871eb6b946ded880e391866f27953654bAlan Viverette * Settings fragment containing captioning properties. 52cc0e782871eb6b946ded880e391866f27953654bAlan Viverette */ 53cc0e782871eb6b946ded880e391866f27953654bAlan Viverettepublic class CaptionPropertiesFragment extends SettingsPreferenceFragment 54cc0e782871eb6b946ded880e391866f27953654bAlan Viverette implements OnPreferenceChangeListener, OnValueChangedListener { 55205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_BACKGROUND_COLOR = "captioning_background_color"; 56205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity"; 57205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color"; 58205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FOREGROUND_OPACITY = "captioning_foreground_opacity"; 59d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private static final String PREF_WINDOW_COLOR = "captioning_window_color"; 60d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private static final String PREF_WINDOW_OPACITY = "captioning_window_opacity"; 61205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_EDGE_COLOR = "captioning_edge_color"; 62205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_EDGE_TYPE = "captioning_edge_type"; 63205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_FONT_SIZE = "captioning_font_size"; 64205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_TYPEFACE = "captioning_typeface"; 65205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_LOCALE = "captioning_locale"; 66205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_PRESET = "captioning_preset"; 67205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private static final String PREF_CUSTOM = "custom"; 68205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 69a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette /** WebVtt specifies line height as 5.3% of the viewport height. */ 70a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette private static final float LINE_HEIGHT_RATIO = 0.0533f; 714098dba2535453a89ba74022de47578f2556bd41Alan Viverette 725ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette private CaptioningManager mCaptioningManager; 734098dba2535453a89ba74022de47578f2556bd41Alan Viverette private SubtitleView mPreviewText; 74d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private View mPreviewWindow; 75a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette private View mPreviewViewport; 766220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private SwitchBar mSwitchBar; 77061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette private ToggleSwitch mToggleSwitch; 78cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 79cc0e782871eb6b946ded880e391866f27953654bAlan Viverette // Standard options. 80cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private LocalePreference mLocale; 81cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ListPreference mFontSize; 82cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private PresetPreference mPreset; 83cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 84cc0e782871eb6b946ded880e391866f27953654bAlan Viverette // Custom options. 85cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ListPreference mTypeface; 86cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mForegroundColor; 87205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private ColorPreference mForegroundOpacity; 88cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private EdgeTypePreference mEdgeType; 89cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mEdgeColor; 90cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mBackgroundColor; 91cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private ColorPreference mBackgroundOpacity; 92d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private ColorPreference mWindowColor; 93d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette private ColorPreference mWindowOpacity; 94660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private PreferenceCategory mCustom; 95660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 96660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private boolean mShowingCustom; 97cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 98cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 998a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren protected int getMetricsCategory() { 1008a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren return MetricsLogger.ACCESSIBILITY_CAPTION_PROPERTIES; 1018a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren } 1028a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren 1038a963babe2e36b7a41f77b8d2598c97658196e58Chris Wren @Override 104cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public void onCreate(Bundle icicle) { 105cc0e782871eb6b946ded880e391866f27953654bAlan Viverette super.onCreate(icicle); 1065ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette 1075ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette mCaptioningManager = (CaptioningManager) getSystemService(Context.CAPTIONING_SERVICE); 1085ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette 109cc0e782871eb6b946ded880e391866f27953654bAlan Viverette addPreferencesFromResource(R.xml.captioning_settings); 110cc0e782871eb6b946ded880e391866f27953654bAlan Viverette initializeAllPreferences(); 111cc0e782871eb6b946ded880e391866f27953654bAlan Viverette updateAllPreferences(); 112660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette refreshShowingCustom(); 113cc0e782871eb6b946ded880e391866f27953654bAlan Viverette installUpdateListeners(); 114cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 115cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 1164098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 1174098dba2535453a89ba74022de47578f2556bd41Alan Viverette public View onCreateView( 1184098dba2535453a89ba74022de47578f2556bd41Alan Viverette LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 1194098dba2535453a89ba74022de47578f2556bd41Alan Viverette final View rootView = inflater.inflate(R.layout.captioning_preview, container, false); 1204098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1214098dba2535453a89ba74022de47578f2556bd41Alan Viverette // We have to do this now because PreferenceFrameLayout looks at it 1224098dba2535453a89ba74022de47578f2556bd41Alan Viverette // only when the view is added. 1234098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (container instanceof PreferenceFrameLayout) { 1244098dba2535453a89ba74022de47578f2556bd41Alan Viverette ((PreferenceFrameLayout.LayoutParams) rootView.getLayoutParams()).removeBorders = true; 1254098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1264098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1274098dba2535453a89ba74022de47578f2556bd41Alan Viverette final View content = super.onCreateView(inflater, container, savedInstanceState); 1284098dba2535453a89ba74022de47578f2556bd41Alan Viverette ((ViewGroup) rootView.findViewById(R.id.properties_fragment)).addView( 1294098dba2535453a89ba74022de47578f2556bd41Alan Viverette content, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 1304098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1314098dba2535453a89ba74022de47578f2556bd41Alan Viverette return rootView; 1324098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1334098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1344098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 1354098dba2535453a89ba74022de47578f2556bd41Alan Viverette public void onViewCreated(View view, Bundle savedInstanceState) { 1364098dba2535453a89ba74022de47578f2556bd41Alan Viverette super.onViewCreated(view, savedInstanceState); 1374098dba2535453a89ba74022de47578f2556bd41Alan Viverette 138061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette final boolean enabled = mCaptioningManager.isEnabled(); 1394098dba2535453a89ba74022de47578f2556bd41Alan Viverette mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); 140061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); 141061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 142a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow = view.findViewById(R.id.preview_window); 143a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewViewport = view.findViewById(R.id.preview_viewport); 144a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewViewport.addOnLayoutChangeListener(new OnLayoutChangeListener() { 145a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette @Override 146a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette public void onLayoutChange(View v, int left, int top, int right, int bottom, 147a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette int oldLeft, int oldTop, int oldRight, int oldBottom) { 148a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette refreshPreviewText(); 149a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 150a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette }); 151138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio } 152138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio 153138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio @Override 154138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio public void onActivityCreated(Bundle savedInstanceState) { 155138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio super.onActivityCreated(savedInstanceState); 156a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette 157138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio final boolean enabled = mCaptioningManager.isEnabled(); 1586220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio SettingsActivity activity = (SettingsActivity) getActivity(); 1596220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar = activity.getSwitchBar(); 160006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio mSwitchBar.setCheckedInternal(enabled); 1616220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mToggleSwitch = mSwitchBar.getSwitch(); 162061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 163061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette getPreferenceScreen().setEnabled(enabled); 164061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 1654098dba2535453a89ba74022de47578f2556bd41Alan Viverette refreshPreviewText(); 1664098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1676220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio installSwitchBarToggleSwitch(); 168061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 169061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 170061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette @Override 171138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio public void onDestroyView() { 172138ff8c0457c6e1345015973668d652fa17c7c3bFabrice Di Meglio super.onDestroyView(); 1736220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio removeSwitchBarToggleSwitch(); 174061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 175061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 1764098dba2535453a89ba74022de47578f2556bd41Alan Viverette private void refreshPreviewText() { 1774098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Context context = getActivity(); 1784098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (context == null) { 1794098dba2535453a89ba74022de47578f2556bd41Alan Viverette // We've been destroyed, abort! 1804098dba2535453a89ba74022de47578f2556bd41Alan Viverette return; 1814098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 1824098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1834098dba2535453a89ba74022de47578f2556bd41Alan Viverette final SubtitleView preview = mPreviewText; 1844098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (preview != null) { 1854098dba2535453a89ba74022de47578f2556bd41Alan Viverette final int styleId = mCaptioningManager.getRawUserStyle(); 186a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette applyCaptionProperties(mCaptioningManager, preview, mPreviewViewport, styleId); 1874098dba2535453a89ba74022de47578f2556bd41Alan Viverette 1884098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Locale locale = mCaptioningManager.getLocale(); 1894098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (locale != null) { 1904098dba2535453a89ba74022de47578f2556bd41Alan Viverette final CharSequence localizedText = AccessibilityUtils.getTextForLocale( 1914098dba2535453a89ba74022de47578f2556bd41Alan Viverette context, locale, R.string.captioning_preview_text); 1924098dba2535453a89ba74022de47578f2556bd41Alan Viverette preview.setText(localizedText); 1934098dba2535453a89ba74022de47578f2556bd41Alan Viverette } else { 1944098dba2535453a89ba74022de47578f2556bd41Alan Viverette preview.setText(R.string.captioning_preview_text); 1954098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 196d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 197d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette final CaptionStyle style = mCaptioningManager.getUserStyle(); 198a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette if (style.hasWindowColor()) { 199a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow.setBackgroundColor(style.windowColor); 200a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } else { 201a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette final CaptionStyle defStyle = CaptionStyle.DEFAULT; 202a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette mPreviewWindow.setBackgroundColor(defStyle.windowColor); 203a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 2044098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2054098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2064098dba2535453a89ba74022de47578f2556bd41Alan Viverette 207a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette public static void applyCaptionProperties(CaptioningManager manager, SubtitleView previewText, 208a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette View previewWindow, int styleId) { 2094098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setStyle(styleId); 2104098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2114098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Context context = previewText.getContext(); 2124098dba2535453a89ba74022de47578f2556bd41Alan Viverette final ContentResolver cr = context.getContentResolver(); 2134098dba2535453a89ba74022de47578f2556bd41Alan Viverette final float fontScale = manager.getFontScale(); 214a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette if (previewWindow != null) { 215389287e5f8a1fe137de959034de39608830878d1Alan Viverette // Assume the viewport is clipped with a 16:9 aspect ratio. 216389287e5f8a1fe137de959034de39608830878d1Alan Viverette final float virtualHeight = Math.max(9 * previewWindow.getWidth(), 217389287e5f8a1fe137de959034de39608830878d1Alan Viverette 16 * previewWindow.getHeight()) / 16.0f; 218389287e5f8a1fe137de959034de39608830878d1Alan Viverette previewText.setTextSize(virtualHeight * LINE_HEIGHT_RATIO * fontScale); 219a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } else { 220a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette final float textSize = context.getResources().getDimension( 221a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette R.dimen.caption_preview_text_size); 222a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette previewText.setTextSize(textSize * fontScale); 223a83a532dde44341319810958d67aabb02ff7aea6Alan Viverette } 2244098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2254098dba2535453a89ba74022de47578f2556bd41Alan Viverette final Locale locale = manager.getLocale(); 2264098dba2535453a89ba74022de47578f2556bd41Alan Viverette if (locale != null) { 2274098dba2535453a89ba74022de47578f2556bd41Alan Viverette final CharSequence localizedText = AccessibilityUtils.getTextForLocale( 2284098dba2535453a89ba74022de47578f2556bd41Alan Viverette context, locale, R.string.captioning_preview_characters); 2294098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setText(localizedText); 2304098dba2535453a89ba74022de47578f2556bd41Alan Viverette } else { 2314098dba2535453a89ba74022de47578f2556bd41Alan Viverette previewText.setText(R.string.captioning_preview_characters); 2324098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2334098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2344098dba2535453a89ba74022de47578f2556bd41Alan Viverette 2356220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio protected void onInstallSwitchBarToggleSwitch() { 236061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mToggleSwitch.setOnBeforeCheckedChangeListener(new OnBeforeCheckedChangeListener() { 2374098dba2535453a89ba74022de47578f2556bd41Alan Viverette @Override 2384098dba2535453a89ba74022de47578f2556bd41Alan Viverette public boolean onBeforeCheckedChanged(ToggleSwitch toggleSwitch, boolean checked) { 239006b2cca1311e61472a8b66fb0c50854fc36d2e7Fabrice Di Meglio mSwitchBar.setCheckedInternal(checked); 2404098dba2535453a89ba74022de47578f2556bd41Alan Viverette Settings.Secure.putInt(getActivity().getContentResolver(), 2414098dba2535453a89ba74022de47578f2556bd41Alan Viverette Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, checked ? 1 : 0); 2424098dba2535453a89ba74022de47578f2556bd41Alan Viverette getPreferenceScreen().setEnabled(checked); 243061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette if (mPreviewText != null) { 244061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mPreviewText.setVisibility(checked ? View.VISIBLE : View.INVISIBLE); 245061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 2464098dba2535453a89ba74022de47578f2556bd41Alan Viverette return false; 2474098dba2535453a89ba74022de47578f2556bd41Alan Viverette } 2484098dba2535453a89ba74022de47578f2556bd41Alan Viverette }); 249cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 250cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 2516220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private void installSwitchBarToggleSwitch() { 2526220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio onInstallSwitchBarToggleSwitch(); 2536220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar.show(); 254061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 255061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 2566220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio private void removeSwitchBarToggleSwitch() { 2576220275d6dec8ffc6f1df2cbfbf42934d09d41f0Fabrice Di Meglio mSwitchBar.hide(); 258061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette mToggleSwitch.setOnBeforeCheckedChangeListener(null); 259061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette } 260061333c26bbb848b8982b04d6043061cb2451a90Alan Viverette 261cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void initializeAllPreferences() { 262205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mLocale = (LocalePreference) findPreference(PREF_LOCALE); 263205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE); 264660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 265cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final Resources res = getResources(); 266cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values); 267cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String[] presetTitles = res.getStringArray(R.array.captioning_preset_selector_titles); 268205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mPreset = (PresetPreference) findPreference(PREF_PRESET); 269cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setValues(presetValues); 270cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setTitles(presetTitles); 271cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 272205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mCustom = (PreferenceCategory) findPreference(PREF_CUSTOM); 273660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = true; 274660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 275cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final int[] colorValues = res.getIntArray(R.array.captioning_color_selector_values); 276cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String[] colorTitles = res.getStringArray(R.array.captioning_color_selector_titles); 277205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundColor = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_COLOR); 278cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setTitles(colorTitles); 279cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setValues(colorValues); 280205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 281205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int[] opacityValues = res.getIntArray(R.array.captioning_opacity_selector_values); 282205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final String[] opacityTitles = res.getStringArray( 283205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette R.array.captioning_opacity_selector_titles); 284205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_OPACITY); 285205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setTitles(opacityTitles); 286205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setValues(opacityValues); 287205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 288205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mEdgeColor = (ColorPreference) mCustom.findPreference(PREF_EDGE_COLOR); 289cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setTitles(colorTitles); 290cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setValues(colorValues); 291cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 292660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette // Add "none" as an additional option for backgrounds. 293660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final int[] bgColorValues = new int[colorValues.length + 1]; 294660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final String[] bgColorTitles = new String[colorTitles.length + 1]; 295660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette System.arraycopy(colorValues, 0, bgColorValues, 1, colorValues.length); 296660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette System.arraycopy(colorTitles, 0, bgColorTitles, 1, colorTitles.length); 297660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette bgColorValues[0] = Color.TRANSPARENT; 298660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette bgColorTitles[0] = getString(R.string.color_none); 299205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mBackgroundColor = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_COLOR); 300cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setTitles(bgColorTitles); 301cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setValues(bgColorValues); 302cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 303205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mBackgroundOpacity = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_OPACITY); 304cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setTitles(opacityTitles); 305cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setValues(opacityValues); 306cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 307d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor = (ColorPreference) mCustom.findPreference(PREF_WINDOW_COLOR); 308d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setTitles(bgColorTitles); 309d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setValues(bgColorValues); 310d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 311d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity = (ColorPreference) mCustom.findPreference(PREF_WINDOW_OPACITY); 312d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setTitles(opacityTitles); 313d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setValues(opacityValues); 314d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette 315205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mEdgeType = (EdgeTypePreference) mCustom.findPreference(PREF_EDGE_TYPE); 316205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mTypeface = (ListPreference) mCustom.findPreference(PREF_TYPEFACE); 317cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 318cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 319cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void installUpdateListeners() { 320cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setOnValueChangedListener(this); 321cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mForegroundColor.setOnValueChangedListener(this); 322205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette mForegroundOpacity.setOnValueChangedListener(this); 323cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setOnValueChangedListener(this); 324cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundColor.setOnValueChangedListener(this); 325cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mBackgroundOpacity.setOnValueChangedListener(this); 326d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowColor.setOnValueChangedListener(this); 327d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette mWindowOpacity.setOnValueChangedListener(this); 328cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeType.setOnValueChangedListener(this); 329cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 330cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mTypeface.setOnPreferenceChangeListener(this); 331cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mFontSize.setOnPreferenceChangeListener(this); 332cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mLocale.setOnPreferenceChangeListener(this); 333cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 334cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 335cc0e782871eb6b946ded880e391866f27953654bAlan Viverette private void updateAllPreferences() { 3365ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final int preset = mCaptioningManager.getRawUserStyle(); 337cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mPreset.setValue(preset); 338cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3395ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final float fontSize = mCaptioningManager.getFontScale(); 340cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mFontSize.setValue(Float.toString(fontSize)); 341cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3425ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final ContentResolver cr = getContentResolver(); 343cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final CaptionStyle attrs = CaptionStyle.getCustomStyle(cr); 344cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeType.setValue(attrs.edgeType); 345cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mEdgeColor.setValue(attrs.edgeColor); 346cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 347751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette final int foregroundColor = attrs.hasForegroundColor() ? 348751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette attrs.foregroundColor : CaptionStyle.COLOR_UNSPECIFIED; 349751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette parseColorOpacity(mForegroundColor, mForegroundOpacity, foregroundColor); 350751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette 351751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette final int backgroundColor = attrs.hasBackgroundColor() ? 352751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette attrs.backgroundColor : CaptionStyle.COLOR_UNSPECIFIED; 353751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette parseColorOpacity(mBackgroundColor, mBackgroundOpacity, backgroundColor); 354751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette 355751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette final int windowColor = attrs.hasWindowColor() ? 356751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette attrs.windowColor : CaptionStyle.COLOR_UNSPECIFIED; 357751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette parseColorOpacity(mWindowColor, mWindowOpacity, windowColor); 358cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 359cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final String rawTypeface = attrs.mRawTypeface; 360cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mTypeface.setValue(rawTypeface == null ? "" : rawTypeface); 361cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 3625ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette final String rawLocale = mCaptioningManager.getRawLocale(); 363cc0e782871eb6b946ded880e391866f27953654bAlan Viverette mLocale.setValue(rawLocale == null ? "" : rawLocale); 364cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 365cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 366751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette /** 367751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette * Unpack the specified color value and update the preferences. 368751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette * 369751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette * @param color color preference 370751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette * @param opacity opacity preference 371751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette * @param value packed value 372751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette */ 373205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) { 374205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int colorValue; 375205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int opacityValue; 376751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette if (!CaptionStyle.hasColor(value)) { 377751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // "Default" color with variable alpha. 378751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette colorValue = CaptionStyle.COLOR_UNSPECIFIED; 379751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette opacityValue = (value & 0xFF) << 24; 380751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette } else if ((value >>> 24) == 0) { 381751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // "None" color with variable alpha. 382205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette colorValue = Color.TRANSPARENT; 383205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacityValue = (value & 0xFF) << 24; 384205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } else { 385751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // Normal color. 386205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette colorValue = value | 0xFF000000; 387205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacityValue = value & 0xFF000000; 388205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 389751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette 390751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // Opacity value is always white. 391205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette opacity.setValue(opacityValue | 0xFFFFFF); 392751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette color.setValue(colorValue); 393205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 394205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 395205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette private int mergeColorOpacity(ColorPreference color, ColorPreference opacity) { 396205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int colorValue = color.getValue(); 397205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int opacityValue = opacity.getValue(); 398205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int value; 399751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // "Default" is 0x00FFFFFF or, for legacy support, 0x00000100. 400751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette if (!CaptionStyle.hasColor(colorValue)) { 401751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // Encode "default" as 0x00FFFFaa. 402751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette value = 0x00FFFF00 | Color.alpha(opacityValue); 403751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette } else if (colorValue == Color.TRANSPARENT) { 404751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // Encode "none" as 0x000000aa. 405751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette value = Color.alpha(opacityValue); 406205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } else { 407751625e9a20cdd11073cdadb06b2c18464e9701cAlan Viverette // Encode custom color normally. 408205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette value = colorValue & 0x00FFFFFF | opacityValue & 0xFF000000; 409205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 410205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette return value; 411205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette } 412205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette 413660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette private void refreshShowingCustom() { 414660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette final boolean customPreset = mPreset.getValue() == CaptionStyle.PRESET_CUSTOM; 415660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette if (!customPreset && mShowingCustom) { 416660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette getPreferenceScreen().removePreference(mCustom); 417660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = false; 418660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } else if (customPreset && !mShowingCustom) { 419660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette getPreferenceScreen().addPreference(mCustom); 420660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette mShowingCustom = true; 421660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } 422660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette } 423660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette 424cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 425cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public void onValueChanged(ListDialogPreference preference, int value) { 426cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final ContentResolver cr = getActivity().getContentResolver(); 427205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette if (mForegroundColor == preference || mForegroundOpacity == preference) { 428205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int merged = mergeColorOpacity(mForegroundColor, mForegroundOpacity); 429cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt( 430205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, merged); 431cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mBackgroundColor == preference || mBackgroundOpacity == preference) { 432205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette final int merged = mergeColorOpacity(mBackgroundColor, mBackgroundOpacity); 433cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt( 434205cee4c1c0d0088c3a8e16093a28fa8f680d7faAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, merged); 435d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette } else if (mWindowColor == preference || mWindowOpacity == preference) { 436d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette final int merged = mergeColorOpacity(mWindowColor, mWindowOpacity); 437d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette Settings.Secure.putInt( 438d07c16107d7cda495a8a2655cdcb0ad552d25a84Alan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, merged); 439cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mEdgeColor == preference) { 440cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, value); 441cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mPreset == preference) { 442cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_PRESET, value); 443660223ff430022aeabc7fb5947d1e1a5116f57d7Alan Viverette refreshShowingCustom(); 444cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mEdgeType == preference) { 445cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, value); 446cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 447cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 448cc0e782871eb6b946ded880e391866f27953654bAlan Viverette refreshPreviewText(); 449cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 450cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 451cc0e782871eb6b946ded880e391866f27953654bAlan Viverette @Override 452cc0e782871eb6b946ded880e391866f27953654bAlan Viverette public boolean onPreferenceChange(Preference preference, Object value) { 453cc0e782871eb6b946ded880e391866f27953654bAlan Viverette final ContentResolver cr = getActivity().getContentResolver(); 454cc0e782871eb6b946ded880e391866f27953654bAlan Viverette if (mTypeface == preference) { 455cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putString( 456cc0e782871eb6b946ded880e391866f27953654bAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE, (String) value); 457cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mFontSize == preference) { 458cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putFloat( 4595ea751e48fc3d7c25cf4e44ef5926e8e70979b5aAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE, 460cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Float.parseFloat((String) value)); 461cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } else if (mLocale == preference) { 462cc0e782871eb6b946ded880e391866f27953654bAlan Viverette Settings.Secure.putString( 463cc0e782871eb6b946ded880e391866f27953654bAlan Viverette cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_LOCALE, (String) value); 464cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 465cc0e782871eb6b946ded880e391866f27953654bAlan Viverette 466cc0e782871eb6b946ded880e391866f27953654bAlan Viverette refreshPreviewText(); 467cc0e782871eb6b946ded880e391866f27953654bAlan Viverette return true; 468cc0e782871eb6b946ded880e391866f27953654bAlan Viverette } 469cc0e782871eb6b946ded880e391866f27953654bAlan Viverette} 470