Additional caption settings for edge styles and window color

Change-Id: Ib967bc566a7b8f7674c696fc05d799e12269ec42
diff --git a/res/layout/captioning_preview.xml b/res/layout/captioning_preview.xml
index 44563e4..0963ee9 100644
--- a/res/layout/captioning_preview.xml
+++ b/res/layout/captioning_preview.xml
@@ -31,13 +31,19 @@
             android:scaleType="centerCrop"
             android:src="@drawable/caption_background" />
 
-        <com.android.internal.widget.SubtitleView
-            android:id="@+id/preview_text"
-            android:layout_width="wrap_content"
+        <FrameLayout
+            android:id="@+id/preview_window"
+            android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="bottom|start"
-            android:layout_margin="16dp"
-            android:text="@string/captioning_preview_text" />
+            android:padding="16dp" >
+
+            <com.android.internal.widget.SubtitleView
+                android:id="@+id/preview_text"
+                android:layout_width="wrap_content"
+                android:layout_height="wrap_content"
+                android:text="@string/captioning_preview_text" />
+        </FrameLayout>
     </FrameLayout>
 
     <FrameLayout
diff --git a/res/values/arrays.xml b/res/values/arrays.xml
index c5c4437..4e407ba 100644
--- a/res/values/arrays.xml
+++ b/res/values/arrays.xml
@@ -747,6 +747,8 @@
         <item>None</item>
         <item>Outline</item>
         <item>Drop shadow</item>
+        <item>Raised</item>
+        <item>Depressed</item>
     </string-array>
 
     <!-- Values for captioning character edge type preference. -->
@@ -754,6 +756,8 @@
         <item>0</item>
         <item>1</item>
         <item>2</item>
+        <item>3</item>
+        <item>4</item>
     </integer-array>
 
     <!-- Titles for captioning color preference. -->
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 08fe28f..bd101cb 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3379,6 +3379,10 @@
     <string name="captioning_background_color">Background color</string>
     <!-- Title for the preference to change video caption background opacity. [CHAR LIMIT=35] -->
     <string name="captioning_background_opacity">Background opacity</string>
+    <!-- Title for the preference to change video caption window color. [CHAR LIMIT=35] -->
+    <string name="captioning_window_color">Caption window color</string>
+    <!-- Title for the preference to change video caption window opacity. [CHAR LIMIT=35] -->
+    <string name="captioning_window_opacity">Caption window opacity</string>
     <!-- Title for the preference to change video caption text color. [CHAR LIMIT=35] -->
     <string name="captioning_foreground_color">Text color</string>
     <!-- Title for the preference to change video caption text opacity. [CHAR LIMIT=35] -->
diff --git a/res/xml/captioning_settings.xml b/res/xml/captioning_settings.xml
index d14d352..ae5b75d 100644
--- a/res/xml/captioning_settings.xml
+++ b/res/xml/captioning_settings.xml
@@ -82,6 +82,15 @@
             android:key="captioning_background_opacity"
             android:persistent="false"
             android:title="@string/captioning_background_opacity" />
+        <com.android.settings.accessibility.ColorPreference
+            android:key="captioning_window_color"
+            android:persistent="false"
+            android:title="@string/captioning_window_color" />
+        <com.android.settings.accessibility.ColorPreference
+            android:dependency="captioning_window_color"
+            android:key="captioning_window_opacity"
+            android:persistent="false"
+            android:title="@string/captioning_window_opacity" />
     </PreferenceCategory>
 
-</PreferenceScreen>
\ No newline at end of file
+</PreferenceScreen>
diff --git a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
index 8a08d90..324c595 100644
--- a/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
+++ b/src/com/android/settings/accessibility/CaptionPropertiesFragment.java
@@ -54,6 +54,8 @@
     private static final String PREF_BACKGROUND_OPACITY = "captioning_background_opacity";
     private static final String PREF_FOREGROUND_COLOR = "captioning_foreground_color";
     private static final String PREF_FOREGROUND_OPACITY = "captioning_foreground_opacity";
+    private static final String PREF_WINDOW_COLOR = "captioning_window_color";
+    private static final String PREF_WINDOW_OPACITY = "captioning_window_opacity";
     private static final String PREF_EDGE_COLOR = "captioning_edge_color";
     private static final String PREF_EDGE_TYPE = "captioning_edge_type";
     private static final String PREF_FONT_SIZE = "captioning_font_size";
@@ -66,6 +68,7 @@
 
     private CaptioningManager mCaptioningManager;
     private SubtitleView mPreviewText;
+    private View mPreviewWindow;
 
     // Standard options.
     private LocalePreference mLocale;
@@ -80,6 +83,8 @@
     private ColorPreference mEdgeColor;
     private ColorPreference mBackgroundColor;
     private ColorPreference mBackgroundOpacity;
+    private ColorPreference mWindowColor;
+    private ColorPreference mWindowOpacity;
     private PreferenceCategory mCustom;
 
     private boolean mShowingCustom;
@@ -120,6 +125,7 @@
         super.onViewCreated(view, savedInstanceState);
 
         mPreviewText = (SubtitleView) view.findViewById(R.id.preview_text);
+        mPreviewWindow = view.findViewById(R.id.preview_window);
 
         installActionBarToggleSwitch();
         refreshPreviewText();
@@ -145,6 +151,9 @@
             } else {
                 preview.setText(R.string.captioning_preview_text);
             }
+
+            final CaptionStyle style = mCaptioningManager.getUserStyle();
+            mPreviewWindow.setBackgroundColor(style.windowColor);
         }
     }
 
@@ -246,6 +255,14 @@
         mBackgroundOpacity.setTitles(opacityTitles);
         mBackgroundOpacity.setValues(opacityValues);
 
+        mWindowColor = (ColorPreference) mCustom.findPreference(PREF_WINDOW_COLOR);
+        mWindowColor.setTitles(bgColorTitles);
+        mWindowColor.setValues(bgColorValues);
+
+        mWindowOpacity = (ColorPreference) mCustom.findPreference(PREF_WINDOW_OPACITY);
+        mWindowOpacity.setTitles(opacityTitles);
+        mWindowOpacity.setValues(opacityValues);
+
         mEdgeType = (EdgeTypePreference) mCustom.findPreference(PREF_EDGE_TYPE);
         mTypeface = (ListPreference) mCustom.findPreference(PREF_TYPEFACE);
     }
@@ -257,6 +274,8 @@
         mEdgeColor.setOnValueChangedListener(this);
         mBackgroundColor.setOnValueChangedListener(this);
         mBackgroundOpacity.setOnValueChangedListener(this);
+        mWindowColor.setOnValueChangedListener(this);
+        mWindowOpacity.setOnValueChangedListener(this);
         mEdgeType.setOnValueChangedListener(this);
 
         mTypeface.setOnPreferenceChangeListener(this);
@@ -278,6 +297,7 @@
 
         parseColorOpacity(mForegroundColor, mForegroundOpacity, attrs.foregroundColor);
         parseColorOpacity(mBackgroundColor, mBackgroundOpacity, attrs.backgroundColor);
+        parseColorOpacity(mWindowColor, mWindowOpacity, attrs.windowColor);
 
         final String rawTypeface = attrs.mRawTypeface;
         mTypeface.setValue(rawTypeface == null ? "" : rawTypeface);
@@ -334,6 +354,10 @@
             final int merged = mergeColorOpacity(mBackgroundColor, mBackgroundOpacity);
             Settings.Secure.putInt(
                     cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_BACKGROUND_COLOR, merged);
+        } else if (mWindowColor == preference || mWindowOpacity == preference) {
+            final int merged = mergeColorOpacity(mWindowColor, mWindowOpacity);
+            Settings.Secure.putInt(
+                    cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_WINDOW_COLOR, merged);
         } else if (mEdgeColor == preference) {
             Settings.Secure.putInt(cr, Settings.Secure.ACCESSIBILITY_CAPTIONING_EDGE_COLOR, value);
         } else if (mPreset == preference) {