diff options
| author | Alan Viverette <alanv@google.com> | 2014-06-04 18:35:42 -0700 |
|---|---|---|
| committer | Alan Viverette <alanv@google.com> | 2014-06-04 18:35:42 -0700 |
| commit | e88aee8ad85b01229b12dbc0c3cc2f0b8b490192 (patch) | |
| tree | ea03bb3ae8e88df6b776b8dd0411a187e4a8fcb7 /core/java/android/view/accessibility | |
| parent | 648a309d9badc405bc969bcb4461369bf89fe7ef (diff) | |
| download | frameworks_base-e88aee8ad85b01229b12dbc0c3cc2f0b8b490192.zip frameworks_base-e88aee8ad85b01229b12dbc0c3cc2f0b8b490192.tar.gz frameworks_base-e88aee8ad85b01229b12dbc0c3cc2f0b8b490192.tar.bz2 | |
Add defaults for caption colors and edge type
BUG: 8151470
Change-Id: I4d7b75bf647aeded77b4000cdcd37e9ace46a374
Diffstat (limited to 'core/java/android/view/accessibility')
| -rw-r--r-- | core/java/android/view/accessibility/CaptioningManager.java | 116 |
1 files changed, 104 insertions, 12 deletions
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 @@ public class CaptioningManager { * language * @hide */ + @Nullable public final String getRawLocale() { return Secure.getString(mContentResolver, Secure.ACCESSIBILITY_CAPTIONING_LOCALE); } @@ -86,6 +89,7 @@ public class CaptioningManager { * @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 @@ public class CaptioningManager { * @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 @@ public class CaptioningManager { * * @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 @@ public class CaptioningManager { * * @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 @@ public class CaptioningManager { /** 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 @@ public class CaptioningManager { /** @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 @@ public class CaptioningManager { /** * 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 @@ public class CaptioningManager { } /** + * 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 @@ public class CaptioningManager { /** * @hide */ + @NonNull public static CaptionStyle getCustomStyle(ContentResolver cr) { final CaptionStyle defStyle = CaptionStyle.DEFAULT_CUSTOM; final int foregroundColor = Secure.getInt( @@ -370,12 +461,17 @@ public class CaptioningManager { 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 @@ public class CaptioningManager { * * @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 @@ public class CaptioningManager { * @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 @@ public class CaptioningManager { * @param fontScale the preferred font scaling factor * @see CaptioningManager#getFontScale() */ - public void onFontScaleChanged(float fontScale) { - } + public void onFontScaleChanged(float fontScale) {} } } |
