Add preference for caption text opacity

BUG: 11990225
Change-Id: Ib7dd92fd3e44931a1a4a2603effb02550b4fbc59
This commit is contained in:
Alan Viverette
2013-12-05 11:27:40 -08:00
parent 3858233f89
commit 205cee4c1c
3 changed files with 71 additions and 38 deletions

View File

@@ -3377,6 +3377,8 @@
<string name="captioning_background_opacity">Background opacity</string> <string name="captioning_background_opacity">Background opacity</string>
<!-- Title for the preference to change video caption text color. [CHAR LIMIT=35] --> <!-- Title for the preference to change video caption text color. [CHAR LIMIT=35] -->
<string name="captioning_foreground_color">Text color</string> <string name="captioning_foreground_color">Text color</string>
<!-- Title for the preference to change video caption text opacity. [CHAR LIMIT=35] -->
<string name="captioning_foreground_opacity">Text opacity</string>
<!-- Title for the preference to change video caption edge color. [CHAR LIMIT=35] --> <!-- Title for the preference to change video caption edge color. [CHAR LIMIT=35] -->
<string name="captioning_edge_color">Edge color</string> <string name="captioning_edge_color">Edge color</string>
<!-- Title for the preference to change video caption edge type. [CHAR LIMIT=35] --> <!-- Title for the preference to change video caption edge type. [CHAR LIMIT=35] -->

View File

@@ -58,6 +58,10 @@
android:key="captioning_foreground_color" android:key="captioning_foreground_color"
android:persistent="false" android:persistent="false"
android:title="@string/captioning_foreground_color" /> android:title="@string/captioning_foreground_color" />
<com.android.settings.accessibility.ColorPreference
android:key="captioning_foreground_opacity"
android:persistent="false"
android:title="@string/captioning_foreground_opacity" />
<com.android.settings.accessibility.EdgeTypePreference <com.android.settings.accessibility.EdgeTypePreference
android:key="captioning_edge_type" android:key="captioning_edge_type"

View File

@@ -50,6 +50,18 @@ import java.util.Locale;
*/ */
public class CaptionPropertiesFragment extends SettingsPreferenceFragment public class CaptionPropertiesFragment extends SettingsPreferenceFragment
implements OnPreferenceChangeListener, OnValueChangedListener { implements OnPreferenceChangeListener, OnValueChangedListener {
private static final String PREF_BACKGROUND_COLOR = "captioning_background_color";
private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity";
private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color";
private static final String PREF_FOREGROUND_OPACITY = "captioning_foreground_opacity";
private static final String PREF_EDGE_COLOR = "captioning_edge_color";
private static final String PREF_EDGE_TYPE = "captioning_edge_type";
private static final String PREF_FONT_SIZE = "captioning_font_size";
private static final String PREF_TYPEFACE = "captioning_typeface";
private static final String PREF_LOCALE = "captioning_locale";
private static final String PREF_PRESET = "captioning_preset";
private static final String PREF_CUSTOM = "custom";
private static final float DEFAULT_FONT_SIZE = 48f; private static final float DEFAULT_FONT_SIZE = 48f;
private CaptioningManager mCaptioningManager; private CaptioningManager mCaptioningManager;
@@ -63,6 +75,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
// Custom options. // Custom options.
private ListPreference mTypeface; private ListPreference mTypeface;
private ColorPreference mForegroundColor; private ColorPreference mForegroundColor;
private ColorPreference mForegroundOpacity;
private EdgeTypePreference mEdgeType; private EdgeTypePreference mEdgeType;
private ColorPreference mEdgeColor; private ColorPreference mEdgeColor;
private ColorPreference mBackgroundColor; private ColorPreference mBackgroundColor;
@@ -188,25 +201,33 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
} }
private void initializeAllPreferences() { private void initializeAllPreferences() {
mLocale = (LocalePreference) findPreference("captioning_locale"); mLocale = (LocalePreference) findPreference(PREF_LOCALE);
mFontSize = (ListPreference) findPreference("captioning_font_size"); mFontSize = (ListPreference) findPreference(PREF_FONT_SIZE);
final Resources res = getResources(); final Resources res = getResources();
final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values); final int[] presetValues = res.getIntArray(R.array.captioning_preset_selector_values);
final String[] presetTitles = res.getStringArray(R.array.captioning_preset_selector_titles); final String[] presetTitles = res.getStringArray(R.array.captioning_preset_selector_titles);
mPreset = (PresetPreference) findPreference("captioning_preset"); mPreset = (PresetPreference) findPreference(PREF_PRESET);
mPreset.setValues(presetValues); mPreset.setValues(presetValues);
mPreset.setTitles(presetTitles); mPreset.setTitles(presetTitles);
mCustom = (PreferenceCategory) findPreference("custom"); mCustom = (PreferenceCategory) findPreference(PREF_CUSTOM);
mShowingCustom = true; mShowingCustom = true;
final int[] colorValues = res.getIntArray(R.array.captioning_color_selector_values); final int[] colorValues = res.getIntArray(R.array.captioning_color_selector_values);
final String[] colorTitles = res.getStringArray(R.array.captioning_color_selector_titles); final String[] colorTitles = res.getStringArray(R.array.captioning_color_selector_titles);
mForegroundColor = (ColorPreference) mCustom.findPreference("captioning_foreground_color"); mForegroundColor = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_COLOR);
mForegroundColor.setTitles(colorTitles); mForegroundColor.setTitles(colorTitles);
mForegroundColor.setValues(colorValues); mForegroundColor.setValues(colorValues);
mEdgeColor = (ColorPreference) mCustom.findPreference("captioning_edge_color");
final int[] opacityValues = res.getIntArray(R.array.captioning_opacity_selector_values);
final String[] opacityTitles = res.getStringArray(
R.array.captioning_opacity_selector_titles);
mForegroundOpacity = (ColorPreference) mCustom.findPreference(PREF_FOREGROUND_OPACITY);
mForegroundOpacity.setTitles(opacityTitles);
mForegroundOpacity.setValues(opacityValues);
mEdgeColor = (ColorPreference) mCustom.findPreference(PREF_EDGE_COLOR);
mEdgeColor.setTitles(colorTitles); mEdgeColor.setTitles(colorTitles);
mEdgeColor.setValues(colorValues); mEdgeColor.setValues(colorValues);
@@ -217,25 +238,22 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
System.arraycopy(colorTitles, 0, bgColorTitles, 1, colorTitles.length); System.arraycopy(colorTitles, 0, bgColorTitles, 1, colorTitles.length);
bgColorValues[0] = Color.TRANSPARENT; bgColorValues[0] = Color.TRANSPARENT;
bgColorTitles[0] = getString(R.string.color_none); bgColorTitles[0] = getString(R.string.color_none);
mBackgroundColor = (ColorPreference) mCustom.findPreference("captioning_background_color"); mBackgroundColor = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_COLOR);
mBackgroundColor.setTitles(bgColorTitles); mBackgroundColor.setTitles(bgColorTitles);
mBackgroundColor.setValues(bgColorValues); mBackgroundColor.setValues(bgColorValues);
final int[] opacityValues = res.getIntArray(R.array.captioning_opacity_selector_values); mBackgroundOpacity = (ColorPreference) mCustom.findPreference(PREF_BACKGROUND_OPACITY);
final String[] opacityTitles = res.getStringArray(
R.array.captioning_opacity_selector_titles);
mBackgroundOpacity = (ColorPreference) mCustom.findPreference(
"captioning_background_opacity");
mBackgroundOpacity.setTitles(opacityTitles); mBackgroundOpacity.setTitles(opacityTitles);
mBackgroundOpacity.setValues(opacityValues); mBackgroundOpacity.setValues(opacityValues);
mEdgeType = (EdgeTypePreference) mCustom.findPreference("captioning_edge_type"); mEdgeType = (EdgeTypePreference) mCustom.findPreference(PREF_EDGE_TYPE);
mTypeface = (ListPreference) mCustom.findPreference("captioning_typeface"); mTypeface = (ListPreference) mCustom.findPreference(PREF_TYPEFACE);
} }
private void installUpdateListeners() { private void installUpdateListeners() {
mPreset.setOnValueChangedListener(this); mPreset.setOnValueChangedListener(this);
mForegroundColor.setOnValueChangedListener(this); mForegroundColor.setOnValueChangedListener(this);
mForegroundOpacity.setOnValueChangedListener(this);
mEdgeColor.setOnValueChangedListener(this); mEdgeColor.setOnValueChangedListener(this);
mBackgroundColor.setOnValueChangedListener(this); mBackgroundColor.setOnValueChangedListener(this);
mBackgroundOpacity.setOnValueChangedListener(this); mBackgroundOpacity.setOnValueChangedListener(this);
@@ -255,22 +273,11 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
final ContentResolver cr = getContentResolver(); final ContentResolver cr = getContentResolver();
final CaptionStyle attrs = CaptionStyle.getCustomStyle(cr); final CaptionStyle attrs = CaptionStyle.getCustomStyle(cr);
mForegroundColor.setValue(attrs.foregroundColor);
mEdgeType.setValue(attrs.edgeType); mEdgeType.setValue(attrs.edgeType);
mEdgeColor.setValue(attrs.edgeColor); mEdgeColor.setValue(attrs.edgeColor);
final int backgroundColor = attrs.backgroundColor; parseColorOpacity(mForegroundColor, mForegroundOpacity, attrs.foregroundColor);
final int bgColor; parseColorOpacity(mBackgroundColor, mBackgroundOpacity, attrs.backgroundColor);
final int bgAlpha;
if (Color.alpha(backgroundColor) == 0) {
bgColor = Color.TRANSPARENT;
bgAlpha = (backgroundColor & 0xFF) << 24;
} else {
bgColor = backgroundColor | 0xFF000000;
bgAlpha = backgroundColor & 0xFF000000;
}
mBackgroundColor.setValue(bgColor);
mBackgroundOpacity.setValue(bgAlpha | 0xFFFFFF);
final String rawTypeface = attrs.mRawTypeface; final String rawTypeface = attrs.mRawTypeface;
mTypeface.setValue(rawTypeface == null ? "" : rawTypeface); mTypeface.setValue(rawTypeface == null ? "" : rawTypeface);
@@ -279,6 +286,32 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
mLocale.setValue(rawLocale == null ? "" : rawLocale); mLocale.setValue(rawLocale == null ? "" : rawLocale);
} }
private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) {
final int colorValue;
final int opacityValue;
if (Color.alpha(value) == 0) {
colorValue = Color.TRANSPARENT;
opacityValue = (value & 0xFF) << 24;
} else {
colorValue = value | 0xFF000000;
opacityValue = value & 0xFF000000;
}
color.setValue(colorValue);
opacity.setValue(opacityValue | 0xFFFFFF);
}
private int mergeColorOpacity(ColorPreference color, ColorPreference opacity) {
final int colorValue = color.getValue();
final int opacityValue = opacity.getValue();
final int value;
if (Color.alpha(colorValue) == 0) {
value = Color.alpha(opacityValue);
} else {
value = colorValue & 0x00FFFFFF | opacityValue & 0xFF000000;
}
return value;
}
private void refreshShowingCustom() { private void refreshShowingCustom() {
final boolean customPreset = mPreset.getValue() == CaptionStyle.PRESET_CUSTOM; final boolean customPreset = mPreset.getValue() == CaptionStyle.PRESET_CUSTOM;
if (!customPreset && mShowingCustom) { if (!customPreset && mShowingCustom) {
@@ -293,20 +326,14 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment
@Override @Override
public void onValueChanged(ListDialogPreference preference, int value) { public void onValueChanged(ListDialogPreference preference, int value) {
final ContentResolver cr = getActivity().getContentResolver(); final ContentResolver cr = getActivity().getContentResolver();
if (mForegroundColor == preference) { if (mForegroundColor == preference || mForegroundOpacity == preference) {
final int merged = mergeColorOpacity(mForegroundColor, mForegroundOpacity);
Settings.Secure.putInt( Settings.Secure.putInt(
cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, value); cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR, merged);
} else if (mBackgroundColor == preference || mBackgroundOpacity == preference) { } else if (mBackgroundColor == preference || mBackgroundOpacity == preference) {
final int bgColor = mBackgroundColor.getValue(); final int merged = mergeColorOpacity(mBackgroundColor, mBackgroundOpacity);
final int bgAlpha = mBackgroundOpacity.getValue();
final int argb;
if (Color.alpha(bgColor) == 0) {
argb = Color.alpha(bgAlpha);
} else {
argb = bgColor & 0x00FFFFFF | bgAlpha & 0xFF000000;
}
Settings.Secure.putInt( Settings.Secure.putInt(
cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, argb); cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, merged);
} else if (mEdgeColor == preference) { } else if (mEdgeColor == preference) {
Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, value); Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, value);
} else if (mPreset == preference) { } else if (mPreset == preference) {