summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Viverette <alanv@google.com>2013-08-05 18:32:20 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-08-05 18:32:20 +0000
commit2191a0c8570b518c8a62e2a7c5e03a5b32ce0aa0 (patch)
tree1c10ae54026822cc065a6180b6049e070bafe1ae
parent78804fc6d8eec112af9857a8513d21fb5134f194 (diff)
parent43a1e3d319d77c251445339bcc8f82c82b097fee (diff)
downloadframeworks_base-2191a0c8570b518c8a62e2a7c5e03a5b32ce0aa0.zip
frameworks_base-2191a0c8570b518c8a62e2a7c5e03a5b32ce0aa0.tar.gz
frameworks_base-2191a0c8570b518c8a62e2a7c5e03a5b32ce0aa0.tar.bz2
Merge "Move caption style to its own class, add presets"
-rw-r--r--api/current.txt18
-rw-r--r--core/java/android/provider/Settings.java21
-rw-r--r--core/java/android/view/accessibility/CaptioningManager.java229
-rw-r--r--core/java/android/view/accessibility/CaptioningPreferences.java246
4 files changed, 258 insertions, 256 deletions
diff --git a/api/current.txt b/api/current.txt
index 7d83fcf..a4cdf85 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -28375,18 +28375,22 @@ package android.view.accessibility {
public class CaptioningPreferences {
ctor public CaptioningPreferences();
- method public static final int getBackgroundColor(android.content.ContentResolver);
- method public static final int getEdgeColor(android.content.ContentResolver);
- method public static final int getEdgeType(android.content.ContentResolver);
method public static final float getFontSize(android.content.ContentResolver);
- method public static final int getForegroundColor(android.content.ContentResolver);
method public static final java.util.Locale getLocale(android.content.ContentResolver);
- method public static final android.graphics.Typeface getTypeface(android.content.ContentResolver);
method public static final boolean isEnabled(android.content.ContentResolver);
field public static final java.lang.String ACTION_CAPTIONING_SETTINGS = "android.settings.CAPTIONING_SETTINGS";
- field public static final int EDGE_TYPE_DROP_SHADOWED = 2; // 0x2
+ }
+
+ public static final class CaptioningPreferences.CaptionStyle {
+ method public static android.view.accessibility.CaptioningPreferences.CaptionStyle defaultUserStyle(android.content.ContentResolver);
+ method public android.graphics.Typeface getTypeface();
+ 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_UNIFORM = 1; // 0x1
+ field public static final int EDGE_TYPE_OUTLINE = 1; // 0x1
+ field public final int backgroundColor;
+ field public final int edgeColor;
+ field public final int edgeType;
+ field public final int foregroundColor;
}
}
diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java
index 1c146b2..5801cd1 100644
--- a/core/java/android/provider/Settings.java
+++ b/core/java/android/provider/Settings.java
@@ -3540,6 +3540,21 @@ public final class Settings {
"accessibility_captioning_locale";
/**
+ * Integer property that specifies the preset style for captions, one
+ * of:
+ * <ul>
+ * <li>{@link android.view.accessibility.CaptioningManager#PRESET_WHITE_ON_BLACK}
+ * <li>{@link android.view.accessibility.CaptioningManager#PRESET_BLACK_ON_WHITE}
+ * <li>{@link android.view.accessibility.CaptioningManager#PRESET_CUSTOM}
+ * </ul>
+ *
+ * @see java.util.Locale#toString
+ * @hide
+ */
+ public static final String ACCESSIBILITY_CAPTIONING_PRESET =
+ "accessibility_captioning_preset";
+
+ /**
* Integer property that specifes the background color for captions as a
* packed 32-bit color.
*
@@ -3562,9 +3577,9 @@ public final class Settings {
/**
* Integer property that specifes the edge type for captions, one of:
* <ul>
- * <li>{@link android.view.accessibility.CaptioningPreferences#EDGE_TYPE_NONE}
- * <li>{@link android.view.accessibility.CaptioningPreferences#EDGE_TYPE_UNIFORM}
- * <li>{@link android.view.accessibility.CaptioningPreferences#EDGE_TYPE_DROP_SHADOWED}
+ * <li>{@link android.view.accessibility.CaptioningManager#EDGE_TYPE_NONE}
+ * <li>{@link android.view.accessibility.CaptioningManager#EDGE_TYPE_OUTLINE}
+ * <li>{@link android.view.accessibility.CaptioningManager#EDGE_TYPE_DROP_SHADOWED}
* </ul>
*
* @see #ACCESSIBILITY_CAPTIONING_EDGE_COLOR
diff --git a/core/java/android/view/accessibility/CaptioningManager.java b/core/java/android/view/accessibility/CaptioningManager.java
new file mode 100644
index 0000000..b1be24c
--- /dev/null
+++ b/core/java/android/view/accessibility/CaptioningManager.java
@@ -0,0 +1,229 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.view.accessibility;
+
+import android.content.ContentResolver;
+import android.graphics.Color;
+import android.graphics.Typeface;
+import android.provider.Settings.Secure;
+import android.text.TextUtils;
+
+import java.util.Locale;
+
+/**
+ * Contains methods for accessing preferred video captioning state and
+ * properties.
+ */
+public class CaptioningManager {
+ /**
+ * Activity Action: Show settings for video captioning.
+ * <p>
+ * In some cases, a matching Activity may not exist, so ensure you safeguard
+ * against this.
+ * <p>
+ * Input: Nothing.
+ * <p>
+ * Output: Nothing.
+ */
+ public static final String ACTION_CAPTIONING_SETTINGS = "android.settings.CAPTIONING_SETTINGS";
+
+ private static final int DEFAULT_PRESET = 0;
+ private static final int DEFAULT_ENABLED = 0;
+ private static final float DEFAULT_FONT_SIZE = 24;
+
+ /**
+ * @param cr Resolver to access the database with.
+ * @return The user's preferred caption enabled state.
+ */
+ public static final boolean isEnabled(ContentResolver cr) {
+ return Secure.getInt(cr, Secure.ACCESSIBILITY_CAPTIONING_ENABLED, DEFAULT_ENABLED) == 1;
+ }
+
+ /**
+ * @param cr Resolver to access the database with.
+ * @return The raw locale string for the user's preferred caption language.
+ * @hide
+ */
+ public static final String getRawLocale(ContentResolver cr) {
+ return Secure.getString(cr, Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
+ }
+
+ /**
+ * @param cr Resolver to access the database with.
+ * @return The locale for the user's preferred caption language, or null if
+ * not specified.
+ */
+ public static final Locale getLocale(ContentResolver cr) {
+ final String rawLocale = getRawLocale(cr);
+ if (!TextUtils.isEmpty(rawLocale)) {
+ final String[] splitLocale = rawLocale.split("_");
+ switch (splitLocale.length) {
+ case 3:
+ return new Locale(splitLocale[0], splitLocale[1], splitLocale[2]);
+ case 2:
+ return new Locale(splitLocale[0], splitLocale[1]);
+ case 1:
+ return new Locale(splitLocale[0]);
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * @param cr Resolver to access the database with.
+ * @return The user's preferred font size for video captions, or 0 if not
+ * specified.
+ */
+ public static final float getFontSize(ContentResolver cr) {
+ return Secure.getFloat(cr, Secure.ACCESSIBILITY_CAPTIONING_FONT_SIZE, DEFAULT_FONT_SIZE);
+ }
+
+ public static final class CaptionStyle {
+ 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;
+
+ /** @hide */
+ public static final CaptionStyle[] PRESETS;
+
+ /** @hide */
+ public static final int PRESET_CUSTOM = -1;
+
+ /** Edge type value specifying no character edges. */
+ public static final int EDGE_TYPE_NONE = 0;
+
+ /** Edge type value specifying uniformly outlined character edges. */
+ public static final int EDGE_TYPE_OUTLINE = 1;
+
+ /** Edge type value specifying drop-shadowed character edges. */
+ public static final int EDGE_TYPE_DROP_SHADOW = 2;
+
+ /** The preferred foreground color for video captions. */
+ public final int foregroundColor;
+
+ /** The preferred background color for video captions. */
+ public final int backgroundColor;
+
+ /**
+ * The preferred edge type for video captions, one of:
+ * <ul>
+ * <li>{@link #EDGE_TYPE_NONE}
+ * <li>{@link #EDGE_TYPE_OUTLINE}
+ * <li>{@link #EDGE_TYPE_DROP_SHADOW}
+ * </ul>
+ */
+ public final int edgeType;
+
+ /**
+ * The preferred edge color for video captions, if using an edge type
+ * other than {@link #EDGE_TYPE_NONE}.
+ */
+ public final int edgeColor;
+
+ /**
+ * @hide
+ */
+ public final String mRawTypeface;
+
+ private Typeface mParsedTypeface;
+
+ private CaptionStyle(int foregroundColor, int backgroundColor, int edgeType, int edgeColor,
+ String rawTypeface) {
+ this.foregroundColor = foregroundColor;
+ this.backgroundColor = backgroundColor;
+ this.edgeType = edgeType;
+ this.edgeColor = edgeColor;
+
+ mRawTypeface = rawTypeface;
+ }
+
+ /**
+ * @return The preferred {@link Typeface} for video captions, or null if
+ * not specified.
+ */
+ public Typeface getTypeface() {
+ if (mParsedTypeface == null && !TextUtils.isEmpty(mRawTypeface)) {
+ mParsedTypeface = Typeface.create(mRawTypeface, Typeface.NORMAL);
+ }
+ return mParsedTypeface;
+ }
+
+ /**
+ * @hide
+ */
+ public static int getRawPreset(ContentResolver cr) {
+ return Secure.getInt(cr, Secure.ACCESSIBILITY_CAPTIONING_PRESET, DEFAULT_PRESET);
+ }
+
+ /**
+ * @param cr Resolver to access the database with.
+ * @return The user's preferred caption style.
+ */
+ public static CaptionStyle defaultUserStyle(ContentResolver cr) {
+ final int preset = getRawPreset(cr);
+ if (preset == PRESET_CUSTOM) {
+ return getCustomStyle(cr);
+ }
+
+ return PRESETS[preset];
+ }
+
+ /**
+ * @hide
+ */
+ public static CaptionStyle getCustomStyle(ContentResolver cr) {
+ final int foregroundColor = Secure.getInt(
+ cr, Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR,
+ DEFAULT_CUSTOM.foregroundColor);
+ final int backgroundColor = Secure.getInt(cr,
+ Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR,
+ DEFAULT_CUSTOM.backgroundColor);
+ final int edgeType = Secure.getInt(
+ cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, DEFAULT_CUSTOM.edgeType);
+ final int edgeColor = Secure.getInt(
+ cr, Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, DEFAULT_CUSTOM.edgeColor);
+
+ String rawTypeface = Secure.getString(cr, Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
+ if (rawTypeface == null) {
+ rawTypeface = DEFAULT_CUSTOM.mRawTypeface;
+ }
+
+ return new CaptionStyle(
+ foregroundColor, backgroundColor, edgeType, edgeColor, rawTypeface);
+ }
+
+ static {
+ WHITE_ON_BLACK = new CaptionStyle(
+ Color.WHITE, Color.BLACK, EDGE_TYPE_NONE, Color.BLACK, null);
+ BLACK_ON_WHITE = new CaptionStyle(
+ Color.BLACK, Color.WHITE, EDGE_TYPE_NONE, Color.BLACK, null);
+ YELLOW_ON_BLACK = new CaptionStyle(
+ Color.YELLOW, Color.BLACK, EDGE_TYPE_NONE, Color.BLACK, null);
+ YELLOW_ON_BLUE = new CaptionStyle(
+ Color.YELLOW, Color.BLUE, EDGE_TYPE_NONE, Color.BLACK, null);
+
+ PRESETS = new CaptionStyle[] {
+ WHITE_ON_BLACK, BLACK_ON_WHITE, YELLOW_ON_BLACK, YELLOW_ON_BLUE
+ };
+
+ DEFAULT_CUSTOM = WHITE_ON_BLACK;
+ }
+ }
+}
diff --git a/core/java/android/view/accessibility/CaptioningPreferences.java b/core/java/android/view/accessibility/CaptioningPreferences.java
deleted file mode 100644
index 48dc3ad..0000000
--- a/core/java/android/view/accessibility/CaptioningPreferences.java
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * Copyright (C) 2013 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package android.view.accessibility;
-
-import android.content.ContentResolver;
-import android.graphics.Color;
-import android.graphics.Typeface;
-import android.provider.Settings;
-
-import java.util.Locale;
-
-/**
- * Contains methods for accessing preferred video captioning state and
- * properties.
- */
-public class CaptioningPreferences {
- /**
- * Activity Action: Show settings for video captioning.
- * <p>
- * In some cases, a matching Activity may not exist, so ensure you safeguard
- * against this.
- * <p>
- * Input: Nothing.
- * <p>
- * Output: Nothing.
- */
- public static final String ACTION_CAPTIONING_SETTINGS = "android.settings.CAPTIONING_SETTINGS";
-
- /**
- * Value specifying no character edges.
- *
- * @see #getEdgeType
- */
- public static final int EDGE_TYPE_NONE = 0;
-
- /**
- * Value specifying uniform (outlined) character edges.
- *
- * @see #getEdgeType
- */
- public static final int EDGE_TYPE_UNIFORM = 1;
-
- /**
- * Value specifying drop-shadowed character edges.
- *
- * @see #getEdgeType
- */
- public static final int EDGE_TYPE_DROP_SHADOWED = 2;
-
- // Typeface values MUST be synced with arrays.xml
- private static final String TYPEFACE_DEFAULT = "DEFAULT";
- private static final String TYPEFACE_MONOSPACE = "MONOSPACE";
- private static final String TYPEFACE_SANS_SERIF = "SANS_SERIF";
- private static final String TYPEFACE_SERIF = "SERIF";
-
- private static final int DEFAULT_ENABLED = 0;
- private static final int DEFAULT_FOREGROUND_COLOR = Color.WHITE;
- private static final int DEFAULT_BACKGROUND_COLOR = Color.TRANSPARENT;
- private static final int DEFAULT_EDGE_TYPE = EDGE_TYPE_UNIFORM;
- private static final int DEFAULT_EDGE_COLOR = Color.BLACK;
- private static final Typeface DEFAULT_TYPEFACE = Typeface.DEFAULT;
- private static final int DEFAULT_FONT_SIZE = 24;
- private static final String DEFAULT_LOCALE = "";
-
- /**
- * Returns the preferred enabled state for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return True if captions should be shown in supported video players.
- */
- public static final boolean isEnabled(ContentResolver cr) {
- return Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_ENABLED, DEFAULT_ENABLED) == 1;
- }
-
- /**
- * Returns the preferred foreground color for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred foreground color for video captions.
- */
- public static final int getForegroundColor(ContentResolver cr) {
- return Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR,
- DEFAULT_FOREGROUND_COLOR);
- }
-
- /**
- * Returns the preferred background color for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred background color for video captions.
- */
- public static final int getBackgroundColor(ContentResolver cr) {
- return Settings.Secure.getInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR,
- DEFAULT_BACKGROUND_COLOR);
- }
-
- /**
- * Returns the preferred edge type for video captions, one of:
- * <ul>
- * <li>{@link #EDGE_TYPE_NONE}
- * <li>{@link #EDGE_TYPE_UNIFORM}
- * <li>{@link #EDGE_TYPE_DROP_SHADOWED}
- * </ul>
- *
- * @param cr Resolver to access the database with.
- * @return The preferred edge type for video captions.
- */
- public static final int getEdgeType(ContentResolver cr) {
- return Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_TYPE, DEFAULT_EDGE_TYPE);
- }
-
- /**
- * Returns the preferred shadow color for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred shadow color for video captions.
- */
- public static final int getEdgeColor(ContentResolver cr) {
- return Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, DEFAULT_EDGE_COLOR);
- }
-
- /**
- * Returns the raw value representing the preferred typeface for video
- * captions.
- *
- * @param cr Resolver to access the database with.
- * @return The raw value representing the preferred typeface for video
- * captions.
- * @hide
- */
- public static final String getRawTypeface(ContentResolver cr) {
- final String rawTypeface = Settings.Secure.getString(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_TYPEFACE);
- if (rawTypeface != null) {
- return rawTypeface;
- }
-
- return TYPEFACE_DEFAULT;
- }
-
- /**
- * Returns the preferred typeface for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred typeface for video captions.
- */
- public static final Typeface getTypeface(ContentResolver cr) {
- final String rawTypeface = getRawTypeface(cr);
- if (TYPEFACE_DEFAULT.equals(rawTypeface)) {
- return Typeface.DEFAULT;
- } else if (TYPEFACE_MONOSPACE.equals(rawTypeface)) {
- return Typeface.MONOSPACE;
- } else if (TYPEFACE_SANS_SERIF.equals(rawTypeface)) {
- return Typeface.SANS_SERIF;
- } else if (TYPEFACE_SERIF.equals(rawTypeface)) {
- return Typeface.SERIF;
- }
-
- return DEFAULT_TYPEFACE;
- }
-
- /**
- * Returns the raw value representing the preferred font size for video
- * captions.
- *
- * @param cr Resolver to access the database with.
- * @return The raw value representing the preferred font size for video
- * captions.
- * @hide
- */
- public static final int getRawFontSize(ContentResolver cr) {
- return Settings.Secure.getInt(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_FONT_SIZE, DEFAULT_FONT_SIZE);
- }
-
- /**
- * Returns the preferred font size for video captions.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred font size for video captions.
- */
- public static final float getFontSize(ContentResolver cr) {
- return getRawFontSize(cr);
- }
-
- /**
- * Returns the raw value representing the preferred locale for video
- * captions.
- *
- * @param cr Resolver to access the database with.
- * @return The raw value representing the preferred locale for video
- * captions.
- * @hide
- */
- public static final String getRawLocale(ContentResolver cr) {
- final String rawLocale = Settings.Secure.getString(
- cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_LOCALE);
- if (rawLocale != null) {
- return rawLocale;
- }
-
- return DEFAULT_LOCALE;
- }
-
- /**
- * Returns the preferred locale for video captions, or null to use the
- * device locale.
- *
- * @param cr Resolver to access the database with.
- * @return The preferred locale for video captions, or null to use the
- * device locale.
- */
- public static final Locale getLocale(ContentResolver cr) {
- final String rawLocale = getRawLocale(cr);
- if (rawLocale.length() > 0) {
- final String[] splitLocale = rawLocale.split("_");
- switch (splitLocale.length) {
- case 3:
- return new Locale(splitLocale[0], splitLocale[1], splitLocale[2]);
- case 2:
- return new Locale(splitLocale[0], splitLocale[1]);
- case 1:
- return new Locale(splitLocale[0]);
- }
- }
-
- return null;
- }
-}