Browse Source

Add support for guardian project panic/ripple app

master
Anthony Restaino 8 years ago
parent
commit
fd5c26cc52
  1. 5
      app/src/main/AndroidManifest.xml
  2. 38
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  3. 8
      app/src/main/java/acr/browser/lightning/activity/MainActivity.java
  4. 9
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  5. 14
      app/src/main/java/acr/browser/lightning/constant/HistoryPage.java
  6. 15
      app/src/main/java/acr/browser/lightning/utils/FileUtils.java

5
app/src/main/AndroidManifest.xml

@ -105,6 +105,11 @@ @@ -105,6 +105,11 @@
<data android:scheme="http"/>
<data android:scheme="https"/>
</intent-filter>
<intent-filter>
<action android:name="info.guardianproject.panic.action.TRIGGER"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity
android:name=".activity.SettingsActivity"

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

@ -125,6 +125,8 @@ import butterknife.ButterKnife; @@ -125,6 +125,8 @@ import butterknife.ButterKnife;
public abstract class BrowserActivity extends ThemableBrowserActivity implements BrowserView, UIController, OnClickListener, OnLongClickListener {
private static final String INTENT_PANIC_TRIGGER = "info.guardianproject.panic.action.TRIGGER";
// Static Layout
@Bind(R.id.drawer_layout)
DrawerLayout mDrawerLayout;
@ -171,12 +173,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -171,12 +173,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Primatives
private boolean mFullScreen;
private boolean mDarkTheme;
private boolean mIsNewIntent = false;
private boolean mIsFullScreen = false;
private boolean mIsImmersive = false;
private boolean mShowTabsInDrawer;
private int mOriginalOrientation, mBackgroundColor, mIdGenerator, mIconColor,
mCurrentUiColor = Color.BLACK;
private int mOriginalOrientation;
private int mBackgroundColor;
private int mIconColor;
private int mCurrentUiColor = Color.BLACK;
private String mSearchText;
private String mUntitledTitle;
private String mCameraPhotoPath;
@ -356,8 +359,29 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -356,8 +359,29 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
}
mPresenter.setupTabs(getIntent(), isIncognito());
mProxyUtils.checkForProxy(BrowserActivity.this);
if (isPanicTrigger(getIntent())) {
panicClean();
} else {
mPresenter.setupTabs(getIntent(), isIncognito());
mProxyUtils.checkForProxy(BrowserActivity.this);
}
}
boolean isPanicTrigger(Intent intent) {
return intent != null && INTENT_PANIC_TRIGGER.equals(intent.getAction());
}
void panicClean() {
Log.d(Constants.TAG, "Closing browser");
mTabsManager.newTab(this, "", false);
mTabsManager.switchToTab(0);
mTabsManager.clearSavedState();
HistoryPage.deleteHistoryPage(getApplication());
closeBrowser();
// System exit needed in the case of receiving
// the panic intent since finish() isn't completely
// closing the browser
System.exit(1);
}
private class SearchListenerClass implements OnKeyListener, OnEditorActionListener, OnFocusChangeListener, OnTouchListener {
@ -806,8 +830,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -806,8 +830,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Set the background color so the color mode color doesn't show through
mBrowserFrame.setBackgroundColor(mBackgroundColor);
mIsNewIntent = false;
mBrowserFrame.removeAllViews();
removeViewFromParent(mCurrentView);
@ -842,8 +864,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -842,8 +864,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
// Set the background color so the color mode color doesn't show through
mBrowserFrame.setBackgroundColor(mBackgroundColor);
mIsNewIntent = false;
final float translation = mToolbarLayout.getTranslationY();
mBrowserFrame.removeAllViews();

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

@ -39,8 +39,12 @@ public class MainActivity extends BrowserActivity { @@ -39,8 +39,12 @@ public class MainActivity extends BrowserActivity {
@Override
protected void onNewIntent(Intent intent) {
handleNewIntent(intent);
super.onNewIntent(intent);
if (isPanicTrigger(intent)) {
panicClean();
} else {
handleNewIntent(intent);
super.onNewIntent(intent);
}
}
@Override

9
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -341,6 +341,15 @@ public class TabsManager { @@ -341,6 +341,15 @@ public class TabsManager {
FileUtils.writeBundleToStorage(mApp, outState, BUNDLE_STORAGE);
}
/**
* Use this method to clear the saved
* state if you do not wish it to be
* restored when the browser next starts.
*/
public void clearSavedState() {
FileUtils.deleteBundleInStorage(mApp, BUNDLE_STORAGE);
}
/**
* Restores the previously saved tabs from the
* bundle stored in peristent file storage.

14
app/src/main/java/acr/browser/lightning/constant/HistoryPage.java

@ -106,4 +106,18 @@ public class HistoryPage extends AsyncTask<Void, Void, Void> { @@ -106,4 +106,18 @@ public class HistoryPage extends AsyncTask<Void, Void, Void> {
executeOnExecutor(BrowserApp.getIOThread());
}
/**
* Use this method to immediately delete the history
* page on the current thread. This will clear the
* cached history page that was stored on file.
*
* @param application the application object needed to get the file.
*/
public static void deleteHistoryPage(@NonNull Application application) {
File historyWebPage = new File(application.getFilesDir(), FILENAME);
if (historyWebPage.exists()) {
historyWebPage.delete();
}
}
}

15
app/src/main/java/acr/browser/lightning/utils/FileUtils.java

@ -54,6 +54,21 @@ public class FileUtils { @@ -54,6 +54,21 @@ public class FileUtils {
});
}
/**
* Use this method to delete the bundle with the specified name.
* This is a blocking call and should be used within a worker
* thread unless immediate deletion is necessary.
*
* @param app the application object needed to get the file.
* @param name the name of the file.
*/
public static void deleteBundleInStorage(final @NonNull Application app, final @NonNull String name) {
File outputFile = new File(app.getFilesDir(), name);
if (outputFile.exists()) {
outputFile.delete();
}
}
/**
* Reads a bundle from the file with the specified
* name in the peristent storage files directory.

Loading…
Cancel
Save