Updated Orbot Preference Handling
This commit is contained in:
parent
58eec7d871
commit
8dcfd05c58
1
lint.xml
1
lint.xml
@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<lint>
|
||||
<issue id="NewApi" severity="ignore" />
|
||||
</lint>
|
@ -159,5 +159,9 @@
|
||||
<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="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>
|
||||
<string name="no">No</string>
|
||||
|
||||
</resources>
|
@ -455,12 +455,48 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
PreferenceConstants.USE_PROXY, false);
|
||||
|
||||
OrbotHelper oh = new OrbotHelper(this);
|
||||
if (oh.isOrbotInstalled() & useProxy == true) {
|
||||
if (oh.isOrbotInstalled()
|
||||
&& !mPreferences.getBoolean(
|
||||
PreferenceConstants.INITIAL_CHECK_FOR_TOR, false)) {
|
||||
mEditPrefs.putBoolean(PreferenceConstants.INITIAL_CHECK_FOR_TOR,
|
||||
true);
|
||||
mEditPrefs.apply();
|
||||
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
switch (which) {
|
||||
case DialogInterface.BUTTON_POSITIVE:
|
||||
mPreferences
|
||||
.edit()
|
||||
.putBoolean(PreferenceConstants.USE_PROXY, true)
|
||||
.apply();
|
||||
|
||||
initializeTor();
|
||||
break;
|
||||
case DialogInterface.BUTTON_NEGATIVE:
|
||||
mPreferences
|
||||
.edit()
|
||||
.putBoolean(PreferenceConstants.USE_PROXY,
|
||||
false).apply();
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setMessage(R.string.use_tor_prompt)
|
||||
.setPositiveButton(R.string.yes, dialogClickListener)
|
||||
.setNegativeButton(R.string.no, dialogClickListener).show();
|
||||
|
||||
return true;
|
||||
} else if (oh.isOrbotInstalled() & useProxy == true) {
|
||||
initializeTor();
|
||||
return true;
|
||||
} else {
|
||||
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, false);
|
||||
mEditPrefs.apply();
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -471,7 +507,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
OrbotHelper oh = new OrbotHelper(this);
|
||||
if (!oh.isOrbotRunning())
|
||||
oh.requestOrbotStart(this);
|
||||
|
||||
|
||||
WebkitProxy wkp = new WebkitProxy();
|
||||
try {
|
||||
String host = mPreferences.getString(
|
||||
@ -483,6 +519,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
} catch (Exception e) {
|
||||
Log.d(Constants.LOGTAG, "error enabling web proxying", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@ -587,7 +624,17 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
}
|
||||
|
||||
updateCookiePreference();
|
||||
|
||||
if (mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false)) {
|
||||
initializeTor();
|
||||
} else {
|
||||
try {
|
||||
WebkitProxy.resetProxy("acr.browser.lightning.BrowserApp",
|
||||
getApplicationContext());
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2415,7 +2462,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
}
|
||||
}
|
||||
|
||||
//Override this, use finish() for Incognito, moveTaskToBack for Main
|
||||
// Override this, use finish() for Incognito, moveTaskToBack for Main
|
||||
public void closeActivity() {
|
||||
finish();
|
||||
}
|
||||
|
@ -35,4 +35,5 @@ public class PreferenceConstants {
|
||||
public static final String USE_PROXY = "useProxy";
|
||||
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";
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
*/
|
||||
package acr.browser.lightning;
|
||||
|
||||
import info.guardianproject.onionkit.ui.OrbotHelper;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
@ -230,6 +231,7 @@ public class SettingsActivity extends Activity {
|
||||
}
|
||||
adblock.setChecked(mPreferences.getBoolean(
|
||||
PreferenceConstants.BLOCK_ADS, false));
|
||||
orbot.setChecked(mPreferences.getBoolean(PreferenceConstants.USE_PROXY, false));
|
||||
|
||||
initSwitch(location, fullScreen, flash, adblock, orbot);
|
||||
clickListenerForSwitches(layoutLocation, layoutFullScreen, layoutFlash,
|
||||
@ -361,8 +363,9 @@ public class SettingsActivity extends Activity {
|
||||
|
||||
public void clickListenerForSwitches(RelativeLayout one,
|
||||
RelativeLayout two, RelativeLayout three,
|
||||
RelativeLayout layoutBlockAds, RelativeLayout layoutOrbot, final Switch loc, final Switch full,
|
||||
final Switch flash, final Switch adblock, final Switch orbot) {
|
||||
RelativeLayout layoutBlockAds, RelativeLayout layoutOrbot,
|
||||
final Switch loc, final Switch full, final Switch flash,
|
||||
final Switch adblock, final Switch orbot) {
|
||||
layoutBlockAds.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@Override
|
||||
@ -405,7 +408,12 @@ public class SettingsActivity extends Activity {
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
orbot.setChecked(!orbot.isChecked());
|
||||
if (orbot.isEnabled()) {
|
||||
orbot.setChecked(!orbot.isChecked());
|
||||
} else {
|
||||
Utils.showToast(mContext,
|
||||
getResources().getString(R.string.install_orbot));
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
@ -509,13 +517,17 @@ public class SettingsActivity extends Activity {
|
||||
}
|
||||
|
||||
});
|
||||
OrbotHelper oh = new OrbotHelper(this);
|
||||
if (!oh.isOrbotInstalled()) {
|
||||
orbot.setEnabled(false);
|
||||
}
|
||||
|
||||
orbot.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView,
|
||||
boolean isChecked) {
|
||||
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY,
|
||||
isChecked);
|
||||
mEditPrefs.putBoolean(PreferenceConstants.USE_PROXY, isChecked);
|
||||
mEditPrefs.commit();
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user