Added support for clearing History and Cookies on exit
This commit is contained in:
parent
d3b73b47d0
commit
c7b3f794ab
@ -38,9 +38,9 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
private static SharedPreferences.Editor mEditPrefs;
|
||||
private static RelativeLayout r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11,
|
||||
r12, r13, r14, r15, rIncognitoCookies, rClearCache,
|
||||
rSearchSuggestions;
|
||||
rSearchSuggestions, rClearHistoryExit, rClearCookiesExit;
|
||||
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 boolean mSystemBrowser;
|
||||
private Handler messageHandler;
|
||||
@ -74,6 +74,8 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
|
||||
r1 = (RelativeLayout) findViewById(R.id.r1);
|
||||
r2 = (RelativeLayout) findViewById(R.id.r2);
|
||||
rClearHistoryExit = (RelativeLayout) findViewById(R.id.rClearHistoryExit);
|
||||
rClearCookiesExit = (RelativeLayout) findViewById(R.id.rClearCookiesExit);
|
||||
r3 = (RelativeLayout) findViewById(R.id.r3);
|
||||
r4 = (RelativeLayout) findViewById(R.id.r4);
|
||||
r5 = (RelativeLayout) findViewById(R.id.r5);
|
||||
@ -93,6 +95,8 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
|
||||
cb1 = (CheckBox) findViewById(R.id.cb1);
|
||||
cb2 = (CheckBox) findViewById(R.id.cb2);
|
||||
cbClearHistoryExit = (CheckBox) findViewById(R.id.cbClearHistoryExit);
|
||||
cbClearCookiesExit = (CheckBox) findViewById(R.id.cbClearCookiesExit);
|
||||
cb3 = (CheckBox) findViewById(R.id.cb3);
|
||||
cb4 = (CheckBox) findViewById(R.id.cb4);
|
||||
cb5 = (CheckBox) findViewById(R.id.cb5);
|
||||
@ -109,6 +113,10 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
PreferenceConstants.SAVE_PASSWORDS, true));
|
||||
cb2.setChecked(mPreferences.getBoolean(
|
||||
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,
|
||||
true));
|
||||
cb4.setChecked(mPreferences.getBoolean(PreferenceConstants.TEXT_REFLOW,
|
||||
@ -139,6 +147,8 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
|
||||
r1(r1);
|
||||
r2(r2);
|
||||
rClearHistoryExit(rClearHistoryExit);
|
||||
rClearCookiesExit(rClearCookiesExit);
|
||||
r3(r3);
|
||||
r4(r4);
|
||||
r5(r5);
|
||||
@ -157,6 +167,8 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
rSearchSuggestions(rSearchSuggestions);
|
||||
cb1(cb1);
|
||||
cb2(cb2);
|
||||
cbClearHistoryExit(cbClearHistoryExit);
|
||||
cbClearCookiesExit(cbClearCookiesExit);
|
||||
cb3(cb3);
|
||||
cb4(cb4);
|
||||
cb5(cb5);
|
||||
@ -233,6 +245,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) {
|
||||
view.setOnCheckedChangeListener(new OnCheckedChangeListener() {
|
||||
|
||||
@ -407,6 +446,30 @@ 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) {
|
||||
view.setOnClickListener(new OnClickListener() {
|
||||
|
||||
@ -678,7 +741,7 @@ public class AdvancedSettingsActivity extends Activity {
|
||||
}
|
||||
}
|
||||
SettingsController.setClearHistory(true);
|
||||
trimCache(AdvancedSettingsActivity.this);
|
||||
Utils.trimCache(AdvancedSettingsActivity.this);
|
||||
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() {
|
||||
if (mSystemBrowser) {
|
||||
try {
|
||||
|
@ -77,7 +77,9 @@ import android.view.WindowManager;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.webkit.CookieManager;
|
||||
import android.webkit.CookieSyncManager;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebViewDatabase;
|
||||
import android.webkit.WebChromeClient.CustomViewCallback;
|
||||
import android.webkit.WebIconDatabase;
|
||||
import android.webkit.WebView;
|
||||
@ -150,6 +152,7 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
private boolean mIsNewIntent = false;
|
||||
private VideoView mVideoView;
|
||||
private static SearchAdapter mSearchAdapter;
|
||||
private boolean isIncognito = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -529,6 +532,14 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
|
||||
}
|
||||
|
||||
public void setIsIncognito(boolean letsAsk){
|
||||
isIncognito = letsAsk;
|
||||
}
|
||||
|
||||
public boolean isThisIncognito(){
|
||||
return isIncognito;
|
||||
}
|
||||
|
||||
public void restoreOrNewTab() {
|
||||
mIdGenerator = 0;
|
||||
|
||||
@ -1084,10 +1095,22 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
mWebViews.remove(position);
|
||||
if (mPreferences.getBoolean(
|
||||
PreferenceConstants.CLEAR_CACHE_EXIT, false)
|
||||
&& mCurrentView != null) {
|
||||
&& mCurrentView != null && !isThisIncognito()) {
|
||||
mCurrentView.clearCache(true);
|
||||
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) {
|
||||
reference.pauseTimers();
|
||||
@ -1115,10 +1138,22 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
|
||||
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
||||
if (mPreferences.getBoolean(PreferenceConstants.CLEAR_CACHE_EXIT,
|
||||
false) && mCurrentView != null) {
|
||||
false) && mCurrentView != null && !isThisIncognito()) {
|
||||
mCurrentView.clearCache(true);
|
||||
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;
|
||||
for (int n = 0; n < mWebViews.size(); n++) {
|
||||
@ -1132,6 +1167,32 @@ public class BrowserActivity extends Activity implements BrowserController {
|
||||
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
|
||||
public void onBackPressed() {
|
||||
if (!mActionBar.isShowing()) {
|
||||
|
@ -16,6 +16,7 @@ public class IncognitoActivity extends BrowserActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
||||
super.setIsIncognito(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -16,6 +16,7 @@ public class MainActivity extends BrowserActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mPreferences = getSharedPreferences(PreferenceConstants.PREFERENCES, 0);
|
||||
super.setIsIncognito(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,6 +31,8 @@ public class PreferenceConstants {
|
||||
public static final String USER_AGENT = "agentchoose";
|
||||
public static final String USER_AGENT_STRING = "userAgentString";
|
||||
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_HOST = "useProxyHost";
|
||||
|
@ -146,4 +146,30 @@ public class Utils {
|
||||
public static String[] getArray(String input) {
|
||||
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…
x
Reference in New Issue
Block a user