Browse Source

Added support for clearing History and Cookies on exit

master
Anthony Restaino 11 years ago
parent
commit
c7b3f794ab
  1. 95
      src/acr/browser/lightning/AdvancedSettingsActivity.java
  2. 65
      src/acr/browser/lightning/BrowserActivity.java
  3. 1
      src/acr/browser/lightning/IncognitoActivity.java
  4. 1
      src/acr/browser/lightning/MainActivity.java
  5. 2
      src/acr/browser/lightning/PreferenceConstants.java
  6. 26
      src/acr/browser/lightning/Utils.java

95
src/acr/browser/lightning/AdvancedSettingsActivity.java

@ -38,9 +38,9 @@ public class AdvancedSettingsActivity extends Activity {
private static SharedPreferences.Editor mEditPrefs; private static SharedPreferences.Editor mEditPrefs;
private static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, private static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11,
r12, r13, r14, r15, rIncognitoCookies, rClearCache, r12, r13, r14, r15, rIncognitoCookies, rClearCache,
rSearchSuggestions; rSearchSuggestions, rClearHistoryExit, rClearCookiesExit;
private static CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10, private static CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10,
cb11, cbIncognitoCookies, cbSearchSuggestions; cb11, cbIncognitoCookies, cbSearchSuggestions, cbClearHistoryExit, cbClearCookiesExit;
private static Context mContext; private static Context mContext;
private boolean mSystemBrowser; private boolean mSystemBrowser;
private Handler messageHandler; private Handler messageHandler;
@ -74,6 +74,8 @@ public class AdvancedSettingsActivity extends Activity {
r1 = (RelativeLayout) findViewById(R.id.r1); r1 = (RelativeLayout) findViewById(R.id.r1);
r2 = (RelativeLayout) findViewById(R.id.r2); r2 = (RelativeLayout) findViewById(R.id.r2);
rClearHistoryExit = (RelativeLayout) findViewById(R.id.rClearHistoryExit);
rClearCookiesExit = (RelativeLayout) findViewById(R.id.rClearCookiesExit);
r3 = (RelativeLayout) findViewById(R.id.r3); r3 = (RelativeLayout) findViewById(R.id.r3);
r4 = (RelativeLayout) findViewById(R.id.r4); r4 = (RelativeLayout) findViewById(R.id.r4);
r5 = (RelativeLayout) findViewById(R.id.r5); r5 = (RelativeLayout) findViewById(R.id.r5);
@ -93,6 +95,8 @@ public class AdvancedSettingsActivity extends Activity {
cb1 = (CheckBox) findViewById(R.id.cb1); cb1 = (CheckBox) findViewById(R.id.cb1);
cb2 = (CheckBox) findViewById(R.id.cb2); cb2 = (CheckBox) findViewById(R.id.cb2);
cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit);
cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit);
cb3 = (CheckBox) findViewById(R.id.cb3); cb3 = (CheckBox) findViewById(R.id.cb3);
cb4 = (CheckBox) findViewById(R.id.cb4); cb4 = (CheckBox) findViewById(R.id.cb4);
cb5 = (CheckBox) findViewById(R.id.cb5); cb5 = (CheckBox) findViewById(R.id.cb5);
@ -109,6 +113,10 @@ public class AdvancedSettingsActivity extends Activity {
PreferenceConstants.SAVE_PASSWORDS, true)); PreferenceConstants.SAVE_PASSWORDS, true));
cb2.setChecked(mPreferences.getBoolean( cb2.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_CACHE_EXIT, false)); PreferenceConstants.CLEAR_CACHE_EXIT, false));
cbClearHistoryExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_HISTORY_EXIT, false));
cbClearCookiesExit.setChecked(mPreferences.getBoolean(
PreferenceConstants.CLEAR_COOKIES_EXIT, false));
cb3.setChecked(mPreferences.getBoolean(PreferenceConstants.JAVASCRIPT, cb3.setChecked(mPreferences.getBoolean(PreferenceConstants.JAVASCRIPT,
true)); true));
cb4.setChecked(mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW, cb4.setChecked(mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW,
@ -139,6 +147,8 @@ public class AdvancedSettingsActivity extends Activity {
r1(r1); r1(r1);
r2(r2); r2(r2);
rClearHistoryExit(rClearHistoryExit);
rClearCookiesExit(rClearCookiesExit);
r3(r3); r3(r3);
r4(r4); r4(r4);
r5(r5); r5(r5);
@ -157,6 +167,8 @@ public class AdvancedSettingsActivity extends Activity {
rSearchSuggestions(rSearchSuggestions); rSearchSuggestions(rSearchSuggestions);
cb1(cb1); cb1(cb1);
cb2(cb2); cb2(cb2);
cbClearHistoryExit(cbClearHistoryExit);
cbClearCookiesExit(cbClearCookiesExit);
cb3(cb3); cb3(cb3);
cb4(cb4); cb4(cb4);
cb5(cb5); cb5(cb5);
@ -232,6 +244,33 @@ public class AdvancedSettingsActivity extends Activity {
}); });
} }
void cbClearHistoryExit(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT,
isChecked);
mEditPrefs.commit();
}
});
}
void cbClearCookiesExit(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mEditPrefs.putBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT,
isChecked);
mEditPrefs.commit();
}
});
}
void cb3(CheckBox view) { void cb3(CheckBox view) {
view.setOnCheckedChangeListener(new OnCheckedChangeListener() { view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@ -406,7 +445,31 @@ public class AdvancedSettingsActivity extends Activity {
}); });
} }
void rClearHistoryExit(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cbClearHistoryExit.setChecked(!cbClearHistoryExit.isChecked());
}
});
}
void rClearCookiesExit(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
cbClearCookiesExit.setChecked(!cbClearCookiesExit.isChecked());
}
});
}
void r3(RelativeLayout view) { void r3(RelativeLayout view) {
view.setOnClickListener(new OnClickListener() { view.setOnClickListener(new OnClickListener() {
@ -678,7 +741,7 @@ public class AdvancedSettingsActivity extends Activity {
} }
} }
SettingsController.setClearHistory(true); SettingsController.setClearHistory(true);
trimCache(AdvancedSettingsActivity.this); Utils.trimCache(AdvancedSettingsActivity.this);
messageHandler.sendEmptyMessage(1); messageHandler.sendEmptyMessage(1);
} }
@ -744,32 +807,6 @@ public class AdvancedSettingsActivity extends Activity {
}); });
} }
void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception ignored) {
}
}
boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
public void importFromStockBrowser() { public void importFromStockBrowser() {
if (mSystemBrowser) { if (mSystemBrowser) {
try { try {

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

@ -77,7 +77,9 @@ import android.view.WindowManager;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
import android.webkit.WebViewDatabase;
import android.webkit.WebChromeClient.CustomViewCallback; import android.webkit.WebChromeClient.CustomViewCallback;
import android.webkit.WebIconDatabase; import android.webkit.WebIconDatabase;
import android.webkit.WebView; import android.webkit.WebView;
@ -150,6 +152,7 @@ public class BrowserActivity extends Activity implements BrowserController {
private boolean mIsNewIntent = false; private boolean mIsNewIntent = false;
private VideoView mVideoView; private VideoView mVideoView;
private static SearchAdapter mSearchAdapter; private static SearchAdapter mSearchAdapter;
private boolean isIncognito = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -528,6 +531,14 @@ public class BrowserActivity extends Activity implements BrowserController {
public synchronized void initializeTabs() { public synchronized void initializeTabs() {
} }
public void setIsIncognito(boolean letsAsk){
isIncognito = letsAsk;
}
public boolean isThisIncognito(){
return isIncognito;
}
public void restoreOrNewTab() { public void restoreOrNewTab() {
mIdGenerator = 0; mIdGenerator = 0;
@ -1084,10 +1095,22 @@ public class BrowserActivity extends Activity implements BrowserController {
mWebViews.remove(position); mWebViews.remove(position);
if (mPreferences.getBoolean( if (mPreferences.getBoolean(
PreferenceConstants.CLEAR_CACHE_EXIT, false) PreferenceConstants.CLEAR_CACHE_EXIT, false)
&& mCurrentView != null) { && mCurrentView != null && !isThisIncognito()) {
mCurrentView.clearCache(true); mCurrentView.clearCache(true);
Log.i(Constants.LOGTAG, "Cache Cleared"); Log.i(Constants.LOGTAG, "Cache Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT,
false) && !isThisIncognito()) {
clearHistory();
Log.i(Constants.LOGTAG, "History Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT,
false) && !isThisIncognito()) {
clearCookies();
Log.i(Constants.LOGTAG, "Cookies Cleared");
} }
if (reference != null) { if (reference != null) {
reference.pauseTimers(); reference.pauseTimers();
@ -1115,10 +1138,22 @@ public class BrowserActivity extends Activity implements BrowserController {
public boolean onKeyLongPress(int keyCode, KeyEvent event) { public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT, if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT,
false) && mCurrentView != null) { false) && mCurrentView != null && !isThisIncognito()) {
mCurrentView.clearCache(true); mCurrentView.clearCache(true);
Log.i(Constants.LOGTAG, "Cache Cleared"); Log.i(Constants.LOGTAG, "Cache Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_HISTORY_EXIT,
false) && !isThisIncognito()) {
clearHistory();
Log.i(Constants.LOGTAG, "History Cleared");
}
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_COOKIES_EXIT,
false) && !isThisIncognito()) {
clearCookies();
Log.i(Constants.LOGTAG, "Cookies Cleared");
} }
mCurrentView = null; mCurrentView = null;
for (int n = 0; n < mWebViews.size(); n++) { for (int n = 0; n < mWebViews.size(); n++) {
@ -1131,6 +1166,32 @@ public class BrowserActivity extends Activity implements BrowserController {
} }
return true; return true;
} }
public void clearHistory() {
this.deleteDatabase(DatabaseHandler.DATABASE_NAME);
WebViewDatabase m = WebViewDatabase
.getInstance(this);
m.clearFormData();
m.clearHttpAuthUsernamePassword();
if (API < 18) {
m.clearUsernamePassword();
WebIconDatabase.getInstance().removeAllIcons();
}
if (mSystemBrowser) {
try {
Browser.clearHistory(getContentResolver());
} catch (NullPointerException ignored) {
}
}
SettingsController.setClearHistory(true);
Utils.trimCache(this);
}
public void clearCookies() {
CookieManager c = CookieManager.getInstance();
CookieSyncManager.createInstance(this);
c.removeAllCookie();
}
@Override @Override
public void onBackPressed() { public void onBackPressed() {

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

@ -16,6 +16,7 @@ public class IncognitoActivity extends BrowserActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
super.setIsIncognito(true);
} }
@Override @Override

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

@ -16,6 +16,7 @@ public class MainActivity extends BrowserActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0); mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
super.setIsIncognito(false);
} }
@Override @Override

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

@ -31,6 +31,8 @@ public class PreferenceConstants {
public static final String USER_AGENT = "agentchoose"; public static final String USER_AGENT = "agentchoose";
public static final String USER_AGENT_STRING = "userAgentString"; public static final String USER_AGENT_STRING = "userAgentString";
public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions"; public static final String GOOGLE_SEARCH_SUGGESTIONS = "GoogleSearchSuggestions";
public static final String CLEAR_HISTORY_EXIT = "clearHistoryExit";
public static final String CLEAR_COOKIES_EXIT = "clearCookiesExit";
public static final String USE_PROXY = "useProxy"; public static final String USE_PROXY = "useProxy";
public static final String USE_PROXY_HOST = "useProxyHost"; public static final String USE_PROXY_HOST = "useProxyHost";

26
src/acr/browser/lightning/Utils.java

@ -146,4 +146,30 @@ public class Utils {
public static String[] getArray(String input) { public static String[] getArray(String input) {
return input.split("\\|\\$\\|SEPARATOR\\|\\$\\|"); return input.split("\\|\\$\\|SEPARATOR\\|\\$\\|");
} }
public static void trimCache(Context context) {
try {
File dir = context.getCacheDir();
if (dir != null && dir.isDirectory()) {
deleteDir(dir);
}
} catch (Exception ignored) {
}
}
public static boolean deleteDir(File dir) {
if (dir != null && dir.isDirectory()) {
String[] children = dir.list();
for (String aChildren : children) {
boolean success = deleteDir(new File(dir, aChildren));
if (!success) {
return false;
}
}
}
// The directory is now empty so delete it
return dir.delete();
}
} }

Loading…
Cancel
Save