OSDN Git Service

Add secure settings for captions
authorAlan Viverette <alanv@google.com>
Tue, 23 Jul 2013 21:15:28 +0000 (14:15 -0700)
committerAlan Viverette <alanv@google.com>
Tue, 23 Jul 2013 21:15:28 +0000 (14:15 -0700)
BUG: 9926077
Change-Id: I202aef88943e1f884e5bd4c112f081b8b4b76ada

api/current.txt
core/java/android/provider/Settings.java
core/java/android/view/accessibility/CaptioningPreferences.java [new file with mode: 0644]

index 9073348..b2a3521 100644 (file)
@@ -28213,6 +28213,22 @@ package android.view.accessibility {
     method public void setToIndex(int);
   }
 
+  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
+    field public static final int EDGE_TYPE_NONE = 0; // 0x0
+    field public static final int EDGE_TYPE_UNIFORM = 1; // 0x1
+  }
+
 }
 
 package android.view.animation {
index 9685fb0..ed9f218 100644 (file)
@@ -3502,6 +3502,104 @@ public final class Settings {
                 "accessibility_display_magnification_auto_update";
 
         /**
+         * Setting that specifies whether timed text (captions) should be
+         * displayed in video content. Text display properties are controlled by
+         * the following settings:
+         * <ul>
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_LOCALE}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_EDGE_COLOR}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_EDGE_TYPE}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_TYPEFACE}
+         * <li>{@link #ACCESSIBILITY_CAPTIONING_FONT_SIZE}
+         * </ul>
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_ENABLED =
+                "accessibility_captioning_enabled";
+
+        /**
+         * Setting that specifies the language for captions as a locale string,
+         * e.g. en_US.
+         *
+         * @see java.util.Locale#toString
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_LOCALE =
+                "accessibility_captioning_locale";
+
+        /**
+         * Integer property that specifes the background color for captions as a
+         * packed 32-bit color.
+         *
+         * @see android.graphics.Color#argb
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR =
+                "accessibility_captioning_background_color";
+
+        /**
+         * Integer property that specifes the foreground color for captions as a
+         * packed 32-bit color.
+         *
+         * @see android.graphics.Color#argb
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR =
+                "accessibility_captioning_foreground_color";
+
+        /**
+         * 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}
+         * </ul>
+         *
+         * @see #ACCESSIBILITY_CAPTIONING_EDGE_COLOR
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_EDGE_TYPE =
+                "accessibility_captioning_edge_type";
+
+        /**
+         * Integer property that specifes the edge color for captions as a
+         * packed 32-bit color.
+         *
+         * @see #ACCESSIBILITY_CAPTIONING_EDGE_TYPE
+         * @see android.graphics.Color#argb
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_EDGE_COLOR =
+                "accessibility_captioning_edge_color";
+
+        /**
+         * String property that specifies the typeface for captions, one of:
+         * <ul>
+         * <li>DEFAULT
+         * <li>MONOSPACE
+         * <li>SANS_SERIF
+         * <li>SERIF
+         * </ul>
+         *
+         * @see android.graphics.Typeface
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_TYPEFACE =
+                "accessibility_captioning_typeface";
+
+        /**
+         * Integer point property that specifies font size for captions in
+         * scaled pixels (sp).
+         *
+         * @hide
+         */
+        public static final String ACCESSIBILITY_CAPTIONING_FONT_SIZE =
+                "accessibility_captioning_font_size";
+
+        /**
          * The timout for considering a press to be a long press in milliseconds.
          * @hide
          */
@@ -4132,6 +4230,14 @@ public final class Settings {
             TOUCH_EXPLORATION_ENABLED,
             ACCESSIBILITY_ENABLED,
             ACCESSIBILITY_SPEAK_PASSWORD,
+            ACCESSIBILITY_CAPTIONING_ENABLED,
+            ACCESSIBILITY_CAPTIONING_LOCALE,
+            ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR,
+            ACCESSIBILITY_CAPTIONING_FOREGROUND_COLOR,
+            ACCESSIBILITY_CAPTIONING_EDGE_TYPE,
+            ACCESSIBILITY_CAPTIONING_EDGE_COLOR,
+            ACCESSIBILITY_CAPTIONING_TYPEFACE,
+            ACCESSIBILITY_CAPTIONING_FONT_SIZE,
             TTS_USE_DEFAULTS,
             TTS_DEFAULT_RATE,
             TTS_DEFAULT_PITCH,
diff --git a/core/java/android/view/accessibility/CaptioningPreferences.java b/core/java/android/view/accessibility/CaptioningPreferences.java
new file mode 100644 (file)
index 0000000..48dc3ad
--- /dev/null
@@ -0,0 +1,246 @@
+/*
+ * 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;
+    }
+}