import android.webkit.WebStorage;
import android.webkit.WebView;
import android.webkit.WebViewClient;
+import android.webkit.WebViewDatabase;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
public static boolean thirdPartyCookiesEnabled;
// domStorageEnabled is public static so it can be accessed from SettingsFragment. It is also used in onCreate(), onCreateOptionsMenu(), and onOptionsItemSelected().
public static boolean domStorageEnabled;
+ // saveFormDataEnabled is public static so it can be accessed from SettingsFragment. It is also used in onCreate(), onCreateOptionsMenu(), and onOptionsItemSelected().
+ public static boolean saveFormDataEnabled;
// javaScriptDisabledSearchURL is public static so it can be accessed from SettingsFragment. It is also used in onCreate() and loadURLFromTextBox().
public static String javaScriptDisabledSearchURL;
// javaScriptEnabledSearchURL is public static so it can be accessed from SettingsFragment. It is also used in onCreate() and loadURLFromTextBox().
* SYSTEM_UI_FLAG_FULLSCREEN hides the status bar across the top of the screen.
* SYSTEM_UI_FLAG_IMMERSIVE_STICKY makes the navigation and status bars ghosted overlays and automatically rehides them.
*/
-
- // Set the one flag supported by API >= 14.
- view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
-
- // Set the two flags that are supported by API >= 16.
- if (Build.VERSION.SDK_INT >= 16) {
- view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN);
- }
-
- // Set all three flags that are supported by API >= 19.
- if (Build.VERSION.SDK_INT >= 19) {
- view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- }
+ view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
// Exit full screen video
domStorageEnabled = savedPreferences.getBoolean("dom_storage_enabled", false);
mainWebView.getSettings().setDomStorageEnabled(domStorageEnabled);
+ // Set the saved form data initial status. The default is false.
+ saveFormDataEnabled = savedPreferences.getBoolean("save_form_data_enabled", false);
+ mainWebView.getSettings().setSaveFormData(saveFormDataEnabled);
+
// Set the user agent initial status.
String userAgentString = savedPreferences.getString("user_agent", "Default user agent");
switch (userAgentString) {
MenuItem toggleFirstPartyCookies = menu.findItem(R.id.toggleFirstPartyCookies);
MenuItem toggleThirdPartyCookies = menu.findItem(R.id.toggleThirdPartyCookies);
MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
+ MenuItem toggleSaveFormData = menu.findItem(R.id.toggleSaveFormData);
// Set the initial status of the privacy icon.
updatePrivacyIcon();
toggleFirstPartyCookies.setChecked(firstPartyCookiesEnabled);
toggleThirdPartyCookies.setChecked(thirdPartyCookiesEnabled);
toggleDomStorage.setChecked(domStorageEnabled);
+ toggleSaveFormData.setChecked(saveFormDataEnabled);
return true;
}
toggleThirdPartyCookies.setEnabled(false);
}
+ // Enable DOM Storage if JavaScript is enabled.
+ MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
+ toggleDomStorage.setEnabled(javaScriptEnabled);
+
// Enable Clear Cookies if there are any.
MenuItem clearCookies = menu.findItem(R.id.clearCookies);
clearCookies.setEnabled(cookieManager.hasCookies());
- // Enable DOM Storage if JavaScript is enabled.
- MenuItem toggleDomStorage = menu.findItem(R.id.toggleDomStorage);
- toggleDomStorage.setEnabled(javaScriptEnabled);
+ // Enable Clear Form Data is there is any.
+ MenuItem clearFormData = menu.findItem(R.id.clearFormData);
+ WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this);
+ clearFormData.setEnabled(mainWebViewDatabase.hasFormData());
// Run all the other default commands.
super.onPrepareOptionsMenu(menu);
mainWebView.reload();
return true;
+ case R.id.toggleSaveFormData:
+ // Switch the status of saveFormDataEnabled.
+ saveFormDataEnabled = !saveFormDataEnabled;
+
+ // Update the menu checkbox.
+ menuItem.setChecked(saveFormDataEnabled);
+
+ // Apply the new form data status.
+ mainWebView.getSettings().setSaveFormData(saveFormDataEnabled);
+
+ // Reload the WebView.
+ mainWebView.reload();
+ return true;
+
case R.id.clearCookies:
if (Build.VERSION.SDK_INT < 21) {
cookieManager.removeAllCookie();
Snackbar.make(findViewById(R.id.mainWebView), R.string.dom_storage_deleted, Snackbar.LENGTH_SHORT).show();
return true;
+ case R.id.clearFormData:
+ WebViewDatabase mainWebViewDatabase = WebViewDatabase.getInstance(this);
+ mainWebViewDatabase.clearFormData();
+ mainWebView.reload();
+ return true;
+
case R.id.share:
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
}
private void loadUrlFromTextBox() throws UnsupportedEncodingException {
- // Get the text from urlTextBox and convert it to a string.
- String unformattedUrlString = urlTextBox.getText().toString();
+ // Get the text from urlTextBox and convert it to a string. trim() removes white spaces from the beginning and end of the string.
+ String unformattedUrlString = urlTextBox.getText().toString().trim();
+
URL unformattedUrl = null;
Uri.Builder formattedUri = new Uri.Builder();