[tor-commits] [orbot/master] update implementation of language selector
n8fr8 at torproject.org
n8fr8 at torproject.org
Sat May 12 04:50:45 UTC 2018
commit 93a0092cda4db50d435d8478649afe45799ff863
Author: n8fr8 <nathan at freitas.net>
Date: Fri May 11 22:53:52 2018 -0400
update implementation of language selector
---
app/build.gradle | 3 ++-
app/src/main/java/org/torproject/android/OrbotApp.java | 9 ++++++++-
.../java/org/torproject/android/settings/Languages.java | 11 -----------
.../torproject/android/settings/SettingsPreferences.java | 13 ++++++++++++-
app/src/main/res/xml-fa/preferences.xml | 15 ++++++++++++---
app/src/main/res/xml/preferences.xml | 9 ++++++++-
6 files changed, 42 insertions(+), 18 deletions(-)
diff --git a/app/build.gradle b/app/build.gradle
index 3c106337..9e55cdde 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -5,7 +5,7 @@ android {
buildToolsVersion '27.0.3'
defaultConfig {
applicationId "org.torproject.android"
- minSdkVersion 16
+ minSdkVersion 14
targetSdkVersion 27
}
lintOptions {
@@ -76,6 +76,7 @@ android {
}
dependencies {
+ implementation 'com.github.delight-im:Android-Languages:v1.0.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
implementation project(':orbotservice')
implementation 'com.android.support:design:27.1.1'
diff --git a/app/src/main/java/org/torproject/android/OrbotApp.java b/app/src/main/java/org/torproject/android/OrbotApp.java
index 2bca1b45..0e8e1375 100644
--- a/app/src/main/java/org/torproject/android/OrbotApp.java
+++ b/app/src/main/java/org/torproject/android/OrbotApp.java
@@ -33,6 +33,8 @@ import org.torproject.android.settings.LocaleHelper;
import java.util.Locale;
import java.util.Set;
+import im.delight.android.languages.Language;
+
public class OrbotApp extends Application implements OrbotConstants
{
@@ -42,8 +44,11 @@ public class OrbotApp extends Application implements OrbotConstants
public void onCreate() {
super.onCreate();
+ /**
Languages.setup(OrbotMainActivity.class, R.string.menu_settings);
Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
+ **/
+ Language.setFromPreference(this, "pref_default_locale");
//check for updates via github, since it is unlikely to be blocked; notify the user of places where upgrades can be found
new AppUpdater(this)
@@ -61,7 +66,9 @@ public class OrbotApp extends Application implements OrbotConstants
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
- //Log.i(TAG, "onConfigurationChanged " + newConfig.locale.getLanguage());
+ Language.setFromPreference(this, "pref_default_locale");
+
+ //Log.i(TAG, "onConfigurationChanged " + newConfig.locale.getLanguage());
// Languages.setLanguage(this, Prefs.getDefaultLocale(), true);
}
/**
diff --git a/app/src/main/java/org/torproject/android/settings/Languages.java b/app/src/main/java/org/torproject/android/settings/Languages.java
index 90ad805c..abed8838 100644
--- a/app/src/main/java/org/torproject/android/settings/Languages.java
+++ b/app/src/main/java/org/torproject/android/settings/Languages.java
@@ -216,17 +216,6 @@ public class Languages {
return nameMap.values().toArray(new String[nameMap.size()]);
}
- public int getPosition(Locale locale) {
- String localeName = locale.getLanguage();
- int i = 0;
- for (String key : nameMap.keySet())
- if (TextUtils.equals(key, localeName))
- return i;
- else
- i++;
- return -1;
- }
-
/**
* Get sorted list of supported locales.
*
diff --git a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
index fb01cde1..513432a1 100644
--- a/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
+++ b/app/src/main/java/org/torproject/android/settings/SettingsPreferences.java
@@ -14,6 +14,8 @@ import android.preference.PreferenceActivity;
import org.torproject.android.R;
import org.torproject.android.service.util.Prefs;
+import im.delight.android.languages.Language;
+
public class SettingsPreferences
extends PreferenceActivity {
private static final String TAG = "SettingsPreferences";
@@ -26,10 +28,12 @@ public class SettingsPreferences
addPreferencesFromResource(R.xml.preferences);
getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS);
+
prefLocale = (ListPreference) findPreference("pref_default_locale");
+ /**
Languages languages = Languages.get(this);
prefLocale.setEntries(languages.getAllNames());
- prefLocale.setEntryValues(languages.getSupportedLocales());
+ prefLocale.setEntryValues(languages.getSupportedLocales());**/
prefLocale.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
@@ -51,4 +55,11 @@ public class SettingsPreferences
super.attachBaseContext(LocaleHelper.onAttach(base));
}
+ @Override
+ protected void onPause() {
+ Language.setFromPreference(this, "pref_default_locale", true);
+
+ super.onPause();
+ }
+
}
diff --git a/app/src/main/res/xml-fa/preferences.xml b/app/src/main/res/xml-fa/preferences.xml
index ebdc3dc6..3ad8a086 100644
--- a/app/src/main/res/xml-fa/preferences.xml
+++ b/app/src/main/res/xml-fa/preferences.xml
@@ -1,7 +1,16 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_general_group">
-<CheckBoxPreference
+
+ <im.delight.android.languages.LanguagePreference
+ android:key="pref_default_locale"
+ android:title="@string/set_locale_title"
+ android:enabled="true"
+ android:selectable="true"
+ android:defaultValue="fa"
+ />
+
+ <CheckBoxPreference
android:defaultValue="true"
android:key="pref_start_boot"
android:title="@string/pref_start_boot_title"
@@ -27,12 +36,12 @@ android:defaultValue="true"
android:key="pref_allow_background_starts"
android:summary="@string/pref_allow_background_starts_summary"
android:title="@string/pref_allow_background_starts_title"/>
-
+<!--
<ListPreference android:title="@string/set_locale_title"
android:key="pref_default_locale"
android:summary="@string/set_locale_summary"
android:defaultValue="fa">
- </ListPreference>
+ </ListPreference>-->
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_node_configuration"
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
index 322db8f3..194d6f1a 100644
--- a/app/src/main/res/xml/preferences.xml
+++ b/app/src/main/res/xml/preferences.xml
@@ -1,6 +1,12 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/pref_general_group">
+ <im.delight.android.languages.LanguagePreference
+ android:key="pref_default_locale"
+ android:title="@string/set_locale_title"
+ android:enabled="true"
+ android:selectable="true" />
+
<CheckBoxPreference
android:defaultValue="true"
android:enabled="true"
@@ -34,11 +40,12 @@
android:summary="@string/pref_open_proxy_on_all_interfaces_summary"
android:title="@string/pref_open_proxy_on_all_interfaces_title" />
+ <!--
<ListPreference
android:defaultValue="en"
android:key="pref_default_locale"
android:summary="@string/set_locale_summary"
- android:title="@string/set_locale_title" />
+ android:title="@string/set_locale_title" />-->
</PreferenceCategory>
<!--
More information about the tor-commits
mailing list