[Android] Preferences : add subtitles appearance options

Alexandre Perraud git at videolan.org
Thu Jul 7 17:28:35 CEST 2016


vlc-android | branch: master | Alexandre Perraud <4leyx4ndre at gmail.com> | Thu Jul  7 17:19:59 2016 +0200| [a3c0fdc2aff698e94bc1ce278f5f0a665fa281d9] | committer: Alexandre Perraud

Preferences : add subtitles appearance options

> https://code.videolan.org/videolan/vlc-android/commit/a3c0fdc2aff698e94bc1ce278f5f0a665fa281d9
---

 vlc-android/res/values/arrays.xml                  | 31 ++++++++++++++++
 vlc-android/res/values/strings.xml                 | 12 ++++++
 vlc-android/res/xml/preferences_ui.xml             | 43 +++++++++++++++++-----
 .../vlc/gui/preferences/PreferencesUi.java         | 22 ++++++++++-
 .../src/org/videolan/vlc/util/VLCOptions.java      | 11 ++++++
 5 files changed, 108 insertions(+), 11 deletions(-)

diff --git a/vlc-android/res/values/arrays.xml b/vlc-android/res/values/arrays.xml
index f713f93..0fba72e 100644
--- a/vlc-android/res/values/arrays.xml
+++ b/vlc-android/res/values/arrays.xml
@@ -145,4 +145,35 @@
         <item>urd</item>
         <item>vie</item>
     </string-array>
+
+    <string-array name="subtitles_size_entries">
+        <item>@string/subtitles_size_small</item>
+        <item>@string/subtitles_size_normal</item>
+        <item>@string/subtitles_size_big</item>
+        <item>@string/subtitles_size_huge</item>
+    </string-array>
+
+    <string-array name="subtitles_size_values">
+        <item>19</item>
+        <item>16</item>
+        <item>13</item>
+        <item>10</item>
+    </string-array>
+
+    <string-array name="subtitles_color_entries">
+        <item>@string/subtitles_color_white</item>
+        <item>@string/subtitles_color_pink</item>
+        <item>@string/subtitles_color_blue</item>
+        <item>@string/subtitles_color_yellow</item>
+        <item>@string/subtitles_color_green</item>
+    </string-array>
+
+    <string-array name="subtitles_color_values">
+        <item>16777215</item>
+        <item>16711935</item>
+        <item>65535</item>
+        <item>16776960</item>
+        <item>65280</item>
+    </string-array>
+
 </resources>
\ No newline at end of file
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 25ba585..66e9088 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -394,6 +394,18 @@
     <string name="video_min_group_length_first">First letter only</string>
     <string name="video_min_group_length_short">Short number of letters (6)</string>
     <string name="video_min_group_length_long">Long number of letters (9)</string>
+    <string name="subtitles_size_title">Subtitles Size</string>
+    <string name="subtitles_size_small">Small</string>
+    <string name="subtitles_size_normal">Normal</string>
+    <string name="subtitles_size_big">Big</string>
+    <string name="subtitles_size_huge">Huge</string>
+    <string name="subtitles_color_title">Subtitles Color</string>
+    <string name="subtitles_color_white">White</string>
+    <string name="subtitles_color_pink">Pink</string>
+    <string name="subtitles_color_blue">Blue</string>
+    <string name="subtitles_color_yellow">Yellow</string>
+    <string name="subtitles_color_green">Green</string>
+    <string name="subtitles_background_title">Subtitles Background</string>
 
     <!--Accessibility-->
     <string name="more_actions">More Actions</string>
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index e044c0c..ad05565 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -17,7 +17,8 @@
         android:persistent="true"
         android:summary="@string/video_min_group_length_summary"
         android:title="@string/video_min_group_length_title" />
-    <PreferenceCategory android:title="@string/interface_gui" >
+
+    <PreferenceCategory android:title="@string/interface_gui">
         <CheckBoxPreference
             android:key="tv_ui"
             android:summary="@string/tv_ui_summary"
@@ -40,14 +41,8 @@
             android:persistent="true"
             android:title="@string/audio_title_alignment" />
     </PreferenceCategory>
-    <PreferenceCategory android:title="@string/interface_controls" >
-        <android.support.v14.preference.MultiSelectListPreference
-            android:dialogTitle="@string/preferences_languages_download"
-            android:entries="@array/language_entries"
-            android:entryValues="@array/language_values"
-            android:key="languages_download_list"
-            android:summary="@string/list_languages_download_summary"
-            android:title="@string/list_languages_download_title" />
+
+    <PreferenceCategory android:title="@string/interface_controls">
         <CheckBoxPreference
             android:defaultValue="false"
             android:key="save_brightness"
@@ -85,7 +80,35 @@
             android:title="@string/enable_steal_remote_control" />
     </PreferenceCategory>
 
-    <PreferenceCategory android:title="@string/interface_secondary_display_category_title" >
+    <PreferenceCategory android:title="@string/subtitles">
+        <ListPreference
+            android:defaultValue="16"
+            android:entries="@array/subtitles_size_entries"
+            android:entryValues="@array/subtitles_size_values"
+            android:key="subtitles_size"
+            android:persistent="true"
+            android:title="@string/subtitles_size_title" />
+        <ListPreference
+            android:defaultValue="16777215"
+            android:entries="@array/subtitles_color_entries"
+            android:entryValues="@array/subtitles_color_values"
+            android:key="subtitles_color"
+            android:persistent="true"
+            android:title="@string/subtitles_color_title" />
+        <CheckBoxPreference
+            android:defaultValue="false"
+            android:key="subtitles_background"
+            android:title="@string/subtitles_background_title" />
+        <android.support.v14.preference.MultiSelectListPreference
+            android:dialogTitle="@string/preferences_languages_download"
+            android:entries="@array/language_entries"
+            android:entryValues="@array/language_values"
+            android:key="languages_download_list"
+            android:summary="@string/list_languages_download_summary"
+            android:title="@string/list_languages_download_title" />
+    </PreferenceCategory>
+
+    <PreferenceCategory android:title="@string/interface_secondary_display_category_title">
         <Preference android:summary="@string/interface_secondary_display_category_summary" />
 
         <CheckBoxPreference
diff --git a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
index 69ef6b8..f27591f 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
@@ -23,6 +23,7 @@
 
 package org.videolan.vlc.gui.preferences;
 
+import android.content.SharedPreferences;
 import android.os.Bundle;
 import android.support.v7.preference.Preference;
 import android.support.v7.preference.TwoStatePreference;
@@ -30,8 +31,9 @@ import android.support.v7.preference.TwoStatePreference;
 import org.videolan.libvlc.util.AndroidUtil;
 import org.videolan.vlc.PlaybackService;
 import org.videolan.vlc.R;
+import org.videolan.vlc.util.VLCInstance;
 
-public class PreferencesUi extends BasePreferenceFragment {
+public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
 
     @Override
     protected int getXml() {
@@ -44,6 +46,12 @@ public class PreferencesUi extends BasePreferenceFragment {
     }
 
     @Override
+    public void onStart() {
+        super.onStart();
+        getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
+    }
+
+    @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
 
@@ -52,6 +60,18 @@ public class PreferencesUi extends BasePreferenceFragment {
     }
 
     @Override
+    public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+        switch (key){
+            case "subtitles_size":
+            case "subtitles_color":
+            case "subtitles_background":
+                VLCInstance.restart();
+                if (getActivity() != null )
+                    ((PreferencesActivity)getActivity()).restartMediaPlayer();
+        }
+    }
+
+    @Override
     public boolean onPreferenceTreeClick(Preference preference) {
         if (preference.getKey() == null)
             return false;
diff --git a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
index 5ab60ee..26f1dd5 100644
--- a/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
+++ b/vlc-android/src/org/videolan/vlc/util/VLCOptions.java
@@ -77,6 +77,10 @@ public class VLCOptions {
         else if (networkCaching < 0)
             networkCaching = 0;
 
+        final String freetypeRelFontsize = pref.getString("subtitles_size", "16");
+        final String freetypeColor = pref.getString("subtitles_color", "16777215");
+        final boolean freetypeBackground = pref.getBoolean("subtitles_background", false);
+
         /* CPU intensive plugin, setting for slow devices */
         options.add(timeStreching ? "--audio-time-stretch" : "--no-audio-time-stretch");
         options.add("--avcodec-skiploopfilter");
@@ -96,6 +100,13 @@ public class VLCOptions {
         options.add("--audio-resampler");
         options.add(getResampler());
 
+        options.add("--freetype-rel-fontsize=" + freetypeRelFontsize);
+        options.add("--freetype-color=" + freetypeColor);
+        if (freetypeBackground)
+            options.add("--freetype-background-opacity=128");
+        else
+            options.add("--freetype-background-opacity=0");
+
         /* Configure keystore */
         options.add("--keystore");
         if (AndroidUtil.isMarshMallowOrLater())



More information about the Android mailing list