Merge "Ensure "default" and "none" caption colors are consistent w/ framework" into mnc-dev
diff --git a/res/layout/grid_picker_dialog.xml b/res/layout/grid_picker_dialog.xml
index 1e04188..1c3bfda 100644
--- a/res/layout/grid_picker_dialog.xml
+++ b/res/layout/grid_picker_dialog.xml
@@ -31,7 +31,8 @@
         android:numColumns="auto_fit"
         android:columnWidth="96dp"
         android:scrollbarStyle="insideOverlay"
-        android:stretchMode="columnWidth" />
+        android:stretchMode="columnWidth"
+        android:scrollIndicators="top|bottom" />
 
     <!-- HACK: Setting minHeight has no effect within a dialog layout,
          so this view keeps the minimum height above 300dp. -->
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index 6c1f68b..93ad961 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -829,7 +829,7 @@
 
     <!-- Values for captioning color preference. -->
     <integer-array name="captioning_color_selector_values" translatable="false" >
-        <item>0x00000100</item>
+        <item>0x00FFFFFF</item>
         <item>0xFFFFFFFF</item>
         <item>0xFF000000</item>
         <item>0xFFFF0000</item>
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
index ff9c9eb..81640e8 100644
--- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
+++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
@@ -344,9 +344,17 @@
         mEdgeType.setValue(attrs.edgeType);
         mEdgeColor.setValue(attrs.edgeColor);
 
-        parseColorOpacity(mForegroundColor, mForegroundOpacity, attrs.foregroundColor);
-        parseColorOpacity(mBackgroundColor, mBackgroundOpacity, attrs.backgroundColor);
-        parseColorOpacity(mWindowColor, mWindowOpacity, attrs.windowColor);
+        final int foregroundColor = attrs.hasForegroundColor() ?
+                attrs.foregroundColor : CaptionStyle.COLOR_UNSPECIFIED;
+        parseColorOpacity(mForegroundColor, mForegroundOpacity, foregroundColor);
+
+        final int backgroundColor = attrs.hasBackgroundColor() ?
+                attrs.backgroundColor : CaptionStyle.COLOR_UNSPECIFIED;
+        parseColorOpacity(mBackgroundColor, mBackgroundOpacity, backgroundColor);
+
+        final int windowColor = attrs.hasWindowColor() ?
+                attrs.windowColor : CaptionStyle.COLOR_UNSPECIFIED;
+        parseColorOpacity(mWindowColor, mWindowOpacity, windowColor);
 
         final String rawTypeface = attrs.mRawTypeface;
         mTypeface.setValue(rawTypeface == null ? "" : rawTypeface);
@@ -355,27 +363,48 @@
         mLocale.setValue(rawLocale == null ? "" : rawLocale);
     }
 
+    /**
+     * Unpack the specified color value and update the preferences.
+     *
+     * @param color color preference
+     * @param opacity opacity preference
+     * @param value packed value
+     */
     private void parseColorOpacity(ColorPreference color, ColorPreference opacity, int value) {
         final int colorValue;
         final int opacityValue;
-        if (Color.alpha(value) == 0) {
+        if (!CaptionStyle.hasColor(value)) {
+            // "Default" color with variable alpha.
+            colorValue = CaptionStyle.COLOR_UNSPECIFIED;
+            opacityValue = (value & 0xFF) << 24;
+        } else if ((value >>> 24) == 0) {
+            // "None" color with variable alpha.
             colorValue = Color.TRANSPARENT;
             opacityValue = (value & 0xFF) << 24;
         } else {
+            // Normal color.
             colorValue = value | 0xFF000000;
             opacityValue = value & 0xFF000000;
         }
-        color.setValue(colorValue);
+
+        // Opacity value is always white.
         opacity.setValue(opacityValue | 0xFFFFFF);
+        color.setValue(colorValue);
     }
 
     private int mergeColorOpacity(ColorPreference color, ColorPreference opacity) {
         final int colorValue = color.getValue();
         final int opacityValue = opacity.getValue();
         final int value;
-        if (Color.alpha(colorValue) == 0) {
-            value = colorValue & 0x00FFFF00 | Color.alpha(opacityValue);
+        // "Default" is 0x00FFFFFF or, for legacy support, 0x00000100.
+        if (!CaptionStyle.hasColor(colorValue)) {
+            // Encode "default" as 0x00FFFFaa.
+            value = 0x00FFFF00 | Color.alpha(opacityValue);
+        } else if (colorValue == Color.TRANSPARENT) {
+            // Encode "none" as 0x000000aa.
+            value = Color.alpha(opacityValue);
         } else {
+            // Encode custom color normally.
             value = colorValue & 0x00FFFFFF | opacityValue & 0xFF000000;
         }
         return value;