165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/* 265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project 365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License"); 565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License. 665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at 765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * http://www.apache.org/licenses/LICENSE-2.0 965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * 1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software 1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS, 1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and 1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License. 1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.system; 1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R; 2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Fragment; 2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Activity; 2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle; 2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.internal.widget.SubtitleView; 2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.accessibility.CaptioningManager; 2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.accessibility.CaptioningManager.CaptionStyle; 2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.ViewGroup; 3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.View; 3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.LayoutInflater; 3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.Context; 3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.res.Resources; 3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.content.res.Configuration; 3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.graphics.Typeface; 3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.util.Log; 3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport java.util.Locale; 4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.text.TextUtils; 4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/** 4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Fragment that shows caption preview image with text overlay. 4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */ 4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class CaptionPreviewFragment extends Fragment { 4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final String TAG = "CaptionPreviewFragment"; 4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private static final boolean DEBUG = false; 5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mDefaultFontSize; 5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private SubtitleView mPreviewText; 5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private View mPreviewWindow; 5565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private CaptioningManager mCaptioningManager; 5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private CaptioningManager.CaptioningChangeListener mCaptionChangeListener; 5765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 5865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private float mFontScale; 5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mStyleId; 6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mTextColor; 6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mBackgroundColor; 6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private int mWindowColor; 6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private Locale mLocale; 6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private boolean mShowingLivePreview; 6565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 6665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public static CaptionPreviewFragment newInstance() { 6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane CaptionPreviewFragment fragment = new CaptionPreviewFragment(); 6865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return fragment; 6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onCreate(Bundle savedInstanceState) { 7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onCreate"); 7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onCreate(savedInstanceState); 7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCaptioningManager = (CaptioningManager) getActivity() 7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getSystemService(Context.CAPTIONING_SERVICE); 7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCaptionChangeListener = 8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane new CaptioningManager.CaptioningChangeListener() { 8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onEnabledChanged(boolean enabled) { 8465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onEnableChanged"); 8565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 8665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 8765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 8865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 8965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onUserStyleChanged(CaptionStyle userStyle) { 9065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onUserStyleChanged"); 9165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadCaptionSettings(); 9265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 9465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 9565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 9665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onLocaleChanged(Locale locale) { 9765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onLocaleChanged"); 9865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadCaptionSettings(); 9965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 10065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 10265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 10365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onFontScaleChanged(float fontScale) { 10465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onFontScaleChanged " + fontScale); 10565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadCaptionSettings(); 10665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 10765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 10865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane }; 10965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mDefaultFontSize = 11165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane getResources().getInteger(R.integer.captioning_preview_default_font_size); 11265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadCaptionSettings(); 11365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 11465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 11565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 11665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onStart() { 11765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onStart(); 11865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCaptioningManager.addCaptioningChangeListener (mCaptionChangeListener); 11965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 12265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onStop() { 12365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mCaptioningManager.removeCaptioningChangeListener (mCaptionChangeListener); 12465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onStop(); 12565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 12665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 12765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane private void loadCaptionSettings() { 12865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mFontScale = mCaptioningManager.getFontScale(); 12965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mStyleId = mCaptioningManager.getRawUserStyle(); 13065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLocale = mCaptioningManager.getLocale(); 13165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane CaptioningManager.CaptionStyle cs = mCaptioningManager.getUserStyle(); 13365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mTextColor = cs.foregroundColor; 13465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mBackgroundColor = cs.backgroundColor; 13565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mWindowColor = cs.windowColor; 13665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 13765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = false; 13865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 13965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 14165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public View onCreateView( 14265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 14365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onCreateView"); 14465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final View rootView = inflater.inflate(R.layout.captioning_preview, container, false); 14565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return rootView; 14665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 14765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 14865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane @Override 14965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void onViewCreated(View view, Bundle savedInstanceState) { 15065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "onViewCreated"); 15165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane super.onViewCreated(view, savedInstanceState); 15265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); 15365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow = view.findViewById(R.id.preview_window); 15465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 15565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 15665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 15765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane static CharSequence getTextForLocale(Context context, Locale locale, int resId) { 15865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final Resources res = context.getResources(); 15965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final Configuration config = res.getConfiguration(); 16065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final Locale prevLocale = config.locale; 16165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane try { 16265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane config.locale = locale; 16365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane res.updateConfiguration(config, null); 16465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane return res.getText(resId); 16565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } finally { 16665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane config.locale = prevLocale; 16765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane res.updateConfiguration(config, null); 16865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 16965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 17065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 17165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewLanguage(String language) { 17265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLocale = null; 17365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (!TextUtils.isEmpty(language)) { 17465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final String[] splitLocale = language.split("_"); 17565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane switch (splitLocale.length) { 17665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case 3: 17765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLocale = new Locale(splitLocale[0], splitLocale[1], splitLocale[2]); 17865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 17965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case 2: 18065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLocale = new Locale(splitLocale[0], splitLocale[1]); 18165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 18265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane case 1: 18365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mLocale = new Locale(splitLocale[0]); 18465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane break; 18565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 18765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 18865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 18965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 19165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewFontScale(float fontScale) { 19265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mFontScale = fontScale; 19365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 19465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 19565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 19665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 19765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewCaptionStyle(int styleId) { 19865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mStyleId = styleId; 19965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 20065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 20165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewFontFamily(String fontFamily) { 20465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Typeface typeface = Typeface.create (fontFamily, Typeface.NORMAL); 20565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setTypeface(typeface); 20665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 20765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 20865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 20965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewTextColor(int textColor) { 21065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = mTextColor & 0xff000000 | textColor & 0xffffff; 21165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setForegroundColor(color); 21265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 21365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 21465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 21565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewTextOpacity(String textOpacity) { 21665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int opacity = Integer.parseInt(textOpacity); 21765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = mTextColor & 0xffffff | opacity & 0xff000000; 21865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setForegroundColor(color); 21965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 22065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewBackgroundColor(int bgColor) { 22365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = mBackgroundColor & 0xff000000 | bgColor & 0xffffff; 22465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setBackgroundColor(color); 22565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 22665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 22765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 22865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewBackgroundOpacity(String bgOpacity) { 22965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int opacity = Integer.parseInt(bgOpacity); 23065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = mBackgroundColor & 0xffffff | opacity & 0xff000000; 23165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setBackgroundColor(color); 23265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 23365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 23465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 23565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewEdgeColor(int edgeColor) { 23665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane edgeColor |= 0xff000000; 23765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setEdgeColor(edgeColor); 23865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 23965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewEdgeType(int edgeType) { 24265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setEdgeType(edgeType); 24365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 24465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 24565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 24665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewWindowColorNone() { 24765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final CaptionStyle defStyle = CaptionStyle.DEFAULT; 24865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow.setBackgroundColor(defStyle.windowColor); 24965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 25065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 25165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewWindowColor(int windowColor) { 25265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int opacity = mWindowColor & 0xff000000; 25365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (opacity == 0) 25465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane opacity = 0xff000000; 25565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = opacity | windowColor & 0xffffff; 25665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow.setBackgroundColor(color); 25765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 25865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 25965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 26065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void livePreviewWindowOpacity(String windowOpacity) { 26165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int opacity = Integer.parseInt(windowOpacity); 26265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane int color = mWindowColor & 0xffffff | opacity & 0xff000000; 26365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow.setBackgroundColor(color); 26465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mShowingLivePreview = true; 26565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 26665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 26765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void resetLivePreview() { 26865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mShowingLivePreview) { 26965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane loadCaptionSettings(); 27065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane refreshPreviewText(); 27165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 27365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 27465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane public void refreshPreviewText() { 27565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if(DEBUG) Log.d(TAG, "refreshPreviewText"); 27665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mPreviewText != null) { 27765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane boolean enabled = mCaptioningManager.isEnabled(); 27865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (enabled) { 27965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setVisibility(View.VISIBLE); 28065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane Activity activity = getActivity(); 28165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setStyle(mStyleId); 28265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setTextSize(mFontScale * mDefaultFontSize); 28365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (mLocale != null) { 28465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane CharSequence localizedText = getTextForLocale( 28565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane activity, mLocale, R.string.captioning_preview_text); 28665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setText(localizedText); 28765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 28865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setText(getResources() 28965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane .getString(R.string.captioning_preview_text)); 29065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 29265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final CaptionStyle style = mCaptioningManager.getUserStyle(); 29365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane if (style.hasWindowColor()) { 29465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow.setBackgroundColor(mWindowColor); 29565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 29665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane final CaptionStyle defStyle = CaptionStyle.DEFAULT; 29765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewWindow.setBackgroundColor(defStyle.windowColor); 29865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 29965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane 30065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.invalidate(); 30165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } else { 30265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane mPreviewText.setVisibility(View.INVISIBLE); 30365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane } 30665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane} 307