diff options
author | Alan Viverette <alanv@google.com> | 2014-06-05 13:51:14 -0700 |
---|---|---|
committer | Alan Viverette <alanv@google.com> | 2014-06-05 13:51:58 -0700 |
commit | a83a532dde44341319810958d67aabb02ff7aea6 (patch) | |
tree | a5697e65a2521fa616ba8f67dfeddcbdf582eb75 | |
parent | bf088b5f5d1dc9452ffc57d70c6591aa39371bc5 (diff) | |
download | packages_apps_Settings-a83a532dde44341319810958d67aabb02ff7aea6.zip packages_apps_Settings-a83a532dde44341319810958d67aabb02ff7aea6.tar.gz packages_apps_Settings-a83a532dde44341319810958d67aabb02ff7aea6.tar.bz2 |
Add defaults for caption colors and edge type, fix preview size
BUG: 15116066
BUG: 8151470
Change-Id: Ieca00f0da209138bdfa691715720263ef5406773
-rw-r--r-- | res/layout/captioning_preview.xml | 1 | ||||
-rw-r--r-- | res/values/arrays.xml | 6 | ||||
-rwxr-xr-x | res/values/dimens.xml | 2 | ||||
-rw-r--r-- | res/values/strings.xml | 4 | ||||
-rw-r--r-- | src/com/android/settings/accessibility/CaptionPropertiesFragment.java | 40 | ||||
-rw-r--r-- | src/com/android/settings/accessibility/ColorPreference.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/accessibility/PresetPreference.java | 3 |
7 files changed, 46 insertions, 12 deletions
diff --git a/res/layout/captioning_preview.xml b/res/layout/captioning_preview.xml index 0963ee9..b90c3a5 100644 --- a/res/layout/captioning_preview.xml +++ b/res/layout/captioning_preview.xml @@ -21,6 +21,7 @@ android:orientation="vertical" > <FrameLayout + android:id="@+id/preview_viewport" android:layout_width="match_parent" android:layout_height="@dimen/captioning_preview_height" > diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 508e799..c960c88 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -736,6 +736,7 @@ <!-- Titles for captioning character edge type preference. [CHAR LIMIT=35] --> <string-array name="captioning_edge_type_selector_titles"> + <item>Default</item> <item>None</item> <item>Outline</item> <item>Drop shadow</item> @@ -745,6 +746,7 @@ <!-- Values for captioning character edge type preference. --> <integer-array name="captioning_edge_type_selector_values" translatable="false" > + <item>-1</item> <item>0</item> <item>1</item> <item>2</item> @@ -754,6 +756,7 @@ <!-- Titles for captioning color preference. --> <string-array name="captioning_color_selector_titles" translatable="false" > + <item>@string/color_unspecified</item> <item>@string/color_white</item> <item>@string/color_black</item> <item>@string/color_red</item> @@ -766,6 +769,7 @@ <!-- Values for captioning color preference. --> <integer-array name="captioning_color_selector_values" translatable="false" > + <item>0x00000100</item> <item>0xFFFFFFFF</item> <item>0xFF000000</item> <item>0xFFFF0000</item> @@ -850,6 +854,7 @@ <!-- Titles for captioning text style preset preference. [CHAR LIMIT=35] --> <string-array name="captioning_preset_selector_titles" > + <item>Use app defaults</item> <item>White on black</item> <item>Black on white</item> <item>Yellow on black</item> @@ -859,6 +864,7 @@ <!-- Values for captioning text style preset preference. --> <integer-array name="captioning_preset_selector_values" translatable="false" > + <item>4</item> <item>0</item> <item>1</item> <item>2</item> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 11213bc..fbc6cb3 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -122,4 +122,6 @@ <!-- Search title (recent / results) padding start --> <dimen name="search_title_padding_start">12dp</dimen> + <!-- Default text size for caption preview samples. Uses dp rather than sp because captions are not scaled. --> + <dimen name="caption_preview_text_size">48dp</dimen> </resources> diff --git a/res/values/strings.xml b/res/values/strings.xml index 9685e82..fd25212 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -3369,7 +3369,9 @@ <!-- Label for the default device locale. [CHAR LIMIT=35] --> <string name="locale_default">Default</string> - <!-- Label for no color. [CHAR LIMIT=35] --> + <!-- Label for default color. This lets the app pick the color. [CHAR LIMIT=35] --> + <string name="color_unspecified">Default</string> + <!-- Label for no color (transparent). [CHAR LIMIT=35] --> <string name="color_none">None</string> <!-- Label for the color white. [CHAR LIMIT=35] --> <string name="color_white">White</string> diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java index 5dcf121..41c80ae 100644 --- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java +++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java @@ -29,6 +29,7 @@ import android.preference.Preference.OnPreferenceChangeListener; import android.provider.Settings; import android.view.LayoutInflater; import android.view.View; +import android.view.View.OnLayoutChangeListener; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.view.accessibility.CaptioningManager; @@ -64,11 +65,13 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment private static final String PREF_PRESET = "captioning_preset"; private static final String PREF_CUSTOM = "custom"; - private static final float DEFAULT_FONT_SIZE = 48f; + /** WebVtt specifies line height as 5.3% of the viewport height. */ + private static final float LINE_HEIGHT_RATIO = 0.0533f; private CaptioningManager mCaptioningManager; private SubtitleView mPreviewText; private View mPreviewWindow; + private View mPreviewViewport; private SwitchBar mSwitchBar; private ToggleSwitch mToggleSwitch; @@ -130,13 +133,21 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text); mPreviewText.setVisibility(enabled ? View.VISIBLE : View.INVISIBLE); + mPreviewWindow = view.findViewById(R.id.preview_window); + mPreviewViewport = view.findViewById(R.id.preview_viewport); + mPreviewViewport.addOnLayoutChangeListener(new OnLayoutChangeListener() { + @Override + public void onLayoutChange(View v, int left, int top, int right, int bottom, + int oldLeft, int oldTop, int oldRight, int oldBottom) { + refreshPreviewText(); + } + }); + SettingsActivity activity = (SettingsActivity) getActivity(); mSwitchBar = activity.getSwitchBar(); mToggleSwitch = mSwitchBar.getSwitch(); mToggleSwitch.setCheckedInternal(enabled); - mPreviewWindow = view.findViewById(R.id.preview_window); - getPreferenceScreen().setEnabled(enabled); refreshPreviewText(); @@ -164,7 +175,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment final SubtitleView preview = mPreviewText; if (preview != null) { final int styleId = mCaptioningManager.getRawUserStyle(); - applyCaptionProperties(mCaptioningManager, preview, styleId); + applyCaptionProperties(mCaptioningManager, preview, mPreviewViewport, styleId); final Locale locale = mCaptioningManager.getLocale(); if (locale != null) { @@ -176,18 +187,29 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment } final CaptionStyle style = mCaptioningManager.getUserStyle(); - mPreviewWindow.setBackgroundColor(style.windowColor); + if (style.hasWindowColor()) { + mPreviewWindow.setBackgroundColor(style.windowColor); + } else { + final CaptionStyle defStyle = CaptionStyle.DEFAULT; + mPreviewWindow.setBackgroundColor(defStyle.windowColor); + } } } - public static void applyCaptionProperties( - CaptioningManager manager, SubtitleView previewText, int styleId) { + public static void applyCaptionProperties(CaptioningManager manager, SubtitleView previewText, + View previewWindow, int styleId) { previewText.setStyle(styleId); final Context context = previewText.getContext(); final ContentResolver cr = context.getContentResolver(); final float fontScale = manager.getFontScale(); - previewText.setTextSize(fontScale * DEFAULT_FONT_SIZE); + if (previewWindow != null) { + previewText.setTextSize(previewWindow.getHeight() * LINE_HEIGHT_RATIO * fontScale); + } else { + final float textSize = context.getResources().getDimension( + R.dimen.caption_preview_text_size); + previewText.setTextSize(textSize * fontScale); + } final Locale locale = manager.getLocale(); if (locale != null) { @@ -341,7 +363,7 @@ public class CaptionPropertiesFragment extends SettingsPreferenceFragment final int opacityValue = opacity.getValue(); final int value; if (Color.alpha(colorValue) == 0) { - value = Color.alpha(opacityValue); + value = colorValue & 0x00FFFF00 | Color.alpha(opacityValue); } else { value = colorValue & 0x00FFFFFF | opacityValue & 0xFF000000; } diff --git a/src/com/android/settings/accessibility/ColorPreference.java b/src/com/android/settings/accessibility/ColorPreference.java index f4a5ba7..39e555a 100644 --- a/src/com/android/settings/accessibility/ColorPreference.java +++ b/src/com/android/settings/accessibility/ColorPreference.java @@ -60,7 +60,7 @@ public class ColorPreference extends ListDialogPreference { @Override public boolean shouldDisableDependents() { - return getValue() == Color.TRANSPARENT || super.shouldDisableDependents(); + return Color.alpha(getValue()) == 0 || super.shouldDisableDependents(); } @Override diff --git a/src/com/android/settings/accessibility/PresetPreference.java b/src/com/android/settings/accessibility/PresetPreference.java index 9f1aee3..fe5ca68 100644 --- a/src/com/android/settings/accessibility/PresetPreference.java +++ b/src/com/android/settings/accessibility/PresetPreference.java @@ -49,10 +49,11 @@ public class PresetPreference extends ListDialogPreference { @Override protected void onBindListItem(View view, int index) { + final View previewViewport = view.findViewById(R.id.preview_viewport); final SubtitleView previewText = (SubtitleView) view.findViewById(R.id.preview); final int value = getValueAt(index); CaptionPropertiesFragment.applyCaptionProperties( - mCaptioningManager, previewText, value); + mCaptioningManager, previewText, previewViewport, value); final float density = getContext().getResources().getDisplayMetrics().density; previewText.setTextSize(DEFAULT_FONT_SIZE * density); |