allow country exit node select to persist
This commit is contained in:
parent
b2081789f5
commit
3b41365708
|
@ -72,6 +72,7 @@ import java.net.URLEncoder;
|
|||
import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
|
@ -306,32 +307,40 @@ public class OrbotMainActivity extends Activity
|
|||
|
||||
});
|
||||
|
||||
Locale[] locale = Locale.getAvailableLocales();
|
||||
ArrayList<String> countries = new ArrayList<String>();
|
||||
countries.add("World (best)");
|
||||
countries.add("US");
|
||||
countries.add("DE");
|
||||
countries.add("CA");
|
||||
countries.add("FR");
|
||||
|
||||
String currentExit = Prefs.getExitNodes();
|
||||
int selIdx = -1;
|
||||
|
||||
ArrayList<String> cList = new ArrayList<String>();
|
||||
cList.add(0, "WORLD");
|
||||
|
||||
for (int i = 0; i < TorServiceConstants.COUNTRY_CODES.length; i++)
|
||||
{
|
||||
Locale locale = new Locale("",TorServiceConstants.COUNTRY_CODES[i]);
|
||||
cList.add(locale.getDisplayCountry());
|
||||
|
||||
if (currentExit.contains(TorServiceConstants.COUNTRY_CODES[i]))
|
||||
selIdx = i+1;
|
||||
}
|
||||
|
||||
spnCountries = (Spinner)findViewById(R.id.spinnerCountry);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, countries);
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, cList);
|
||||
spnCountries.setAdapter(adapter);
|
||||
|
||||
if (selIdx != -1)
|
||||
spnCountries.setSelection(selIdx);
|
||||
|
||||
spnCountries.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
|
||||
// your code here
|
||||
|
||||
String country = (String)spnCountries.getItemAtPosition(position);
|
||||
String country = null;
|
||||
|
||||
if (position == 0)
|
||||
country = "";
|
||||
else
|
||||
country = '{' + country.toLowerCase() + '}';
|
||||
country = '{' + TorServiceConstants.COUNTRY_CODES[position-1] + '}';
|
||||
|
||||
Intent torService = new Intent(OrbotMainActivity.this, TorService.class);
|
||||
torService.setAction(TorServiceConstants.CMD_SET_EXIT);
|
||||
|
|
|
@ -3,6 +3,8 @@ package org.torproject.android;
|
|||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import org.torproject.android.service.TorServiceUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
@ -23,6 +25,7 @@ public class Prefs {
|
|||
private final static String PREF_TRANSPROXY_REFRESH = "pref_transproxy_refresh";
|
||||
private final static String PREF_USE_SYSTEM_IPTABLES = "pref_use_sys_iptables";
|
||||
private final static String PREF_USE_VPN = "pref_vpn";
|
||||
private final static String PREF_EXIT_NODES = "pref_exit_nodes";
|
||||
|
||||
private static SharedPreferences prefs;
|
||||
|
||||
|
@ -118,4 +121,14 @@ public class Prefs {
|
|||
public static void putStartOnBoot(boolean value) {
|
||||
putBoolean(PREF_START_ON_BOOT, value);
|
||||
}
|
||||
|
||||
public static String getExitNodes ()
|
||||
{
|
||||
return prefs.getString(PREF_EXIT_NODES, "");
|
||||
}
|
||||
|
||||
public static void setExitNodes (String exits)
|
||||
{
|
||||
putString(PREF_EXIT_NODES,exits);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -149,4 +149,8 @@ public interface TorServiceConstants {
|
|||
//DNS daemon for TCP DNS over TOr
|
||||
public final static String PDNSD_ASSET_KEY = "pdnsd";
|
||||
|
||||
//EXIT COUNTRY CODES
|
||||
public final static String[] COUNTRY_CODES = {"DE","AT","SE","CH","IS","CA","US","FR","BG","AU","BR","CZ","DK","FI","GB","HU","NL","JP","HK","RO","RU","SG","SK","CN"};
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue