updates for manually setting locales

This commit is contained in:
Nathan Freitas 2012-02-24 00:13:27 -05:00
parent b4952ea44d
commit 3a9a269296
5 changed files with 68 additions and 4 deletions

View File

@ -260,4 +260,8 @@
<string name="notification_using_bridges">Bridges enabled!</string> <string name="notification_using_bridges">Bridges enabled!</string>
<string name="default_bridges"></string> <string name="default_bridges"></string>
<string name="set_locale_title">Set Locale</string>
<string name="set_locale_summary">Choose the locale and language for Orbot</string>
</resources> </resources>

View File

@ -23,6 +23,15 @@ android:summary="@string/pref_use_persistent_notifications"
android:enabled="true" android:enabled="true"
android:title="@string/pref_use_persistent_notifications_title"/> android:title="@string/pref_use_persistent_notifications_title"/>
<ListPreference android:title="@string/set_locale_title"
android:key="pref_default_locale"
android:entryValues="@array/languages_values"
android:entries="@array/languages"
android:summary="@string/set_locale_summary"
android:defaultValue="en">
</ListPreference>
<!-- <!--
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
@ -92,12 +101,12 @@ android:summary="@string/use_only_these_specified_nodes"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/bridges"> <PreferenceCategory android:title="@string/bridges">
<CheckBoxPreference android:defaultValue="true" <CheckBoxPreference android:defaultValue="false"
android:title="@string/use_bridges" android:key="pref_bridges_enabled" android:title="@string/use_bridges" android:key="pref_bridges_enabled"
android:summary="@string/enable_alternate_entrance_nodes_into_the_tor_network"/> android:summary="@string/enable_alternate_entrance_nodes_into_the_tor_network"/>
<CheckBoxPreference android:key="pref_bridges_obfuscated" <CheckBoxPreference android:key="pref_bridges_obfuscated"
android:defaultValue="true" android:defaultValue="false"
android:title="@string/bridges_obfuscated" android:title="@string/bridges_obfuscated"
android:summary="@string/enable_if_configured_bridges_are_obfuscated_bridges"/> android:summary="@string/enable_if_configured_bridges_are_obfuscated_bridges"/>

View File

@ -3,6 +3,8 @@
package org.torproject.android; package org.torproject.android;
import java.util.Locale;
import org.torproject.android.service.ITorService; import org.torproject.android.service.ITorService;
import org.torproject.android.service.ITorServiceCallback; import org.torproject.android.service.ITorServiceCallback;
import org.torproject.android.service.TorServiceConstants; import org.torproject.android.service.TorServiceConstants;
@ -22,6 +24,7 @@ import android.content.ServiceConnection;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Configuration;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
@ -74,6 +77,7 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
//might want to look at whether we need to call this every time //might want to look at whether we need to call this every time
//or whether binding to the service is enough //or whether binding to the service is enough
setLocale();
bindService(); bindService();
startService(new Intent(INTENT_TOR_SERVICE)); startService(new Intent(INTENT_TOR_SERVICE));
@ -342,6 +346,8 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
setLocale();
if (getIntent() == null) if (getIntent() == null)
return; return;
@ -897,4 +903,22 @@ public class Orbot extends Activity implements OnLongClickListener, TorConstants
} }
private void setLocale ()
{
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getResources().getConfiguration();
String lang = settings.getString(PREF_DEFAULT_LOCALE, "");
if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang))
{
Locale locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
}
}
} }

View File

@ -12,12 +12,13 @@ public class OrbotApp extends Application implements TorConstants
private Locale locale; private Locale locale;
private final static String DEFAULT_LOCALE = "en"; private final static String DEFAULT_LOCALE = "en";
private SharedPreferences settings;
@Override @Override
public void onCreate() { public void onCreate() {
super.onCreate(); super.onCreate();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getResources().getConfiguration(); Configuration config = getResources().getConfiguration();
@ -38,8 +39,11 @@ public class OrbotApp extends Application implements TorConstants
{ {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
if (locale != null) String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE);
if (! "".equals(lang) && ! newConfig.locale.getLanguage().equals(lang))
{ {
locale = new Locale(lang);
newConfig.locale = locale; newConfig.locale = locale;
Locale.setDefault(locale); Locale.setDefault(locale);
getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics()); getResources().updateConfiguration(newConfig, getResources().getDisplayMetrics());

View File

@ -3,6 +3,8 @@
package org.torproject.android.settings; package org.torproject.android.settings;
import java.util.Locale;
import org.torproject.android.R; import org.torproject.android.R;
import org.torproject.android.R.xml; import org.torproject.android.R.xml;
import org.torproject.android.TorConstants; import org.torproject.android.TorConstants;
@ -12,6 +14,7 @@ import org.torproject.android.service.TorTransProxy;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor; import android.content.SharedPreferences.Editor;
import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.Preference; import android.preference.Preference;
@ -31,6 +34,7 @@ public class SettingsPreferences
private Preference prefTransProxyApps = null; private Preference prefTransProxyApps = null;
private CheckBoxPreference prefHiddenServices = null; private CheckBoxPreference prefHiddenServices = null;
private CheckBoxPreference prefRequestRoot = null; private CheckBoxPreference prefRequestRoot = null;
private Preference prefLocale = null;
private boolean hasRoot = false; private boolean hasRoot = false;
@ -61,11 +65,16 @@ public class SettingsPreferences
super.onResume(); super.onResume();
int REQUEST_ROOT_IDX = 1; int REQUEST_ROOT_IDX = 1;
int SET_LOCALE_IDX = 3;
int GENERAL_GROUP_IDX = 0; int GENERAL_GROUP_IDX = 0;
prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(REQUEST_ROOT_IDX)); prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(REQUEST_ROOT_IDX));
prefRequestRoot.setOnPreferenceClickListener(this); prefRequestRoot.setOnPreferenceClickListener(this);
prefLocale = (((PreferenceCategory)getPreferenceScreen().getPreference(GENERAL_GROUP_IDX)).getPreference(SET_LOCALE_IDX));
prefLocale.setOnPreferenceClickListener(this);
prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0)); prefCBTransProxy = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0));
prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(1); prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(1);
prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2); prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2);
@ -154,6 +163,20 @@ public class SettingsPreferences
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked()); ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(1).setEnabled(prefHiddenServices.isChecked());
((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked()); ((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(2).setEnabled(prefHiddenServices.isChecked());
}
else if (preference == prefLocale)
{
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
Configuration config = getResources().getConfiguration();
String lang = settings.getString("pref_default_locale", "");
Locale locale = new Locale(lang);
Locale.setDefault(locale);
config.locale = locale;
getResources().updateConfiguration(config, getResources().getDisplayMetrics());
} }
else else
{ {