From 6c2a55713524dcdf2dea0ec7a531e2cdab34656e Mon Sep 17 00:00:00 2001 From: str4d Date: Sun, 24 May 2015 13:20:08 +0000 Subject: [PATCH] Change Orbot checkbox to an HTTP proxy choice list (None, Orbot, I2P) --- .../lightning/activity/SettingsActivity.java | 96 +++++++++++++------ .../preference/PreferenceManager.java | 9 ++ app/src/main/res/layout/settings.xml | 30 +++--- app/src/main/res/values/strings.xml | 7 +- 4 files changed, 96 insertions(+), 46 deletions(-) diff --git a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java index c5a8b92..e3a627f 100644 --- a/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java +++ b/app/src/main/java/acr/browser/lightning/activity/SettingsActivity.java @@ -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 { 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 { 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 { 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 { 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 { 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 { } }); - 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 { } 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 { } }); - 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 { 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); diff --git a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java index 275e93d..f03651d 100644 --- a/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java +++ b/app/src/main/java/acr/browser/lightning/preference/PreferenceManager.java @@ -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 { 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 { 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); } diff --git a/app/src/main/res/layout/settings.xml b/app/src/main/res/layout/settings.xml index 3a04e18..4ba9191 100644 --- a/app/src/main/res/layout/settings.xml +++ b/app/src/main/res/layout/settings.xml @@ -1,8 +1,9 @@ + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> @@ -159,33 +160,32 @@ android:layout_marginRight="10dp" android:background="?attr/dividerColor" /> - - - + android:paddingLeft="16dp" + android:textAppearance="?android:attr/textAppearanceSmall" + android:textColor="@color/light" + tools:text="Disabled" /> + Powered by Google AdBlock AdBlock is currently only available in the browser\'s paid version, Lightning Browser+. It is available to download on Google Play. - Enable Orbot + HTTP proxy + + None + Orbot + I2P + It looks like you have Orbot installed. Do you want to use Tor? Please install Orbot in order to proxy with Tor. Yes