Browse Source

Change Orbot checkbox to an HTTP proxy choice list (None, Orbot, I2P)

master
str4d 9 years ago
parent
commit
6c2a557135
  1. 96
      app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java
  2. 9
      app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java
  3. 30
      app/src/main/res/layout/settings.xml
  4. 7
      app/src/main/res/values/strings.xml

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

@ -22,11 +22,15 @@ import android.widget.CheckBox; @@ -22,11 +22,15 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import net.i2p.android.ui.I2PAndroidHelper;
import acr.browser.lightning.R;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.R;
import acr.browser.lightning.utils.Utils;
import info.guardianproject.onionkit.ui.OrbotHelper;
@ -36,6 +40,8 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -36,6 +40,8 @@ public class SettingsActivity extends ThemableSettingsActivity {
private PreferenceManager mPreferences;
private Context mContext;
private Activity mActivity;
private CharSequence[] mProxyChoices;
private TextView mProxyChoiceName;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -69,7 +75,7 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -69,7 +75,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
layoutBlockAds.setEnabled(Constants.FULL_VERSION);
RelativeLayout layoutImages = (RelativeLayout) findViewById(R.id.layoutImages);
RelativeLayout layoutEnableJS = (RelativeLayout) findViewById(R.id.layoutEnableJS);
RelativeLayout layoutOrbot = (RelativeLayout) findViewById(R.id.layoutUseOrbot);
LinearLayout layoutProxyChoice = (LinearLayout) findViewById(R.id.layoutProxyChoice);
RelativeLayout layoutColor = (RelativeLayout) findViewById(R.id.layoutColorMode);
RelativeLayout layoutBookmarks = (RelativeLayout) findViewById(R.id.layoutBookmarks);
@ -89,12 +95,16 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -89,12 +95,16 @@ public class SettingsActivity extends ThemableSettingsActivity {
boolean imagesBool = mPreferences.getBlockImagesEnabled();
boolean enableJSBool = mPreferences.getJavaScriptEnabled();
mProxyChoiceName = (TextView) findViewById(R.id.proxyChoiceName);
mProxyChoices = this.getResources().getStringArray(R.array.proxy_choices_array);
int choice = mPreferences.getProxyChoice();
mProxyChoiceName.setText(mProxyChoices[choice]);
CheckBox flash = (CheckBox) findViewById(R.id.cbFlash);
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
adblock.setEnabled(Constants.FULL_VERSION);
CheckBox images = (CheckBox) findViewById(R.id.cbImageBlock);
CheckBox enablejs = (CheckBox) findViewById(R.id.cbJavascript);
CheckBox orbot = (CheckBox) findViewById(R.id.cbOrbot);
CheckBox color = (CheckBox) findViewById(R.id.cbColorMode);
images.setChecked(imagesBool);
@ -105,12 +115,11 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -105,12 +115,11 @@ public class SettingsActivity extends ThemableSettingsActivity {
flash.setChecked(false);
}
adblock.setChecked(mPreferences.getAdBlockEnabled());
orbot.setChecked(mPreferences.getUseProxy());
color.setChecked(mPreferences.getColorModeEnabled());
initCheckBox(flash, adblock, images, enablejs, orbot, color);
initCheckBox(flash, adblock, images, enablejs, color);
clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS,
layoutOrbot, layoutColor, flash, adblock, images, enablejs, orbot, color);
layoutProxyChoice, layoutColor, flash, adblock, images, enablejs, color);
RelativeLayout general = (RelativeLayout) findViewById(R.id.layoutGeneral);
RelativeLayout display = (RelativeLayout) findViewById(R.id.layoutDisplay);
@ -127,9 +136,9 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -127,9 +136,9 @@ public class SettingsActivity extends ThemableSettingsActivity {
public void clickListenerForCheckBoxes(RelativeLayout layoutFlash,
RelativeLayout layoutBlockAds, RelativeLayout layoutImages,
RelativeLayout layoutEnableJS, RelativeLayout layoutOrbot, RelativeLayout layoutColor,
RelativeLayout layoutEnableJS, LinearLayout layoutProxyChoice, RelativeLayout layoutColor,
final CheckBox flash, final CheckBox adblock, final CheckBox images,
final CheckBox enablejs, final CheckBox orbot, final CheckBox color) {
final CheckBox enablejs, final CheckBox color) {
layoutFlash.setOnClickListener(new OnClickListener() {
@Override
@ -168,17 +177,12 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -168,17 +177,12 @@ public class SettingsActivity extends ThemableSettingsActivity {
}
});
layoutOrbot.setOnClickListener(new OnClickListener() {
layoutProxyChoice.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (orbot.isEnabled()) {
orbot.setChecked(!orbot.isChecked());
} else {
Utils.showToast(mContext, getResources().getString(R.string.install_orbot));
}
public void onClick(View view) {
proxyChoicePicker();
}
});
layoutColor.setOnClickListener(new OnClickListener() {
@ -191,7 +195,7 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -191,7 +195,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
}
public void initCheckBox(CheckBox flash, CheckBox adblock, CheckBox images, CheckBox enablejs,
CheckBox orbot, CheckBox color) {
CheckBox color) {
flash.setEnabled(API < 19);
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -253,20 +257,7 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -253,20 +257,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
}
});
OrbotHelper oh = new OrbotHelper(this);
if (!oh.isOrbotInstalled()) {
orbot.setEnabled(false);
}
orbot.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
mPreferences.setUseProxy(isChecked);
}
});
color.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
@ -309,6 +300,51 @@ public class SettingsActivity extends ThemableSettingsActivity { @@ -309,6 +300,51 @@ public class SettingsActivity extends ThemableSettingsActivity {
alert.show();
}
private void proxyChoicePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mContext);
picker.setTitle(getResources().getString(R.string.http_proxy));
picker.setSingleChoiceItems(mProxyChoices, mPreferences.getProxyChoice(),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
setProxyChoice(which);
}
});
picker.setNeutralButton(getResources().getString(R.string.action_ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
picker.show();
}
private void setProxyChoice(int choice) {
switch (choice) {
case 1:
OrbotHelper oh = new OrbotHelper(this);
if (!oh.isOrbotInstalled()) {
choice = 0;
Utils.showToast(mContext, getResources().getString(R.string.install_orbot));
}
break;
case 2:
I2PAndroidHelper ih = new I2PAndroidHelper(this);
if (!ih.isI2PAndroidInstalled()) {
choice = 0;
ih.promptToInstall(this);
}
break;
}
mPreferences.setUseProxy(choice != 0);
mPreferences.setProxyChoice(choice);
if (choice < mProxyChoices.length)
mProxyChoiceName.setText(mProxyChoices[choice]);
}
public void agentPicker() {
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);

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

@ -49,6 +49,7 @@ public class PreferenceManager { @@ -49,6 +49,7 @@ public class PreferenceManager {
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
public static final String USE_PROXY = "useProxy";
public static final String PROXY_CHOICE = "proxyChoice";
public static final String USE_PROXY_HOST = "useProxyHost";
public static final String USE_PROXY_PORT = "useProxyPort";
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
@ -226,6 +227,10 @@ public class PreferenceManager { @@ -226,6 +227,10 @@ public class PreferenceManager {
return mPrefs.getBoolean(Name.USE_PROXY, false);
}
public int getProxyChoice() {
return mPrefs.getInt(Name.PROXY_CHOICE, 0);
}
public int getUserAgentChoice() {
return mPrefs.getInt(Name.USER_AGENT, 1);
}
@ -398,6 +403,10 @@ public class PreferenceManager { @@ -398,6 +403,10 @@ public class PreferenceManager {
putBoolean(Name.USE_PROXY, enable);
}
public void setProxyChoice(int choice) {
putInt(Name.PROXY_CHOICE, choice);
}
public void setUserAgentChoice(int choice) {
putInt(Name.USER_AGENT, choice);
}

30
app/src/main/res/layout/settings.xml

@ -1,8 +1,9 @@ @@ -1,8 +1,9 @@
<?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" >
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<include layout="@layout/toolbar_settings" />
@ -159,33 +160,32 @@ @@ -159,33 +160,32 @@
android:layout_marginRight="10dp"
android:background="?attr/dividerColor" />
<RelativeLayout
android:id="@+id/layoutUseOrbot"
<LinearLayout
android:id="@+id/layoutProxyChoice"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/listChoiceBackgroundIndicator"
android:minHeight="60dp"
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:paddingLeft="16dp"
android:paddingRight="60dp"
android:text="@string/enable_orbot"
android:text="@string/http_proxy"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="@+id/cbOrbot"
<TextView
android:id="@+id/proxyChoiceName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
android:paddingLeft="16dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/light"
tools:text="Disabled" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"

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

@ -158,7 +158,12 @@ @@ -158,7 +158,12 @@
<string name="powered_by_google">Powered by Google</string>
<string name="title_adblock">AdBlock</string>
<string name="message_adblock">AdBlock is currently only available in the browser\'s paid version, Lightning Browser+. It is available to download on Google Play.</string>
<string name="enable_orbot">Enable Orbot</string>
<string name="http_proxy">HTTP proxy</string>
<string-array name="proxy_choices_array">
<item>None</item>
<item>Orbot</item>
<item>I2P</item>
</string-array>
<string name="use_tor_prompt">It looks like you have Orbot installed. Do you want to use Tor?</string>
<string name="install_orbot">Please install Orbot in order to proxy with Tor.</string>
<string name="yes">Yes</string>

Loading…
Cancel
Save