diff --git a/.tx/config b/.tx/config new file mode 100644 index 00000000..44d0e0a4 --- /dev/null +++ b/.tx/config @@ -0,0 +1,10 @@ +[main] +host = https://www.transifex.com +lang_map = af_ZA: af-rZA, am_ET: am-rET, ar_AE: ar-rAE, ar_BH: ar-rBH, ar_DZ: ar-rDZ, ar_EG: ar-rEG, ar_IQ: ar-rIQ, ar_JO: ar-rJO, ar_KW: ar-rKW, ar_LB: ar-rLB, ar_LY: ar-rLY, ar_MA: ar-rMA, ar_OM: ar-rOM, ar_QA: ar-rQA, ar_SA: ar-rSA, ar_SY: ar-rSY, ar_TN: ar-rTN, ar_YE: ar-rYE, arn_CL: arn-rCL, as_IN: as-rIN, az_AZ: az-rAZ, ba_RU: ba-rRU, be_BY: be-rBY, bg_BG: bg-rBG, bn_BD: bn-rBD, bn_IN: bn-rIN, bo_CN: bo-rCN, br_FR: br-rFR, bs_BA: bs-rBA, ca_ES: ca-rES, co_FR: co-rFR, cs_CZ: cs-rCZ, cy_GB: cy-rGB, da_DK: da-rDK, de_AT: de-rAT, de_CH: de-rCH, de_DE: de-rDE, de_LI: de-rLI, de_LU: de-rLU, dsb_DE: dsb-rDE, dv_MV: dv-rMV, el_GR: el-rGR, en_AU: en-rAU, en_BZ: en-rBZ, en_CA: en-rCA, en_GB: en-rGB, en_IE: en-rIE, en_IN: en-rIN, en_JM: en-rJM, en_MY: en-rMY, en_NZ: en-rNZ, en_PH: en-rPH, en_SG: en-rSG, en_TT: en-rTT, en_US: en-rUS, en_ZA: en-rZA, en_ZW: en-rZW, es_AR: es-rAR, es_BO: es-rBO, es_CL: es-rCL, es_CO: es-rCO, es_CR: es-rCR, es_DO: es-rDO, es_EC: es-rEC, es_ES: es-rES, es_GT: es-rGT, es_HN: es-rHN, es_MX: es-rMX, es_NI: es-rNI, es_PA: es-rPA, es_PE: es-rPE, es_PR: es-rPR, es_PY: es-rPY, es_SV: es-rSV, es_US: es-rUS, es_UY: es-rUY, es_VE: es-rVE, et_EE: et-rEE, eu_ES: eu-rES, fa_IR: fa-rIR, fi_FI: fi-rFI, fil: tl, fil_PH: tl-rPH, fo_FO: fo-rFO, fr_BE: fr-rBE, fr_CA: fr-rCA, fr_CH: fr-rCH, fr_FR: fr-rFR, fr_LU: fr-rLU, fr_MC: fr-rMC, fy_NL: fy-rNL, ga_IE: ga-rIE, gd_GB: gd-rGB, gl_ES: gl-rES, gsw_FR: gsw-rFR, gu_IN: gu-rIN, ha_NG: ha-rNG, he: iw, he_IL: iw-rIL, hi_IN: hi-rIN, hr_BA: hr-rBA, hr_HR: hr-rHR, hsb_DE: hsb-rDE, hu_HU: hu-rHU, hy_AM: hy-rAM, id: in, id_ID: in-rID, ig_NG: ig-rNG, ii_CN: ii-rCN, is_IS: is-rIS, it_CH: it-rCH, it_IT: it-rIT, iu_CA: iu-rCA, ja_JP: ja-rJP, ka_GE: ka-rGE, kk_KZ: kk-rKZ, kl_GL: kl-rGL, km_KH: km-rKH, kn_IN: kn-rIN, ko_KR: ko-rKR, kok_IN: kok-rIN, ky_KG: ky-rKG, lb_LU: lb-rLU, lo_LA: lo-rLA, lt_LT: lt-rLT, lv_LV: lv-rLV, mi_NZ: mi-rNZ, mk_MK: mk-rMK, ml_IN: ml-rIN, mn_CN: mn-rCN, mn_MN: mn-rMN, moh_CA: moh-rCA, mr_IN: mr-rIN, ms_BN: ms-rBN, ms_MY: ms-rMY, mt_MT: mt-rMT, nb_NO: nb-rNO, ne_NP: ne-rNP, nl_BE: nl-rBE, nl_NL: nl-rNL, nn_NO: nn-rNO, nso_ZA: nso-rZA, oc_FR: oc-rFR, or_IN: or-rIN, pa_IN: pa-rIN, pl_PL: pl-rPL, prs_AF: prs-rAF, ps_AF: ps-rAF, pt_BR: pt-rBR, pt_PT: pt-rPT, qut_GT: qut-rGT, quz_BO: quz-rBO, quz_EC: quz-rEC, quz_PE: quz-rPE, rm_CH: rm-rCH, ro_RO: ro-rRO, ru_RU: ru-rRU, rw_RW: rw-rRW, sa_IN: sa-rIN, sah_RU: sah-rRU, se_FI: se-rFI, se_NO: se-rNO, se_SE: se-rSE, si_LK: si-rLK, sk_SK: sk-rSK, sl_SI: sl-rSI, sma_NO: sma-rNO, sma_SE: sma-rSE, smj_NO: smj-rNO, smj_SE: smj-rSE, smn_FI: smn-rFI, sms_FI: sms-rFI, sq_AL: sq-rAL, sr: sr, sv_FI: sv-rFI, sv_SE: sv-rSE, sw_KE: sw-rKE, syr_SY: syr-rSY, ta_IN: ta-rIN, te_IN: te-rIN, tg_TJ: tg-rTJ, th_TH: th-rTH, tk_TM: tk-rTM, tn_ZA: tn-rZA, tr_TR: tr-rTR, tt_RU: tt-rRU, tzm_DZ: tzm-rDZ, ug_CN: ug-rCN, uk_UA: uk-rUA, ur_PK: ur-rPK, uz_UZ: uz-rUZ, vi_VN: vi-rVN, wo_SN: wo-rSN, xh_ZA: xh-rZA, yo_NG: yo-rNG, zh: zh-rCN, zh_HK: zh-rHK, zh_MO: zh-rMO, zh_SG: zh-rSG, zh_TW: zh-rTW, zu_ZA: zu-rZA + +[orbot.stringsxml] +file_filter = res/values-/strings.xml +host = https://www.transifex.com +source_file = res/values/strings.xml +source_lang = en + diff --git a/res/values-bn-rBD/strings.xml b/res/values-bn-rBD/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-bn-rBD/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-de-rAT/strings.xml b/res/values-de-rAT/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-de-rAT/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-hi/strings.xml b/res/values-hi/strings.xml deleted file mode 100644 index 67d29c14..00000000 --- a/res/values-hi/strings.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - ब्राउज़ - सेटिंग्स - मदद - मदद - बंद करें - वापस - रद्द करें - - प्रोक्सी सेटींग - - समन्य - - - - - - - - - - - कोई नहीं - स्थिति - - diff --git a/res/values-hy-rAM/strings.xml b/res/values-hy-rAM/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-hy-rAM/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-id/strings.xml b/res/values-id/strings.xml deleted file mode 100644 index 914f6f21..00000000 --- a/res/values-id/strings.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - Orbot - http://orbot/ - http://check.torproject.org - https://check.torproject.org - https://check.torproject.org/?TorButton=true - mulai dan akhiri Tor - torproxyservice - Orbot sedang dimulai… - Tersambung ke Jaringan Tor - Orbot telah dibatalkan - Orbot sedang dimatikan - PERINGATAN: - Home - Jelajahi - Pengaturan - Log - Bantuan - Mengenai - Bantuan - Dekat - Mengenai - Hapus Log - Periksa - Keluar - Tor Semuanya - Daftar Port - Minta Akses Dasar - Kembali - Batal - - Pengaturan Proxy - - Umum - - - - Peringatan - - - - - - - - Tidak ada - Status - Kesalahan - - Simpan Pengaturan - diff --git a/res/values-id-rID/strings.xml b/res/values-in-rID/strings.xml similarity index 100% rename from res/values-id-rID/strings.xml rename to res/values-in-rID/strings.xml diff --git a/res/values-he/strings.xml b/res/values-iw/strings.xml similarity index 100% rename from res/values-he/strings.xml rename to res/values-iw/strings.xml diff --git a/res/values-kn-rIN/strings.xml b/res/values-kn-rIN/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-kn-rIN/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-kn/strings.xml b/res/values-kn/strings.xml deleted file mode 100644 index f7b900f8..00000000 --- a/res/values-kn/strings.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/res/values-ml/strings.xml b/res/values-ml/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-ml/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-mn-rMN/strings.xml b/res/values-mn-rMN/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-mn-rMN/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-sn/strings.xml b/res/values-sn/strings.xml deleted file mode 100644 index 39b2be8e..00000000 --- a/res/values-sn/strings.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - Orbot - http://check.torproject.org - https://check.torproject.org - https://check.torproject.org/?TorButton=true - Zvamada - Maererano - Maererano - Buda - Maererano Orbot - - Proxy Zvamada - - - - - - - - - - - - - diff --git a/res/values-ta/strings.xml b/res/values-ta/strings.xml deleted file mode 100644 index 47b2a084..00000000 --- a/res/values-ta/strings.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - diff --git a/res/values-zh/strings.xml b/res/values-zh-rCN/strings.xml similarity index 100% rename from res/values-zh/strings.xml rename to res/values-zh-rCN/strings.xml diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 00eb3a43..09ed951b 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1,43 +1,7 @@ - - - Default - English - العربية - فارسی - 中文(简体) - Deutsche - Español - Français - Italian - Nederlands - Magyar - Português - Português Brasileiro - русский язык - - - - xx - en - ar - fa - zh - de - es - fr - it - nl - hu - pt - pt_BR - ru - - - - + Obfs4 (Recommended) Obfs3 diff --git a/res/values/strings.xml b/res/values/strings.xml index 0f98f5ef..e5b4cd35 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -236,7 +236,7 @@ Bridges enabled! - Set Locale + Language Choose the locale and language for Orbot Choose Language Leave default or switch the current language diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 3778dd6f..d910fee2 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -25,8 +25,6 @@ android:title="@string/pref_use_expanded_notifications_title"/> diff --git a/src/info/guardianproject/util/Languages.java b/src/info/guardianproject/util/Languages.java new file mode 100644 index 00000000..b776f758 --- /dev/null +++ b/src/info/guardianproject/util/Languages.java @@ -0,0 +1,157 @@ + +package info.guardianproject.util; + +import android.app.Activity; +import android.content.res.AssetManager; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.text.TextUtils; +import android.util.DisplayMetrics; + +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.TreeMap; + +public class Languages { + private static final String TAG = "Languages"; + private static Languages singleton; + private static Map tmpMap = new TreeMap(); + private static Map nameMap; + public static final String USE_SYSTEM_DEFAULT = ""; + public static final Locale TIBETAN = new Locale("bo"); + static final Locale localesToTest[] = { + Locale.ENGLISH, Locale.FRENCH, Locale.GERMAN, + Locale.ITALIAN, Locale.JAPANESE, Locale.KOREAN, + Locale.TRADITIONAL_CHINESE, Locale.SIMPLIFIED_CHINESE, + TIBETAN, new Locale("af"), new Locale("am"), + new Locale("ar"), new Locale("az"), new Locale("bg"), + new Locale("bn"), new Locale("ca"), new Locale("cs"), + new Locale("da"), new Locale("el"), new Locale("es"), + new Locale("et"), new Locale("eu"), new Locale("fa"), + new Locale("fi"), new Locale("gl"), new Locale("hi"), + new Locale("hr"), new Locale("hu"), new Locale("hy"), + new Locale("in"), new Locale("hy"), new Locale("in"), + new Locale("is"), new Locale("it"), new Locale("iw"), + new Locale("ka"), new Locale("kk"), new Locale("km"), + new Locale("kn"), new Locale("ky"), new Locale("lo"), + new Locale("lt"), new Locale("lv"), new Locale("mk"), + new Locale("ml"), new Locale("mn"), new Locale("mr"), + new Locale("ms"), new Locale("my"), new Locale("nb"), + new Locale("ne"), new Locale("nl"), new Locale("pl"), + new Locale("pt"), new Locale("rm"), new Locale("ro"), + new Locale("ru"), new Locale("si"), new Locale("sk"), + new Locale("sl"), new Locale("sn"), new Locale("sr"), + new Locale("sv"), new Locale("sw"), new Locale("ta"), + new Locale("te"), new Locale("th"), new Locale("tl"), + new Locale("tr"), new Locale("uk"), new Locale("ur"), + new Locale("uz"), new Locale("vi"), new Locale("zu"), + }; + + private Languages(Activity activity, int resId, String defaultString) { + AssetManager assets = activity.getAssets(); + Configuration config = activity.getResources().getConfiguration(); + DisplayMetrics metrics = new DisplayMetrics(); + activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); + Resources resources; + Set localeSet = new LinkedHashSet(); + for (Locale locale : localesToTest) { + config.locale = locale; + resources = new Resources(assets, metrics, config); + if (!TextUtils.equals(defaultString, resources.getString(resId)) + || locale.equals(Locale.ENGLISH)) + localeSet.add(locale); + } + for (Locale locale : localeSet) { + if (locale.equals(TIBETAN)) { + // include English name for devices that don't support Tibetan + // font + tmpMap.put(TIBETAN.getLanguage(), "Tibetan བོད་སྐད།"); // Tibetan + } else if (locale.equals(Locale.SIMPLIFIED_CHINESE)) { + tmpMap.put(Locale.SIMPLIFIED_CHINESE.toString(), "中文 (中国)"); // Chinese + // (China) + } else if (locale.equals(Locale.TRADITIONAL_CHINESE)) { + tmpMap.put(Locale.TRADITIONAL_CHINESE.toString(), "中文 (台灣)"); // Chinese + // (Taiwan) + } else { + tmpMap.put(locale.getLanguage(), locale.getDisplayLanguage(locale)); + } + } + // TODO implement this completely, the menu item works, but doesn't work + // properly + /* USE_SYSTEM_DEFAULT is a fake one for displaying in a chooser menu. */ + // localeSet.add(null); + // tmpMap.put(USE_SYSTEM_DEFAULT, + // activity.getString(R.string.use_system_default)); + nameMap = Collections.unmodifiableMap(tmpMap); + } + + /** + * Get the instance of {@link Languages} to work with, providing the + * {@link Activity} that is will be working as part of. This uses the + * provided string resource {@code resId} find the supported translations: + * if an included translation has a translated string that matches that + * {@code resId}, i.e. {@code R.string.menu_settings}, then that language + * will be included as a supported language. + * + * @param activity the {@link Activity} this is working as part of + * @param resId the string resource ID to test, e.g. + * {@code R.string.menu_settings} + * @param defaultString the string resource in the default language, e.g. + * {@code "Settings"} + * @return + */ + public static Languages get(Activity activity, int resId, String defaultString) { + if (singleton == null) + singleton = new Languages(activity, resId, defaultString); + return singleton; + } + + /** + * Return the name of the language based on the locale. + * + * @param locale + * @return + */ + public String getName(String locale) { + String ret = nameMap.get(locale); + // if no match, try to return a more general name (i.e. English for + // en_IN) + if (ret == null && locale.contains("_")) + ret = nameMap.get(locale.split("_")[0]); + return ret; + } + + /** + * Return an array of the names of all the supported languages, sorted to + * match what is returned by {@link Languages#getSupportedLocales()}. + * + * @return + */ + public String[] getAllNames() { + 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. + * + * @return + */ + public String[] getSupportedLocales() { + Set keys = nameMap.keySet(); + return keys.toArray(new String[keys.size()]); + } +} diff --git a/src/org/torproject/android/OrbotApp.java b/src/org/torproject/android/OrbotApp.java index 4e6d9ec6..070d7d73 100644 --- a/src/org/torproject/android/OrbotApp.java +++ b/src/org/torproject/android/OrbotApp.java @@ -1,68 +1,90 @@ + package org.torproject.android; -import java.util.Locale; +import android.annotation.TargetApi; +import android.app.Activity; +import android.app.Application; +import android.content.Intent; +import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; +import android.content.res.Configuration; +import android.os.Build; +import android.text.TextUtils; +import android.util.Log; + +import info.guardianproject.util.Languages; import org.torproject.android.service.TorServiceUtils; -import android.app.Application; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.preference.PreferenceManager; +import java.util.Locale; public class OrbotApp extends Application implements OrbotConstants { - private Locale locale; - private final static String DEFAULT_LOCALE = "en"; - private SharedPreferences settings; - - @Override + private Locale locale; + private SharedPreferences prefs; + + @Override public void onCreate() { super.onCreate(); - - settings = TorServiceUtils.getSharedPrefs(getApplicationContext()); - Configuration config = getResources().getConfiguration(); - - String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE); - - if (! "".equals(lang) && ! config.locale.getLanguage().equals(lang)) - { - if (lang.equals("xx")) - { - locale = Locale.getDefault(); - - } - else - locale = new Locale(lang); - - Locale.setDefault(locale); - - Configuration myConfig = new Configuration(config); - myConfig.locale = locale; - - getResources().updateConfiguration(myConfig, getResources().getDisplayMetrics()); - } - - + prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); + setNewLocale(prefs.getString(PREF_DEFAULT_LOCALE, Locale.getDefault().getLanguage())); } - + @Override - public void onConfigurationChanged(Configuration newConfig) - { + public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); + Log.i(TAG, "onConfigurationChanged " + newConfig.locale.getLanguage()); + setNewLocale(prefs.getString(PREF_DEFAULT_LOCALE, Locale.getDefault().getLanguage())); + } - String lang = settings.getString(PREF_DEFAULT_LOCALE, DEFAULT_LOCALE); + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) + public void setNewLocale(String language) { + if (TextUtils.isEmpty(language)) + return; - if (! "".equals(lang) && ! newConfig.locale.getLanguage().equals(lang)) - { - locale = new Locale(lang); - Locale.setDefault(locale); - - Configuration myConfig = new Configuration(newConfig); - myConfig.locale = locale; - - getResources().updateConfiguration(myConfig, getResources().getDisplayMetrics()); - } + if (locale != null && TextUtils.equals(locale.getLanguage(), language)) + return; // already configured + + /* handle locales with the country in it, i.e. zh_CN, zh_TW, etc */ + String localeSplit[] = language.split("_"); + if (localeSplit.length > 1) + locale = new Locale(localeSplit[0], localeSplit[1]); + else + locale = new Locale(language); + Configuration config = getResources().getConfiguration(); + if (Build.VERSION.SDK_INT >= 17) + config.setLocale(locale); + else + config.locale = locale; + getResources().updateConfiguration(config, getResources().getDisplayMetrics()); + + /* + * Set the preference after setting the locale in case something goes + * wrong. If setting the locale causes an Exception, it should be set in + * the preferences, otherwise ChatSecure will be stuck in a crash loop. + */ + SharedPreferences prefs = TorServiceUtils.getSharedPrefs(this); + Editor prefEdit = prefs.edit(); + prefEdit.putString(PREF_DEFAULT_LOCALE, language); + prefEdit.apply(); + Log.i(TAG, "setNewLocale complete: locale: " + locale.getLanguage() + + " Locale.getDefault: " + Locale.getDefault().getLanguage()); + } + + public static void forceChangeLanguage(Activity activity) { + Intent intent = activity.getIntent(); + if (intent == null) // when launched as LAUNCHER + intent = new Intent(activity, OrbotMainActivity.class); + intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION); + activity.finish(); + activity.overridePendingTransition(0, 0); + activity.startActivity(intent); + activity.overridePendingTransition(0, 0); + } + + public static Languages getLanguages(Activity activity) { + return Languages.get(activity, R.string.menu_settings, "Settings"); } } diff --git a/src/org/torproject/android/OrbotMainActivity.java b/src/org/torproject/android/OrbotMainActivity.java index bf9791f1..786849a8 100644 --- a/src/org/torproject/android/OrbotMainActivity.java +++ b/src/org/torproject/android/OrbotMainActivity.java @@ -75,7 +75,6 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon private MenuItem mItemOnOff = null; private TextView downloadText = null; private TextView uploadText = null; - private NumberFormat mNumberFormat = null; private TextView mTxtOrbotLog = null; private Button mBtnBrowser = null; @@ -96,6 +95,7 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon private final static long INIT_DELAY = 100; private final static int REQUEST_VPN = 8888; + private final static int REQUEST_SETTINGS = 0x9874; /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { @@ -103,8 +103,6 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon mPrefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); mPrefs.registerOnSharedPreferenceChangeListener(this); - - setLocale(); doLayout(); @@ -391,7 +389,8 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon if (item.getItemId() == R.id.menu_settings) { - showSettings(); + Intent intent = new Intent(OrbotMainActivity.this, SettingsPreferences.class); + startActivityForResult(intent, REQUEST_SETTINGS); } else if (item.getItemId() == R.id.menu_wizard) { @@ -473,10 +472,6 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon } - /* (non-Javadoc) -<<<<<<< HEAD:src/org/torproject/android/OrbotMainActivity.java - * @see android.app.Activity#onPause() - */ protected void onPause() { try { @@ -572,6 +567,8 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon // Get intent, action and MIME type Intent intent = getIntent(); String action = intent.getAction(); + Log.e(TAG, "handleIntents " + action); + String type = intent.getType(); if (action == null) @@ -620,21 +617,24 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon else if (action.equals("org.torproject.android.START_TOR")) { autoStartFromIntent = true; - - try { - startTor(); + try { + Log.i(TAG, "action equals org.torproject.android.START_TOR"); + startTor(); + + Intent resultIntent = new Intent(intent); + resultIntent.putExtra("socks_proxy", "socks://127.0.0.1:" + TorServiceConstants.PORT_SOCKS_DEFAULT); + resultIntent.putExtra("socks_proxy_host", "127.0.0.1"); + resultIntent.putExtra("socks_proxy_port", TorServiceConstants.PORT_SOCKS_DEFAULT); + resultIntent.putExtra("http_proxy", "http://127.0.0.1" + TorServiceConstants.PORT_HTTP); + resultIntent.putExtra("http_proxy_host", "127.0.0.1"); + resultIntent.putExtra("http_proxy_port", TorServiceConstants.PORT_HTTP); + setResult(RESULT_OK, resultIntent); + finish(); + } catch (RemoteException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } - Intent nResult = new Intent(); - - //nResult.putExtra("socks", ); //TODO respond with socks, transport, dns, etc - - setResult(RESULT_OK,nResult); - - } catch (RemoteException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } else if (action.equals(Intent.ACTION_VIEW)) { @@ -806,25 +806,15 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon { return false; } - } - - /* - * Load the basic settings application to display torrc - */ - private void showSettings () - { - - startActivityForResult(new Intent(this, SettingsPreferences.class), 1); - } - + } @Override protected void onActivityResult(int request, int response, Intent data) { super.onActivityResult(request, response, data); - - - if (request == 1 && response == RESULT_OK) + + if (request == REQUEST_SETTINGS && response == RESULT_OK) { + OrbotApp.forceChangeLanguage(this); if (data != null && data.getBooleanExtra("transproxywipe", false)) { @@ -1162,13 +1152,11 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon boolean useBridges = mPrefs.getBoolean("pref_bridges_enabled", false); mBtnBridges.setChecked(useBridges); } - + mHandler.postDelayed(new Runnable () { public void run () { - - setLocale(); handleIntents(); @@ -1253,13 +1241,12 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon } - if (autoStartFromIntent) { - setResult(RESULT_OK); + autoStartFromIntent = false; finish(); + Log.e(TAG, "autoStartFromIntent finish"); } - } else if (torStatus == TorServiceConstants.STATUS_CONNECTING) { @@ -1430,33 +1417,6 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon }; - - /** - * Class for interacting with the main interface of the service. - */ - // this is the connection that gets called back when a successfull bind occurs - // we should use this to activity monitor unbind so that we don't have to call - // bindService() a million times - - private void setLocale () - { - - - Configuration config = getResources().getConfiguration(); - String lang = mPrefs.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()); - } - - mNumberFormat = NumberFormat.getInstance(Locale.getDefault()); - - } - @Override protected void onDestroy() { super.onDestroy(); @@ -1476,31 +1436,32 @@ public class OrbotMainActivity extends Activity implements OrbotConstants, OnLon } } - private String formatCount(long count) { + private String formatCount(long count) { + NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault()); // Converts the supplied argument into a string. // Under 2Mb, returns "xxx.xKb" // Over 2Mb, returns "xxx.xxMb" - - //Locale.getDefault(); - if (count < 1e6) - return mNumberFormat.format(Math.round(((float)((int)(count*10/1024))/10))) + getString(R.string.kbps); - - return mNumberFormat.format(Math.round(((float)((int)(count*100/1024/1024))/100))) + getString(R.string.mbps); - - //return count+" kB"; + return numberFormat.format(Math.round(((float) ((int) (count * 10 / 1024)) / 10))) + + getString(R.string.kbps); + else + return numberFormat.format(Math + .round(((float) ((int) (count * 100 / 1024 / 1024)) / 100))) + + getString(R.string.mbps); } - - private String formatTotal(long count) { + + private String formatTotal(long count) { + NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault()); // Converts the supplied argument into a string. // Under 2Mb, returns "xxx.xKb" // Over 2Mb, returns "xxx.xxMb" if (count < 1e6) - return mNumberFormat.format(Math.round(((float)((int)(count*10/1024))/10))) + getString(R.string.kb); - - return mNumberFormat.format(Math.round(((float)((int)(count*100/1024/1024))/100))) + getString(R.string.mb); - - //return count+" kB"; + return numberFormat.format(Math.round(((float) ((int) (count * 10 / 1024)) / 10))) + + getString(R.string.kb); + else + return numberFormat.format(Math + .round(((float) ((int) (count * 100 / 1024 / 1024)) / 100))) + + getString(R.string.mb); } @Override diff --git a/src/org/torproject/android/settings/SettingsPreferences.java b/src/org/torproject/android/settings/SettingsPreferences.java index 339514ac..5c02d2be 100644 --- a/src/org/torproject/android/settings/SettingsPreferences.java +++ b/src/org/torproject/android/settings/SettingsPreferences.java @@ -3,141 +3,116 @@ package org.torproject.android.settings; -import java.util.Locale; - -import org.sufficientlysecure.rootcommands.RootCommands; -import org.sufficientlysecure.rootcommands.Shell; -import org.torproject.android.R; -import org.torproject.android.service.TorServiceUtils; - import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.content.res.Configuration; import android.os.Bundle; import android.preference.CheckBoxPreference; +import android.preference.EditTextPreference; +import android.preference.ListPreference; import android.preference.Preference; +import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceClickListener; import android.preference.PreferenceActivity; -import android.preference.PreferenceCategory; import android.widget.Toast; +import info.guardianproject.util.Languages; + +import org.sufficientlysecure.rootcommands.RootCommands; +import org.sufficientlysecure.rootcommands.Shell; +import org.torproject.android.OrbotApp; +import org.torproject.android.R; +import org.torproject.android.service.TorServiceUtils; + +import java.util.Locale; + public class SettingsPreferences extends PreferenceActivity implements OnPreferenceClickListener { + private static final String TAG = "SettingsPreferences"; private CheckBoxPreference prefCBTransProxy = null; private CheckBoxPreference prefcBTransProxyAll = null; private Preference prefTransProxyFlush = null; private Preference prefTransProxyApps = null; - private CheckBoxPreference prefHiddenServices = null; + private CheckBoxPreference prefHiddenServices = null; + private EditTextPreference prefHiddenServicesPorts; + private EditTextPreference prefHiddenServicesHostname; private CheckBoxPreference prefRequestRoot = null; - private Preference prefLocale = null; + private ListPreference prefLocale = null; - private boolean hasRoot = false; + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - private final static int HIDDEN_SERVICE_PREF_IDX = 6; - private final static int TRANSPROXY_GROUP_IDX = 1; - private final static int DEBUG_GROUP_IDX = 8; - - - protected void onCreate(Bundle savedInstanceState) - { - super.onCreate(savedInstanceState); - - addPreferencesFromResource(R.xml.preferences); - getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); - SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); - - hasRoot = prefs.getBoolean("has_root",false); - - init(); - } - - - @Override - protected void onResume() { - - super.onResume(); - - } - - private void init () - { - int SET_LOCALE_IDX = 3; + addPreferencesFromResource(R.xml.preferences); + getPreferenceManager().setSharedPreferencesMode(Context.MODE_MULTI_PROCESS); + SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); - int GENERAL_GROUP_IDX = 0; - - prefRequestRoot = ((CheckBoxPreference)((PreferenceCategory)getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(0)); - prefRequestRoot.setOnPreferenceClickListener(this); + prefRequestRoot = (CheckBoxPreference) findPreference("has_root"); + 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(1)); - prefcBTransProxyAll = (CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(2); - - prefTransProxyFlush = (Preference)((PreferenceCategory)this.getPreferenceScreen().getPreference(DEBUG_GROUP_IDX)).getPreference(8); - prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() { + prefLocale = (ListPreference) findPreference("pref_default_locale"); + prefLocale.setOnPreferenceClickListener(this); + Languages languages = Languages.get(this, R.string.menu_settings, "Settings"); + prefLocale.setEntries(languages.getAllNames()); + prefLocale.setEntryValues(languages.getSupportedLocales()); + prefLocale.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { - @Override - public boolean onPreferenceClick(Preference arg0) { - - Intent data = new Intent(); - data.putExtra("transproxywipe", true); - setResult(RESULT_OK,data); - - finish(); - return false; - } - - }); - - prefTransProxyApps = ((PreferenceCategory)this.getPreferenceScreen().getPreference(TRANSPROXY_GROUP_IDX)).getPreference(3); + @Override + public boolean onPreferenceChange(Preference preference, Object newValue) { + String language = (String) newValue; + if (preference == prefLocale) { + SharedPreferences settings = TorServiceUtils + .getSharedPrefs(getApplicationContext()); + String lang = settings.getString("pref_default_locale", + Locale.getDefault().getLanguage()); + OrbotApp app = (OrbotApp) getApplication(); + app.setNewLocale(language); + lang = settings.getString("pref_default_locale", + Locale.getDefault().getLanguage()); + OrbotApp.forceChangeLanguage(SettingsPreferences.this); + } + return false; + } + }); - prefCBTransProxy.setOnPreferenceClickListener(this); - prefcBTransProxyAll.setOnPreferenceClickListener(this); - prefTransProxyApps.setOnPreferenceClickListener(this); - - prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked()); - prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() && (!prefcBTransProxyAll.isChecked())); - - - prefHiddenServices = ((CheckBoxPreference)((PreferenceCategory)this.getPreferenceScreen().getPreference(HIDDEN_SERVICE_PREF_IDX)).getPreference(0)); - prefHiddenServices.setOnPreferenceClickListener(this); - ((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()); - - - }; - - - - - @Override - protected void onPause() { + prefCBTransProxy = (CheckBoxPreference) findPreference("pref_transparent"); + prefcBTransProxyAll = (CheckBoxPreference) findPreference("pref_transparent_all"); - super.onPause(); - + prefTransProxyFlush = (Preference) findPreference("pref_transproxy_flush"); + prefTransProxyFlush.setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override + public boolean onPreferenceClick(Preference arg0) { - - - - - } + Intent data = new Intent(); + data.putExtra("transproxywipe", true); + setResult(RESULT_OK, data); + finish(); + return false; + } - /* (non-Javadoc) - * @see android.app.Activity#onStop() - */ - @Override - protected void onStop() { - super.onStop(); - - } + }); + + prefTransProxyApps = findPreference("pref_transparent_app_list"); + prefTransProxyApps.setOnPreferenceClickListener(this); + prefTransProxyApps.setEnabled(prefCBTransProxy.isChecked() + && (!prefcBTransProxyAll.isChecked())); + + prefCBTransProxy.setOnPreferenceClickListener(this); + prefcBTransProxyAll.setOnPreferenceClickListener(this); + prefcBTransProxyAll.setEnabled(prefCBTransProxy.isChecked()); + + prefHiddenServices = (CheckBoxPreference) findPreference("pref_hs_enable"); + prefHiddenServices.setOnPreferenceClickListener(this); + prefHiddenServicesPorts = (EditTextPreference) findPreference("pref_hs_ports"); + prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked()); + prefHiddenServicesHostname = (EditTextPreference) findPreference("pref_hs_hostname"); + prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked()); + } public boolean onPreferenceClick(Preference preference) { @@ -175,33 +150,8 @@ public class SettingsPreferences } else if (preference == prefHiddenServices) { - - ((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()); - - } - else if (preference == prefLocale) - { - SharedPreferences settings = TorServiceUtils.getSharedPrefs(getApplicationContext()); - - Configuration config = getResources().getConfiguration(); - - String lang = settings.getString("pref_default_locale", ""); - - Locale locale; - - if (lang.equals("xx")) - { - locale = Locale.getDefault(); - - } - else - locale = new Locale(lang); - - Locale.setDefault(locale); - config.locale = locale; - getResources().updateConfiguration(config, getResources().getDisplayMetrics()); - + prefHiddenServicesPorts.setEnabled(prefHiddenServices.isChecked()); + prefHiddenServicesHostname.setEnabled(prefHiddenServices.isChecked()); } else { diff --git a/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java b/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java index 2c5470c9..a804f45c 100644 --- a/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java +++ b/src/org/torproject/android/ui/wizard/ChooseLocaleWizardActivity.java @@ -1,11 +1,5 @@ package org.torproject.android.ui.wizard; -import java.util.Locale; - -import org.torproject.android.R; -import org.torproject.android.OrbotConstants; -import org.torproject.android.service.TorServiceUtils; - import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; @@ -21,38 +15,39 @@ import android.widget.Button; import android.widget.ListView; import android.widget.Toast; +import info.guardianproject.util.Languages; + +import org.torproject.android.OrbotApp; +import org.torproject.android.OrbotConstants; +import org.torproject.android.R; +import org.torproject.android.service.TorServiceUtils; + +import java.util.Locale; + public class ChooseLocaleWizardActivity extends Activity implements OrbotConstants { - private int flag = 0; private ListView listLocales; + private String[] localeValues; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - - } - - @Override - protected void onStart() { - - super.onStart(); + setContentView(R.layout.layout_wizard_locale); - - + listLocales = (ListView)findViewById(R.id.wizard_locale_list); Button next = ((Button)findViewById(R.id.btnWizard2)); // next.setEnabled(false); - String[] strLangs = getResources().getStringArray(R.array.languages); - strLangs[0] = Locale.getDefault().getDisplayName(); - ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, android.R.id.text1, strLangs); + Languages languages = OrbotApp.getLanguages(this); + localeValues = languages.getSupportedLocales(); + ArrayAdapter adapter = new ArrayAdapter(this, + android.R.layout.simple_list_item_1, android.R.id.text1, + languages.getAllNames()); listLocales.setAdapter(adapter); - + listLocales.setSelection(0); - - listLocales.setOnItemClickListener(new OnItemClickListener() { - @Override public void onItemClick(AdapterView arg0, View arg1, @@ -61,7 +56,6 @@ public class ChooseLocaleWizardActivity extends Activity implements OrbotConstan setLocalePref(arg2); finish(); startActivity(new Intent(ChooseLocaleWizardActivity.this, PromoAppsActivity.class)); - } }); @@ -74,21 +68,15 @@ public class ChooseLocaleWizardActivity extends Activity implements OrbotConstan } }); - - - } private void setLocalePref(int selId) { - SharedPreferences prefs = TorServiceUtils.getSharedPrefs(getApplicationContext()); Configuration config = getResources().getConfiguration(); - - String[] localeVals = getResources().getStringArray(R.array.languages_values); - String lang = localeVals[selId]; + String lang = localeValues[selId]; Editor pEdit = prefs.edit(); pEdit.putString(PREF_DEFAULT_LOCALE, lang); @@ -106,21 +94,6 @@ public class ChooseLocaleWizardActivity extends Activity implements OrbotConstan Locale.setDefault(locale); config.locale = locale; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); - - - - - } - - @Override - protected void onRestoreInstanceState(Bundle savedInstanceState) { - super.onRestoreInstanceState(savedInstanceState); - } - - @Override - protected void onSaveInstanceState(Bundle outState) { - super.onSaveInstanceState(outState); - } //Code to override the back button!