[Android] Use ListPreference for setLocale
Habib Kazemi
git at videolan.org
Thu Jul 19 14:54:36 CEST 2018
vlc-android | branch: master | Habib Kazemi <kazemihabib1996 at gmail.com> | Sat Jul 14 14:44:38 2018 +0430| [504f2b08b77f4f36a1a64d8eecb2da1cd2bc4baa] | committer: Geoffrey Métais
Use ListPreference for setLocale
Signed-off-by: Geoffrey Métais <geoffrey.metais at gmail.com>
> https://code.videolan.org/videolan/vlc-android/commit/504f2b08b77f4f36a1a64d8eecb2da1cd2bc4baa
---
vlc-android/res/xml/preferences_ui.xml | 3 +--
vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java | 10 ++++++++++
.../src/org/videolan/vlc/gui/preferences/PreferencesUi.java | 11 +++++++++++
.../org/videolan/vlc/gui/tv/preferences/PreferencesUi.java | 11 +++++++++++
vlc-android/src/org/videolan/vlc/util/LocalePair.kt | 3 +++
5 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/vlc-android/res/xml/preferences_ui.xml b/vlc-android/res/xml/preferences_ui.xml
index 16b4611f1..d4e034577 100644
--- a/vlc-android/res/xml/preferences_ui.xml
+++ b/vlc-android/res/xml/preferences_ui.xml
@@ -29,10 +29,9 @@
android:summary="@string/playback_speed_summary"
android:title="@string/playback_speed_title" />
- <EditTextPreference
+ <ListPreference
android:defaultValue=""
android:key="set_locale"
- android:summary="@string/set_locale_detail"
android:title="@string/set_locale" />
<CheckBoxPreference
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 19d4b667c..155c582c3 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -83,6 +83,7 @@ import org.videolan.vlc.gui.dialogs.SavePlaylistDialog;
import org.videolan.vlc.media.MediaUtils;
import org.videolan.vlc.util.Constants;
import org.videolan.vlc.util.FileUtils;
+import org.videolan.vlc.util.LocalePair;
import org.videolan.vlc.viewmodels.BaseModel;
import java.util.List;
@@ -505,4 +506,13 @@ public class UiTools {
.create()
.show();
}
+
+ public static LocalePair getLocalesUsedInProject(Context context) {
+ final String[] localesEntryValues = context.getAssets().getLocales();
+ final String[] localesEntry = new String[localesEntryValues.length];
+ for (int i=0; i<localesEntryValues.length; i++) {
+ localesEntry[i] = new Locale(localesEntryValues[i]).getDisplayLanguage(new Locale(localesEntryValues[i]));
+ }
+ return new LocalePair(localesEntry, localesEntryValues);
+ }
}
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 faa19b1a3..f9137291e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/preferences/PreferencesUi.java
@@ -26,12 +26,15 @@ package org.videolan.vlc.gui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AppCompatDelegate;
+import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.SwitchPreferenceCompat;
import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.UiTools;
+import org.videolan.vlc.util.LocalePair;
+
public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -64,6 +67,7 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
super.onCreate(savedInstanceState);
findPreference("tv_ui").setVisible(AndroidUtil.isJellyBeanMR1OrLater);
findPreference("blurred_cover_background").setVisible(AndroidUtil.isJellyBeanMR1OrLater);
+ prepareLocaleList();
}
@Override
@@ -88,4 +92,11 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
if (key.equals("set_locale"))
UiTools.restartDialog(getActivity());
}
+
+ private void prepareLocaleList() {
+ final LocalePair localePair = UiTools.getLocalesUsedInProject(getActivity());
+ final ListPreference lp = (ListPreference)findPreference("set_locale");
+ lp.setEntries(localePair.getLocaleEntries());
+ lp.setEntryValues(localePair.getLocaleEntryValues());
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
index bd72a102e..8aceeefdc 100644
--- a/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
+++ b/vlc-android/src/org/videolan/vlc/gui/tv/preferences/PreferencesUi.java
@@ -27,10 +27,13 @@ import android.annotation.TargetApi;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
+import android.support.v7.preference.ListPreference;
import org.videolan.vlc.R;
import org.videolan.vlc.gui.helpers.UiTools;
import org.videolan.vlc.util.AndroidDevices;
+import org.videolan.vlc.util.LocalePair;
+
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class PreferencesUi extends BasePreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
@@ -56,6 +59,7 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
findPreference("secondary_display_category_summary").setVisible(false);
findPreference("daynight").setVisible(false);
findPreference("blurred_cover_background").setVisible(false);
+ prepareLocaleList();
}
@Override
@@ -82,4 +86,11 @@ public class PreferencesUi extends BasePreferenceFragment implements SharedPrefe
break;
}
}
+
+ private void prepareLocaleList() {
+ LocalePair localePair = UiTools.getLocalesUsedInProject(getActivity());
+ ListPreference lp = (ListPreference)findPreference("set_locale");
+ lp.setEntries(localePair.getLocaleEntries());
+ lp.setEntryValues(localePair.getLocaleEntryValues());
+ }
}
diff --git a/vlc-android/src/org/videolan/vlc/util/LocalePair.kt b/vlc-android/src/org/videolan/vlc/util/LocalePair.kt
new file mode 100644
index 000000000..dab20c792
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/util/LocalePair.kt
@@ -0,0 +1,3 @@
+package org.videolan.vlc.util
+
+class LocalePair(val localeEntries: Array<String>, val localeEntryValues: Array<String>)
\ No newline at end of file
More information about the Android
mailing list