Browse Source

Add manual proxy picker

master
str4d 10 years ago
parent
commit
2eec8be4ce
  1. 32
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  2. 1
      app/src/main/java/acr/browser/lightning/constant/Constants.java
  3. 8
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  4. 43
      app/src/main/res/layout/picker_manual_proxy.xml
  5. 4
      app/src/main/res/values/strings.xml

32
app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java

@ -98,7 +98,10 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -98,7 +98,10 @@ public class SettingsActivity extends ThemableSettingsActivity {
mProxyChoiceName = (TextView) findViewById(R.id.proxyChoiceName);
mProxyChoices = this.getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice();
mProxyChoiceName.setText(mProxyChoices[choice]);
if (choice == Constants.PROXY_MANUAL)
mProxyChoiceName.setText(mPreferences.getProxyHost() + ":" + mPreferences.getProxyPort());
else
mProxyChoiceName.setText(mProxyChoices[choice]);
CheckBox flash = (CheckBox) findViewById(R.id.cbFlash);
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
@ -337,6 +340,10 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -337,6 +340,10 @@ public class SettingsActivity extends ThemableSettingsActivity {
ih.promptToInstall(this);
}
break;
case Constants.PROXY_MANUAL:
manualProxyPicker();
break;
}
mPreferences.setProxyChoice(choice);
@ -344,6 +351,29 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -344,6 +351,29 @@ public class SettingsActivity extends ThemableSettingsActivity {
mProxyChoiceName.setText(mProxyChoices[choice]);
}
public void manualProxyPicker() {
View v = getLayoutInflater().inflate(R.layout.picker_manual_proxy, null);
final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost);
final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort);
eProxyHost.setText(mPreferences.getProxyHost());
eProxyPort.setText(Integer.toString(mPreferences.getProxyPort()));
new AlertDialog.Builder(mActivity)
.setTitle(R.string.manual_proxy)
.setView(v)
.setPositiveButton(R.string.action_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String proxyHost = eProxyHost.getText().toString();
int proxyPort = Integer.parseInt(eProxyPort.getText().toString());
mPreferences.setProxyHost(proxyHost);
mPreferences.setProxyPort(proxyPort);
mProxyChoiceName.setText(proxyHost + ":" + proxyPort);
}
})
.show();
}
public void agentPicker() {
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);

1
app/src/main/java/acr/browser/lightning/constant/Constants.java

@ -43,4 +43,5 @@ public final class Constants { @@ -43,4 +43,5 @@ public final class Constants {
public static final int NO_PROXY = 0;
public static final int PROXY_ORBOT = 1;
public static final int PROXY_I2P = 2;
public static final int PROXY_MANUAL = 3;
}

8
app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java

@ -423,6 +423,14 @@ public class PreferenceManager { @@ -423,6 +423,14 @@ public class PreferenceManager {
putInt(Name.PROXY_CHOICE, choice);
}
public void setProxyHost(String proxyHost) {
putString(Name.USE_PROXY_HOST, proxyHost);
}
public void setProxyPort(int proxyPort) {
putInt(Name.USE_PROXY_PORT, proxyPort);
}
public void setUserAgentChoice(int choice) {
putInt(Name.USER_AGENT, choice);
}

43
app/src/main/res/layout/picker_manual_proxy.xml

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="4dp"
android:paddingStart="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/host"/>
<EditText
android:id="@+id/proxyHost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/port"/>
<EditText
android:id="@+id/proxyPort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number"/>
</LinearLayout>
</LinearLayout>

4
app/src/main/res/values/strings.xml

@ -163,7 +163,11 @@ @@ -163,7 +163,11 @@
<item>None</item>
<item>Orbot</item>
<item>I2P</item>
<item>Manual</item>
</string-array>
<string name="manual_proxy">Manual proxy</string>
<string name="host">Host:</string>
<string name="port">Port:</string>
<string name="use_tor_prompt">It looks like you have Orbot installed. Do you want to use Tor?</string>
<string name="use_i2p_prompt">It looks like you have I2P installed. Do you want to use I2P?</string>
<string name="install_orbot">Please install Orbot in order to proxy with Tor.</string>

Loading…
Cancel
Save