Add defaults for caption colors and edge type, fix preview size
BUG: 15116066 BUG: 8151470 Change-Id: Ieca00f0da209138bdfa691715720263ef5406773
This commit is contained in:
@@ -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" >
|
||||
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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>
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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);
|
||||
|
Reference in New Issue
Block a user