Merge "Add defaults for caption colors and edge type" into lmp-preview-dev
diff --git a/api/current.txt b/api/current.txt
index af39259..9b9f4ad 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -33797,11 +33797,17 @@
public static final class CaptioningManager.CaptionStyle {
method public android.graphics.Typeface getTypeface();
+ method public boolean hasBackgroundColor();
+ method public boolean hasEdgeColor();
+ method public boolean hasEdgeType();
+ method public boolean hasForegroundColor();
+ method public boolean hasWindowColor();
field public static final int EDGE_TYPE_DEPRESSED = 4; // 0x4
field public static final int EDGE_TYPE_DROP_SHADOW = 2; // 0x2
field public static final int EDGE_TYPE_NONE = 0; // 0x0
field public static final int EDGE_TYPE_OUTLINE = 1; // 0x1
field public static final int EDGE_TYPE_RAISED = 3; // 0x3
+ field public static final int EDGE_TYPE_UNSPECIFIED = -1; // 0xffffffff
field public final int backgroundColor;
field public final int edgeColor;
field public final int edgeType;
diff --git a/core/java/android/view/accessibility/CaptioningManager.java b/core/java/android/view/accessibility/CaptioningManager.java
index a0134d6..334ff43 100644
--- a/core/java/android/view/accessibility/CaptioningManager.java
+++ b/core/java/android/view/accessibility/CaptioningManager.java
@@ -16,6 +16,8 @@
package android.view.accessibility;
+import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
@@ -78,6 +80,7 @@
* language
* @hide
*/
+ @Nullable
public final String getRawLocale() {
return Secure.getString(mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
}
@@ -86,6 +89,7 @@
* @return the locale for the user's preferred captioning language, or null
* if not specified
*/
+ @Nullable
public final Locale getLocale() {
final String rawLocale = getRawLocale();
if (!TextUtils.isEmpty(rawLocale)) {
@@ -125,6 +129,7 @@
* @return the user's preferred visual properties for captions as a
* {@link CaptionStyle}, or the default style if not specified
*/
+ @NonNull
public CaptionStyle getUserStyle() {
final int preset = getRawUserStyle();
if (preset == CaptionStyle.PRESET_CUSTOM) {
@@ -140,17 +145,19 @@
*
* @param listener the listener to add
*/
- public void addCaptioningChangeListener(CaptioningChangeListener listener) {
+ public void addCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
synchronized (mListeners) {
if (mListeners.isEmpty()) {
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_ENABLED);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR);
+ registerObserver(Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_FONT_SCALE);
registerObserver(Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
+ registerObserver(Secure.ACCESSIBILITY_CAPTIONING_PRESET);
}
mListeners.add(listener);
@@ -167,7 +174,7 @@
*
* @param listener the listener to remove
*/
- public void removeCaptioningChangeListener(CaptioningChangeListener listener) {
+ public void removeCaptioningChangeListener(@NonNull CaptioningChangeListener listener) {
synchronized (mListeners) {
mListeners.remove(listener);
@@ -253,11 +260,18 @@
/** Packed value for a color of 'none' and a cached opacity of 100%. */
private static final int COLOR_NONE_OPAQUE = 0x000000FF;
+ /** Packed value for an unspecified color and opacity. */
+ private static final int COLOR_UNSPECIFIED = 0x000001FF;
+
private static final CaptionStyle WHITE_ON_BLACK;
private static final CaptionStyle BLACK_ON_WHITE;
private static final CaptionStyle YELLOW_ON_BLACK;
private static final CaptionStyle YELLOW_ON_BLUE;
private static final CaptionStyle DEFAULT_CUSTOM;
+ private static final CaptionStyle UNSPECIFIED;
+
+ /** The default caption style used to fill in unspecified values. @hide */
+ public static final CaptionStyle DEFAULT;
/** @hide */
public static final CaptionStyle[] PRESETS;
@@ -265,6 +279,9 @@
/** @hide */
public static final int PRESET_CUSTOM = -1;
+ /** Unspecified edge type value. */
+ public static final int EDGE_TYPE_UNSPECIFIED = -1;
+
/** Edge type value specifying no character edges. */
public static final int EDGE_TYPE_NONE = 0;
@@ -289,6 +306,7 @@
/**
* The preferred edge type for video captions, one of:
* <ul>
+ * <li>{@link #EDGE_TYPE_UNSPECIFIED}
* <li>{@link #EDGE_TYPE_NONE}
* <li>{@link #EDGE_TYPE_OUTLINE}
* <li>{@link #EDGE_TYPE_DROP_SHADOW}
@@ -326,9 +344,81 @@
}
/**
+ * Applies a caption style, overriding any properties that are specified
+ * in the overlay caption.
+ *
+ * @param overlay The style to apply
+ * @return A caption style with the overlay style applied
+ * @hide
+ */
+ @NonNull
+ public CaptionStyle applyStyle(@NonNull CaptionStyle overlay) {
+ final int newForegroundColor = overlay.hasForegroundColor() ?
+ overlay.foregroundColor : foregroundColor;
+ final int newBackgroundColor = overlay.hasBackgroundColor() ?
+ overlay.backgroundColor : backgroundColor;
+ final int newEdgeType = overlay.hasEdgeType() ?
+ overlay.edgeType : edgeType;
+ final int newEdgeColor = overlay.hasEdgeColor() ?
+ overlay.edgeColor : edgeColor;
+ final int newWindowColor = overlay.hasWindowColor() ?
+ overlay.windowColor : windowColor;
+ final String newRawTypeface = overlay.mRawTypeface != null ?
+ overlay.mRawTypeface : mRawTypeface;
+ return new CaptionStyle(newForegroundColor, newBackgroundColor, newEdgeType,
+ newEdgeColor, newWindowColor, newRawTypeface);
+ }
+
+ /**
+ * @return {@code true} if the user has specified a background color
+ * that should override the application default, {@code false}
+ * otherwise
+ */
+ public boolean hasBackgroundColor() {
+ return backgroundColor != COLOR_UNSPECIFIED;
+ }
+
+ /**
+ * @return {@code true} if the user has specified a foreground color
+ * that should override the application default, {@code false}
+ * otherwise
+ */
+ public boolean hasForegroundColor() {
+ return foregroundColor != COLOR_UNSPECIFIED;
+ }
+
+ /**
+ * @return {@code true} if the user has specified an edge type that
+ * should override the application default, {@code false}
+ * otherwise
+ */
+ public boolean hasEdgeType() {
+ return edgeType != EDGE_TYPE_UNSPECIFIED;
+ }
+
+ /**
+ * @return {@code true} if the user has specified an edge color that
+ * should override the application default, {@code false}
+ * otherwise
+ */
+ public boolean hasEdgeColor() {
+ return edgeColor != COLOR_UNSPECIFIED;
+ }
+
+ /**
+ * @return {@code true} if the user has specified a window color that
+ * should override the application default, {@code false}
+ * otherwise
+ */
+ public boolean hasWindowColor() {
+ return windowColor != COLOR_UNSPECIFIED;
+ }
+
+ /**
* @return the preferred {@link Typeface} for video captions, or null if
* not specified
*/
+ @Nullable
public Typeface getTypeface() {
if (mParsedTypeface == null && !TextUtils.isEmpty(mRawTypeface)) {
mParsedTypeface = Typeface.create(mRawTypeface, Typeface.NORMAL);
@@ -339,6 +429,7 @@
/**
* @hide
*/
+ @NonNull
public static CaptionStyle getCustomStyle(ContentResolver cr) {
final CaptionStyle defStyle = CaptionStyle.DEFAULT_CUSTOM;
final int foregroundColor = Secure.getInt(
@@ -370,12 +461,17 @@
Color.BLACK, COLOR_NONE_OPAQUE, null);
YELLOW_ON_BLUE = new CaptionStyle(Color.YELLOW, Color.BLUE, EDGE_TYPE_NONE,
Color.BLACK, COLOR_NONE_OPAQUE, null);
+ UNSPECIFIED = new CaptionStyle(COLOR_UNSPECIFIED, COLOR_UNSPECIFIED,
+ EDGE_TYPE_UNSPECIFIED, COLOR_UNSPECIFIED, COLOR_UNSPECIFIED, null);
+ // The ordering of these cannot change since we store the index
+ // directly in preferences.
PRESETS = new CaptionStyle[] {
- WHITE_ON_BLACK, BLACK_ON_WHITE, YELLOW_ON_BLACK, YELLOW_ON_BLUE
+ WHITE_ON_BLACK, BLACK_ON_WHITE, YELLOW_ON_BLACK, YELLOW_ON_BLUE, UNSPECIFIED
};
DEFAULT_CUSTOM = WHITE_ON_BLACK;
+ DEFAULT = WHITE_ON_BLACK;
}
}
@@ -389,8 +485,7 @@
*
* @param enabled the user's new preferred captioning enabled state
*/
- public void onEnabledChanged(boolean enabled) {
- }
+ public void onEnabledChanged(boolean enabled) {}
/**
* Called when the captioning user style changes.
@@ -398,17 +493,15 @@
* @param userStyle the user's new preferred style
* @see CaptioningManager#getUserStyle()
*/
- public void onUserStyleChanged(CaptionStyle userStyle) {
- }
+ public void onUserStyleChanged(@NonNull CaptionStyle userStyle) {}
/**
* Called when the captioning locale changes.
*
- * @param locale the preferred captioning locale
+ * @param locale the preferred captioning locale, or {@code null} if not specified
* @see CaptioningManager#getLocale()
*/
- public void onLocaleChanged(Locale locale) {
- }
+ public void onLocaleChanged(@Nullable Locale locale) {}
/**
* Called when the captioning font scaling factor changes.
@@ -416,7 +509,6 @@
* @param fontScale the preferred font scaling factor
* @see CaptioningManager#getFontScale()
*/
- public void onFontScaleChanged(float fontScale) {
- }
+ public void onFontScaleChanged(float fontScale) {}
}
}
diff --git a/core/java/com/android/internal/widget/SubtitleView.java b/core/java/com/android/internal/widget/SubtitleView.java
index 117463a..2f987e9 100644
--- a/core/java/com/android/internal/widget/SubtitleView.java
+++ b/core/java/com/android/internal/widget/SubtitleView.java
@@ -271,10 +271,13 @@
style = CaptionStyle.PRESETS[styleId];
}
- mForegroundColor = style.foregroundColor;
- mBackgroundColor = style.backgroundColor;
- mEdgeType = style.edgeType;
- mEdgeColor = style.edgeColor;
+ final CaptionStyle defStyle = CaptionStyle.DEFAULT;
+ mForegroundColor = style.hasForegroundColor() ?
+ style.foregroundColor : defStyle.foregroundColor;
+ mBackgroundColor = style.hasBackgroundColor() ?
+ style.backgroundColor : defStyle.backgroundColor;
+ mEdgeType = style.hasEdgeType() ? style.edgeType : defStyle.edgeType;
+ mEdgeColor = style.hasEdgeColor() ? style.edgeColor : defStyle.edgeColor;
mHasMeasurements = false;
final Typeface typeface = style.getTypeface();
diff --git a/media/java/android/media/WebVttRenderer.java b/media/java/android/media/WebVttRenderer.java
index 1c9730f..7977988 100644
--- a/media/java/android/media/WebVttRenderer.java
+++ b/media/java/android/media/WebVttRenderer.java
@@ -1103,6 +1103,9 @@
*/
class WebVttRenderingWidget extends ViewGroup implements SubtitleTrack.RenderingWidget {
private static final boolean DEBUG = false;
+
+ private static final CaptionStyle DEFAULT_CAPTION_STYLE = CaptionStyle.DEFAULT;
+
private static final int DEBUG_REGION_BACKGROUND = 0x800000FF;
private static final int DEBUG_CUE_BACKGROUND = 0x80FF0000;
@@ -1144,7 +1147,8 @@
this(context, attrs, defStyleAttr, 0);
}
- public WebVttRenderingWidget(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ public WebVttRenderingWidget(
+ Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
// Cannot render text over video when layer type is hardware.
@@ -1259,6 +1263,7 @@
}
private void setCaptionStyle(CaptionStyle captionStyle, float fontSize) {
+ captionStyle = DEFAULT_CAPTION_STYLE.applyStyle(captionStyle);
mCaptionStyle = captionStyle;
mFontSize = fontSize;