Browse Source

Updated ProxyUtils to automatically start TOR when needed, more abstraction of BrowserActivity, other cleanup

master
Anthony Restaino 10 years ago
parent
commit
e35b368d50
  1. 2
      app/app.iml
  2. 1
      app/build.gradle
  3. 2
      app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java
  4. 33
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  5. 1
      app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java
  6. 1
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  7. 2
      app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java
  8. 13
      app/src/main/java/acr/browser/lightning/utils/Utils.java
  9. 4
      app/src/main/res/values/strings.xml
  10. 74
      app/src/main/res/xml/preference_about.xml

2
app/app.iml

@ -93,6 +93,7 @@ @@ -93,6 +93,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/design/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/net.i2p.android/client/0.7/jars" />
@ -115,6 +116,7 @@ @@ -115,6 +116,7 @@
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="client-0.7" level="project" />
<orderEntry type="library" exported="" name="palette-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />

1
app/build.gradle

@ -46,6 +46,7 @@ android { @@ -46,6 +46,7 @@ android {
dependencies {
compile 'com.android.support:palette-v7:22.2.0'
compile 'com.android.support:appcompat-v7:22.2.0'
compile 'com.android.support:design:22.2.0'
compile 'org.jsoup:jsoup:1.8.1'
// Only Lightning Plus needs the proxy libraries

2
app/src/LightningPlus/java/acr/browser/lightning/utils/ProxyUtils.java

@ -117,7 +117,7 @@ public class ProxyUtils { @@ -117,7 +117,7 @@ public class ProxyUtils {
case Constants.PROXY_ORBOT:
if (!OrbotHelper.isOrbotRunning(activity))
OrbotHelper.requestShowOrbotStart(activity);
OrbotHelper.requestStartTor(activity);
host = "localhost";
port = 8118;
break;

33
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -139,7 +139,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -139,7 +139,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
// List
private final List<LightningView> mWebViewList = new ArrayList<>();
private List<HistoryItem> mBookmarkList;
private final List<HistoryItem> mBookmarkList = new ArrayList<>();
private LightningView mCurrentView;
private WebView mWebView;
@ -164,8 +164,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -164,8 +164,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
private Activity mActivity;
// Primatives
private boolean mSystemBrowser = false, mIsNewIntent = false, mFullScreen, mColorMode,
mDarkTheme;
private boolean mSystemBrowser = false, mIsNewIntent = false, mFullScreen, mColorMode, mDarkTheme;
private int mOriginalOrientation, mBackgroundColor, mIdGenerator;
private String mSearchText, mUntitledTitle, mHomepage, mCameraPhotoPath;
@ -200,6 +199,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -200,6 +199,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
public abstract void updateHistory(final String title, final String url);
abstract void updateCookiePreference();
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -318,7 +319,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -318,7 +319,8 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
@Override
public void run() {
mBookmarkManager = BookmarkManager.getInstance(mActivity.getApplicationContext());
mBookmarkList = mBookmarkManager.getBookmarks(true);
mBookmarkList.clear();
mBookmarkList.addAll(mBookmarkManager.getBookmarks(true));
if (mBookmarkList.size() == 0 && mPreferences.getDefaultBookmarks()) {
for (String[] array : BookmarkManager.DEFAULT_BOOKMARKS) {
HistoryItem bookmark = new HistoryItem(array[0], array[1]);
@ -715,13 +717,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -715,13 +717,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
mProxyUtils.updateProxySettings(this);
}
/*
* Override this if class overrides BrowserActivity
*/
void updateCookiePreference() {
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
@ -803,7 +798,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -803,7 +798,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
if (mCurrentView != null && !mCurrentView.getUrl().startsWith(Constants.FILE)) {
HistoryItem bookmark = new HistoryItem(mCurrentView.getUrl(),
mCurrentView.getTitle());
if (mBookmarkManager.addBookmark(bookmark) && mBookmarkList != null) {
if (mBookmarkManager.addBookmark(bookmark)) {
mBookmarkList.add(bookmark);
Collections.sort(mBookmarkList, new SortIgnoreCase());
notifyBookmarkDataSetChanged();
@ -829,8 +824,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -829,8 +824,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
* adapter doesn't always change when notifyDataChanged gets called.
*/
private void notifyBookmarkDataSetChanged() {
mBookmarkAdapter.clear();
mBookmarkAdapter.addAll(mBookmarkList);
mBookmarkAdapter.notifyDataSetChanged();
}
@ -1111,8 +1104,10 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -1111,8 +1104,10 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
url = intent.getDataString();
}
int num = 0;
String source = null;
if (intent != null && intent.getExtras() != null) {
num = intent.getExtras().getInt(getPackageName() + ".Origin");
source = intent.getExtras().getString("SOURCE");
}
if (num == 1) {
mCurrentView.loadUrl(url);
@ -1122,7 +1117,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -1122,7 +1117,7 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
url = null;
}
newTab(url, true);
mIsNewIntent = true;
mIsNewIntent = (source == null);
}
}
@ -1403,13 +1398,12 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -1403,13 +1398,12 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
if (mCurrentView != null) {
mCurrentView.resumeTimers();
mCurrentView.onResume();
}
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext());
mBookmarkList = mBookmarkManager.getBookmarks(true);
mBookmarkList.clear();
mBookmarkList.addAll(mBookmarkManager.getBookmarks(true));
notifyBookmarkDataSetChanged();
}
initializePreferences();
if (mWebViewList != null) {
for (int n = 0; n < mWebViewList.size(); n++) {
if (mWebViewList.get(n) != null) {
mWebViewList.get(n).initializePreferences(this);
@ -1417,7 +1411,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse @@ -1417,7 +1411,6 @@ public abstract class BrowserActivity extends ThemableActivity implements Browse
mWebViewList.remove(n);
}
}
}
supportInvalidateOptionsMenu();
}

1
app/src/main/java/acr/browser/lightning/activity/IncognitoActivity.java

@ -20,7 +20,6 @@ public class IncognitoActivity extends BrowserActivity { @@ -20,7 +20,6 @@ public class IncognitoActivity extends BrowserActivity {
CookieSyncManager.createInstance(this);
}
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getIncognitoCookiesEnabled());
super.updateCookiePreference();
}
@Override

1
app/src/main/java/acr/browser/lightning/activity/MainActivity.java

@ -20,7 +20,6 @@ public class MainActivity extends BrowserActivity { @@ -20,7 +20,6 @@ public class MainActivity extends BrowserActivity {
CookieSyncManager.createInstance(this);
}
cookieManager.setAcceptCookie(PreferenceManager.getInstance().getCookiesEnabled());
super.updateCookiePreference();
}
@Override

2
app/src/main/java/acr/browser/lightning/fragment/DisplaySettingsFragment.java

@ -143,7 +143,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe @@ -143,7 +143,7 @@ public class DisplaySettingsFragment extends PreferenceFragment implements Prefe
private void themePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.url_contents));
picker.setTitle(getResources().getString(R.string.theme));
int n = mPreferences.getUseTheme();
picker.setSingleChoiceItems(mThemeOptions, n, new DialogInterface.OnClickListener() {

13
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -17,9 +17,11 @@ import android.graphics.Canvas; @@ -17,9 +17,11 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Environment;
import android.support.annotation.StringRes;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AlertDialog;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.View;
import android.webkit.URLUtil;
import android.widget.Toast;
@ -82,6 +84,14 @@ public final class Utils { @@ -82,6 +84,14 @@ public final class Utils {
Toast.makeText(context, resource, Toast.LENGTH_SHORT).show();
}
public static void showSnackBar(View view, String message) {
Snackbar.make(view, message, Snackbar.LENGTH_SHORT).show();
}
public static void showSnackBar(View view, @StringRes int resource) {
Snackbar.make(view, resource, Snackbar.LENGTH_SHORT).show();
}
/**
* Returns the number of pixels corresponding to the passed density pixels
*/
@ -154,8 +164,7 @@ public final class Utils { @@ -154,8 +164,7 @@ public final class Utils {
* Creates and returns a new favicon which is the same as the provided
* favicon but with horizontal or vertical padding of 4dp
*
* @param bitmap
* is the bitmap to pad.
* @param bitmap is the bitmap to pad.
* @return the padded bitmap.
*/
public static Bitmap padFavicon(Bitmap bitmap) {

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

@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
<string name="stock_browser_unavailable">No stock browser detected</string>
<string name="stock_browser_available">Supported stock browser detected</string>
<string name="fullScreenOption">Hide status bar while browsing</string>
<string name="clear_cookies">Clear browser cookies</string>
<string name="clear_cookies">Clear Browser Cookies</string>
<string name="dialog_image">What would you like to do with this image?</string>
<string name="action_download">Download</string>
<string name="action_open">Open</string>
@ -110,7 +110,7 @@ @@ -110,7 +110,7 @@
<string name="action_auto">Auto</string>
<string name="action_follow_me">Contact Me</string>
<string name="url_twitter">twitter.com/RestainoAnthony</string>
<string name="clear_cache">Clear cache</string>
<string name="clear_cache">Clear Cache</string>
<string name="message_cache_cleared">Cache Cleared</string>
<string name="message_import">Bookmarks Were Imported</string>
<string name="message_clear_history">History Cleared</string>

74
app/src/main/res/xml/preference_about.xml

@ -3,58 +3,86 @@ @@ -3,58 +3,86 @@
<PreferenceCategory android:title="@string/settings_about">
<Preference
android:title="@string/action_follow_me"
android:summary="@string/url_twitter">
android:summary="@string/url_twitter"
android:title="@string/action_follow_me">
<intent
android:action="android.intent.action.VIEW"
android:data="http://twitter.com/RestainoAnthony" />
android:data="http://twitter.com/RestainoAnthony">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/version"
android:key="pref_version" />
android:key="pref_version"
android:title="@string/version" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/licenses">
<Preference
android:title="@string/app_name"
android:summary="@string/mpl_license">
android:summary="@string/mpl_license"
android:title="@string/app_name">
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.mozilla.org/MPL/2.0/" />
android:data="http://www.mozilla.org/MPL/2.0/">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/android_open_source_project"
android:summary="@string/apache">
android:summary="@string/apache"
android:title="@string/android_open_source_project">
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.apache.org/licenses/LICENSE-2.0" />
android:data="http://www.apache.org/licenses/LICENSE-2.0">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/hphosts_ad_server_list"
android:summary="@string/freeware">
android:summary="@string/freeware"
android:title="@string/hphosts_ad_server_list">
<intent
android:action="android.intent.action.VIEW"
android:data="http://hosts-file.net/" />
android:data="http://hosts-file.net/">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/library_netcipher"
android:summary="@string/license_gnu">
android:summary="@string/license_gnu"
android:title="@string/library_netcipher">
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.gnu.org/licenses/lgpl.html" />
android:data="http://www.gnu.org/licenses/lgpl.html">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/snacktory"
android:summary="@string/apache">
android:summary="@string/apache"
android:title="@string/snacktory">
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.apache.org/licenses/LICENSE-2.0" />
android:data="http://www.apache.org/licenses/LICENSE-2.0">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
<Preference
android:title="@string/jsoup"
android:summary="@string/mit_license">
android:summary="@string/mit_license"
android:title="@string/jsoup">
<intent
android:action="android.intent.action.VIEW"
android:data="http://jsoup.org/license" />
android:data="http://jsoup.org/license">
<extra
android:name="SOURCE"
android:value="SELF" />
</intent>
</Preference>
</PreferenceCategory>
</PreferenceScreen>
Loading…
Cancel
Save