Browse Source

Updated Orbot Preference Handling

master
Anthony Restaino 11 years ago
parent
commit
8dcfd05c58
  1. 1
      lint.xml
  2. 4
      res/values/strings.xml
  3. 55
      src/acr/browser/lightning/BrowserActivity.java
  4. 1
      src/acr/browser/lightning/PreferenceConstants.java
  5. 20
      src/acr/browser/lightning/SettingsActivity.java

1
lint.xml

@ -1,3 +1,4 @@ @@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<lint>
<issue id="NewApi" severity="ignore" />
</lint>

4
res/values/strings.xml

@ -159,5 +159,9 @@ @@ -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>

55
src/acr/browser/lightning/BrowserActivity.java

@ -455,13 +455,49 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -455,13 +455,49 @@ 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();
return true;
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;
}
}
/*
* Initialize WebKit Proxying for Tor
@ -483,6 +519,7 @@ public class BrowserActivity extends Activity implements BrowserController { @@ -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 { @@ -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 { @@ -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();
}

1
src/acr/browser/lightning/PreferenceConstants.java

@ -35,4 +35,5 @@ public class PreferenceConstants { @@ -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";
}

20
src/acr/browser/lightning/SettingsActivity.java

@ -3,6 +3,7 @@ @@ -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 { @@ -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 { @@ -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 { @@ -405,7 +408,12 @@ public class SettingsActivity extends Activity {
@Override
public void onClick(View v) {
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 { @@ -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…
Cancel
Save