Change Orbot checkbox to an HTTP proxy choice list (None, Orbot, I2P)
This commit is contained in:
parent
46fbc56604
commit
6c2a557135
@ -22,11 +22,15 @@ import android.widget.CheckBox;
|
|||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RelativeLayout;
|
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.constant.Constants;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.R;
|
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
import info.guardianproject.onionkit.ui.OrbotHelper;
|
import info.guardianproject.onionkit.ui.OrbotHelper;
|
||||||
|
|
||||||
@ -36,6 +40,8 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
private PreferenceManager mPreferences;
|
private PreferenceManager mPreferences;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private Activity mActivity;
|
private Activity mActivity;
|
||||||
|
private CharSequence[] mProxyChoices;
|
||||||
|
private TextView mProxyChoiceName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -69,7 +75,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
layoutBlockAds.setEnabled(Constants.FULL_VERSION);
|
layoutBlockAds.setEnabled(Constants.FULL_VERSION);
|
||||||
RelativeLayout layoutImages = (RelativeLayout) findViewById(R.id.layoutImages);
|
RelativeLayout layoutImages = (RelativeLayout) findViewById(R.id.layoutImages);
|
||||||
RelativeLayout layoutEnableJS = (RelativeLayout) findViewById(R.id.layoutEnableJS);
|
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 layoutColor = (RelativeLayout) findViewById(R.id.layoutColorMode);
|
||||||
RelativeLayout layoutBookmarks = (RelativeLayout) findViewById(R.id.layoutBookmarks);
|
RelativeLayout layoutBookmarks = (RelativeLayout) findViewById(R.id.layoutBookmarks);
|
||||||
|
|
||||||
@ -89,12 +95,16 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
boolean imagesBool = mPreferences.getBlockImagesEnabled();
|
boolean imagesBool = mPreferences.getBlockImagesEnabled();
|
||||||
boolean enableJSBool = mPreferences.getJavaScriptEnabled();
|
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 flash = (CheckBox) findViewById(R.id.cbFlash);
|
||||||
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
|
CheckBox adblock = (CheckBox) findViewById(R.id.cbAdblock);
|
||||||
adblock.setEnabled(Constants.FULL_VERSION);
|
adblock.setEnabled(Constants.FULL_VERSION);
|
||||||
CheckBox images = (CheckBox) findViewById(R.id.cbImageBlock);
|
CheckBox images = (CheckBox) findViewById(R.id.cbImageBlock);
|
||||||
CheckBox enablejs = (CheckBox) findViewById(R.id.cbJavascript);
|
CheckBox enablejs = (CheckBox) findViewById(R.id.cbJavascript);
|
||||||
CheckBox orbot = (CheckBox) findViewById(R.id.cbOrbot);
|
|
||||||
CheckBox color = (CheckBox) findViewById(R.id.cbColorMode);
|
CheckBox color = (CheckBox) findViewById(R.id.cbColorMode);
|
||||||
|
|
||||||
images.setChecked(imagesBool);
|
images.setChecked(imagesBool);
|
||||||
@ -105,12 +115,11 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
flash.setChecked(false);
|
flash.setChecked(false);
|
||||||
}
|
}
|
||||||
adblock.setChecked(mPreferences.getAdBlockEnabled());
|
adblock.setChecked(mPreferences.getAdBlockEnabled());
|
||||||
orbot.setChecked(mPreferences.getUseProxy());
|
|
||||||
color.setChecked(mPreferences.getColorModeEnabled());
|
color.setChecked(mPreferences.getColorModeEnabled());
|
||||||
|
|
||||||
initCheckBox(flash, adblock, images, enablejs, orbot, color);
|
initCheckBox(flash, adblock, images, enablejs, color);
|
||||||
clickListenerForCheckBoxes(layoutFlash, layoutBlockAds, layoutImages, layoutEnableJS,
|
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 general = (RelativeLayout) findViewById(R.id.layoutGeneral);
|
||||||
RelativeLayout display = (RelativeLayout) findViewById(R.id.layoutDisplay);
|
RelativeLayout display = (RelativeLayout) findViewById(R.id.layoutDisplay);
|
||||||
@ -127,9 +136,9 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
|
|
||||||
public void clickListenerForCheckBoxes(RelativeLayout layoutFlash,
|
public void clickListenerForCheckBoxes(RelativeLayout layoutFlash,
|
||||||
RelativeLayout layoutBlockAds, RelativeLayout layoutImages,
|
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 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() {
|
layoutFlash.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -168,17 +177,12 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
layoutOrbot.setOnClickListener(new OnClickListener() {
|
layoutProxyChoice.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View view) {
|
||||||
if (orbot.isEnabled()) {
|
proxyChoicePicker();
|
||||||
orbot.setChecked(!orbot.isChecked());
|
|
||||||
} else {
|
|
||||||
Utils.showToast(mContext, getResources().getString(R.string.install_orbot));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
layoutColor.setOnClickListener(new OnClickListener() {
|
layoutColor.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@ -191,7 +195,7 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void initCheckBox(CheckBox flash, CheckBox adblock, CheckBox images, CheckBox enablejs,
|
public void initCheckBox(CheckBox flash, CheckBox adblock, CheckBox images, CheckBox enablejs,
|
||||||
CheckBox orbot, CheckBox color) {
|
CheckBox color) {
|
||||||
flash.setEnabled(API < 19);
|
flash.setEnabled(API < 19);
|
||||||
flash.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
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() {
|
color.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -309,6 +300,51 @@ public class SettingsActivity extends ThemableSettingsActivity {
|
|||||||
alert.show();
|
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() {
|
public void agentPicker() {
|
||||||
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);
|
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);
|
||||||
|
|
||||||
|
@ -49,6 +49,7 @@ public class PreferenceManager {
|
|||||||
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
|
public static final String DEFAULT_BOOKMARKS = "defaultBookmarks";
|
||||||
|
|
||||||
public static final String USE_PROXY = "useProxy";
|
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_HOST = "useProxyHost";
|
||||||
public static final String USE_PROXY_PORT = "useProxyPort";
|
public static final String USE_PROXY_PORT = "useProxyPort";
|
||||||
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
|
public static final String INITIAL_CHECK_FOR_TOR = "checkForTor";
|
||||||
@ -226,6 +227,10 @@ public class PreferenceManager {
|
|||||||
return mPrefs.getBoolean(Name.USE_PROXY, false);
|
return mPrefs.getBoolean(Name.USE_PROXY, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getProxyChoice() {
|
||||||
|
return mPrefs.getInt(Name.PROXY_CHOICE, 0);
|
||||||
|
}
|
||||||
|
|
||||||
public int getUserAgentChoice() {
|
public int getUserAgentChoice() {
|
||||||
return mPrefs.getInt(Name.USER_AGENT, 1);
|
return mPrefs.getInt(Name.USER_AGENT, 1);
|
||||||
}
|
}
|
||||||
@ -398,6 +403,10 @@ public class PreferenceManager {
|
|||||||
putBoolean(Name.USE_PROXY, enable);
|
putBoolean(Name.USE_PROXY, enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setProxyChoice(int choice) {
|
||||||
|
putInt(Name.PROXY_CHOICE, choice);
|
||||||
|
}
|
||||||
|
|
||||||
public void setUserAgentChoice(int choice) {
|
public void setUserAgentChoice(int choice) {
|
||||||
putInt(Name.USER_AGENT, choice);
|
putInt(Name.USER_AGENT, choice);
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_height="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:orientation="vertical" >
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<include layout="@layout/toolbar_settings" />
|
<include layout="@layout/toolbar_settings" />
|
||||||
|
|
||||||
@ -159,33 +160,32 @@
|
|||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:background="?attr/dividerColor" />
|
android:background="?attr/dividerColor" />
|
||||||
|
|
||||||
<RelativeLayout
|
<LinearLayout
|
||||||
android:id="@+id/layoutUseOrbot"
|
android:id="@+id/layoutProxyChoice"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?attr/listChoiceBackgroundIndicator"
|
android:background="?attr/listChoiceBackgroundIndicator"
|
||||||
android:minHeight="60dp"
|
android:minHeight="60dp"
|
||||||
|
android:orientation="vertical"
|
||||||
android:paddingBottom="10dp"
|
android:paddingBottom="10dp"
|
||||||
android:paddingRight="10dp"
|
|
||||||
android:paddingTop="10dp" >
|
android:paddingTop="10dp" >
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentLeft="true"
|
|
||||||
android:layout_centerVertical="true"
|
|
||||||
android:paddingLeft="16dp"
|
android:paddingLeft="16dp"
|
||||||
android:paddingRight="60dp"
|
android:text="@string/http_proxy"
|
||||||
android:text="@string/enable_orbot"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium" />
|
android:textAppearance="?android:attr/textAppearanceMedium" />
|
||||||
|
|
||||||
<CheckBox
|
<TextView
|
||||||
android:id="@+id/cbOrbot"
|
android:id="@+id/proxyChoiceName"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentRight="true"
|
android:paddingLeft="16dp"
|
||||||
android:layout_centerVertical="true" />
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
</RelativeLayout>
|
android:textColor="@color/light"
|
||||||
|
tools:text="Disabled" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -158,7 +158,12 @@
|
|||||||
<string name="powered_by_google">Powered by Google</string>
|
<string name="powered_by_google">Powered by Google</string>
|
||||||
<string name="title_adblock">AdBlock</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="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="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="install_orbot">Please install Orbot in order to proxy with Tor.</string>
|
||||||
<string name="yes">Yes</string>
|
<string name="yes">Yes</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user