From a45494e763affaa93f42927ee58f45803e1ee9db Mon Sep 17 00:00:00 2001
From: Soren Stoutner
Date: Tue, 13 Sep 2016 16:17:42 -0700
Subject: [PATCH] Add a download file `AlertDialog` that allows setting the
download file name. Fixes https://redmine.stoutner.com/issues/58 and
https://redmine.stoutner.com/issues/59.
---
.idea/dictionaries/soren.xml | 1 +
.../main/assets/en/guide_tracking_ids.html | 5 +-
.../privacybrowser/BookmarksActivity.java | 20 ---
.../privacybrowser/CreateBookmark.java | 5 +-
.../privacybrowser/CreateBookmarkFolder.java | 5 +-
.../CreateHomeScreenShortcut.java | 8 +-
.../stoutner/privacybrowser/DownloadFile.java | 169 ++++++++++++++++++
.../stoutner/privacybrowser/EditBookmark.java | 12 +-
.../privacybrowser/EditBookmarkFolder.java | 5 +-
.../privacybrowser/MainWebViewActivity.java | 52 +++---
.../privacybrowser/SslCertificateError.java | 6 +-
.../create_home_screen_shortcut_dialog.xml | 5 +-
.../main/res/layout/download_file_dialog.xml | 51 ++++++
.../main/res/layout/edit_bookmark_dialog.xml | 5 +-
app/src/main/res/values/strings.xml | 3 +
15 files changed, 277 insertions(+), 75 deletions(-)
create mode 100644 app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java
create mode 100644 app/src/main/res/layout/download_file_dialog.xml
diff --git a/.idea/dictionaries/soren.xml b/.idea/dictionaries/soren.xml
index d142454e..c623c835 100644
--- a/.idea/dictionaries/soren.xml
+++ b/.idea/dictionaries/soren.xml
@@ -20,6 +20,7 @@
coordinatorlayout
displayorder
dname
+ downloadfile
eadd
edittext
exynos
diff --git a/app/src/main/assets/en/guide_tracking_ids.html b/app/src/main/assets/en/guide_tracking_ids.html
index 77813ade..87ed4ef9 100644
--- a/app/src/main/assets/en/guide_tracking_ids.html
+++ b/app/src/main/assets/en/guide_tracking_ids.html
@@ -38,9 +38,8 @@
This is accomplished by including a DNT (Do Not Track) header with web requests.
This header is enabled by default in Privacy Browser, although if desired it can be disabled in the settings.
-The DNT header doesn't really provide much privacy because most web servers ignore it. Yahoo programmed their servers to ignore the DNT header
- from Internet Explorer 10 when it was turned on by default because they argued that the user had not made the decision to enable DNT.
- Google and Microsoft ignore DNT even though they include a DNT feature in the browsers they distribute. Facebook also ignores DNT.
+The DNT header doesn't really provide much privacy because most web servers ignore it. For example, Yahoo, Google, Microsoft, and Facebook
+ all ignore at least some DNT headers.
Advertisements
diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java
index 0c1a883f..f39dae6e 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java
@@ -528,11 +528,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
return true;
}
- @Override
- public void onCancelCreateBookmark(DialogFragment dialogFragment) {
- // Do nothing because the user selected `Cancel`.
- }
-
@Override
public void onCreateBookmark(DialogFragment dialogFragment) {
// Get the `EditText`s from the `createBookmarkDialogFragment` and extract the strings.
@@ -558,11 +553,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
bookmarksListView.setSelection(newBookmarkDisplayOrder);
}
- @Override
- public void onCancelCreateBookmarkFolder(DialogFragment dialogFragment) {
- // Do nothing because the user selected `Cancel`.
- }
-
@Override
public void onCreateBookmarkFolder(DialogFragment dialogFragment) {
// Get `create_folder_name_edit_text` and extract the string.
@@ -609,11 +599,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
}
}
- @Override
- public void onCancelEditBookmark(DialogFragment dialogFragment) {
- // Do nothing because the user selected `Cancel`.
- }
-
@Override
public void onSaveEditBookmark(DialogFragment dialogFragment) {
// Get a long array with the the databaseId of the selected bookmark and convert it to an `int`.
@@ -648,11 +633,6 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
bookmarksListView.setSelection(selectedBookmarkPosition);
}
- @Override
- public void onCancelEditBookmarkFolder(DialogFragment dialogFragment) {
- // Do nothing because the user selected `Cancel`.
- }
-
@Override
public void onSaveEditBookmarkFolder(DialogFragment dialogFragment) {
// Get the new folder name.
diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java
index b779709c..4b09ba1a 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java
@@ -36,8 +36,6 @@ import android.widget.EditText;
public class CreateBookmark extends DialogFragment {
// The public interface is used to send information back to the parent activity.
public interface CreateBookmarkListener {
- void onCancelCreateBookmark(DialogFragment dialogFragment);
-
void onCreateBookmark(DialogFragment dialogFragment);
}
@@ -72,8 +70,7 @@ public class CreateBookmark extends DialogFragment {
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- // Return the `DialogFragment` to the parent activity on cancel.
- createBookmarkListener.onCancelCreateBookmark(CreateBookmark.this);
+ // Do nothing. The `AlertDialog` will close automatically.
}
});
diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java
index 0847ce3f..57d9f8af 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmarkFolder.java
@@ -35,8 +35,6 @@ import android.widget.ImageView;
public class CreateBookmarkFolder extends DialogFragment {
// The public interface is used to send information back to the parent activity.
public interface CreateBookmarkFolderListener {
- void onCancelCreateBookmarkFolder(DialogFragment dialogFragment);
-
void onCreateBookmarkFolder(DialogFragment dialogFragment);
}
@@ -66,8 +64,7 @@ public class CreateBookmarkFolder extends DialogFragment {
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- // Return the `DialogFragment` to the parent activity on cancel.
- createBookmarkFolderListener.onCancelCreateBookmarkFolder(CreateBookmarkFolder.this);
+ // Do nothing. The `AlertDialog` will close automatically.
}
});
diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java
index 35601387..1eb74fb6 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java
@@ -37,12 +37,10 @@ import android.widget.EditText;
public class CreateHomeScreenShortcut extends DialogFragment {
// The public interface is used to send information back to the parent activity.
public interface CreateHomeScreenSchortcutListener {
- void onCancelCreateHomeScreenShortcut(DialogFragment dialogFragment);
-
void onCreateHomeScreenShortcut(DialogFragment dialogFragment);
}
- //createHomeScreenShortcutListener is used in `onAttach` and and `onCreateDialog`.
+ //`createHomeScreenShortcutListener` is used in `onAttach()` and `onCreateDialog()`.
private CreateHomeScreenSchortcutListener createHomeScreenShortcutListener;
// Check to make sure that the parent activity implements the listener.
@@ -74,7 +72,7 @@ public class CreateHomeScreenShortcut extends DialogFragment {
dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- createHomeScreenShortcutListener.onCancelCreateHomeScreenShortcut(CreateHomeScreenShortcut.this);
+ // Do nothing if `Cancel` is clicked.
}
});
@@ -93,7 +91,7 @@ public class CreateHomeScreenShortcut extends DialogFragment {
// Show the keyboard when the Dialog is displayed on the screen.
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- // We need to show the `AlertDialog` before we can call setOnKeyListener() below.
+ // We need to show `alertDialog` before we can call `setOnKeyListener()` below.
alertDialog.show();
// Allow the "enter" key on the keyboard to create the shortcut.
diff --git a/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java
new file mode 100644
index 00000000..4bdc879a
--- /dev/null
+++ b/app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java
@@ -0,0 +1,169 @@
+/**
+ * Copyright 2016 Soren Stoutner .
+ *
+ * This file is part of Privacy Browser .
+ *
+ * Privacy Browser is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Privacy Browser is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Privacy Browser. If not, see .
+ */
+
+package com.stoutner.privacybrowser;
+
+import android.app.Activity;
+import android.app.Dialog;
+import android.app.DialogFragment;
+import android.content.DialogInterface;
+import android.os.Bundle;
+// `android.support.v7.app.AlertDialog` uses more of the horizontal screen real estate versus `android.app.AlertDialog's` smaller width.
+import android.support.v7.app.AlertDialog;
+import android.view.KeyEvent;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import java.util.Locale;
+
+public class DownloadFile extends DialogFragment {
+
+ private String downloadUrl;
+ private String downloadFileName;
+ private String fileSize;
+
+ public static DownloadFile fromUrl(String urlString, String contentDisposition, long contentLength) {
+ // Create `argumentsBundle`.
+ Bundle argumentsBundle = new Bundle();
+
+ // If `contentDisposition` is empty, use Android's standard string of `downloadfile.bin`.
+ String fileNameString;
+ if (contentDisposition.isEmpty()) {
+ fileNameString = "downloadfile.bin";
+ } else {
+ // Extract `fileNameString` from `contentDisposition` using the substring beginning after `filename="` and ending one character before the end of `contentDisposition`.
+ fileNameString = contentDisposition.substring(contentDisposition.indexOf("filename=\"") + 10, contentDisposition.length() - 1);
+ }
+
+ // Convert `contentLength` to MB and store it in `fileSizeString`. `%.3g` displays the three most significant digits.
+ String fileSizeString = String.format(Locale.getDefault(), "%.3g", (float) contentLength / 1048576) + " MB";
+
+ // Store the variables in the `Bundle`.
+ argumentsBundle.putString("URL", urlString);
+ argumentsBundle.putString("File_Name", fileNameString);
+ argumentsBundle.putString("File_Size", fileSizeString);
+
+ // Add `argumentsBundle` to this instance of `DownloadFile`.
+ DownloadFile thisDownloadFileDialog = new DownloadFile();
+ thisDownloadFileDialog.setArguments(argumentsBundle);
+ return thisDownloadFileDialog;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // Store the strings in the local class variables.
+ downloadUrl = getArguments().getString("URL");
+ downloadFileName = getArguments().getString("File_Name");
+ fileSize = getArguments().getString("File_Size");
+ }
+
+ // The public interface is used to send information back to the parent activity.
+ public interface DownloadFileListener {
+ void onDownloadFile(DialogFragment dialogFragment, String downloadUrl);
+ }
+
+ // `downloadFileListener` is used in `onAttach()` and `onCreateDialog()`.
+ private DownloadFileListener downloadFileListener;
+
+ // Check to make sure tha the parent activity implements the listener.
+ public void onAttach(Activity parentActivity) {
+ super.onAttach(parentActivity);
+ try {
+ downloadFileListener = (DownloadFileListener) parentActivity;
+ } catch (ClassCastException exception) {
+ throw new ClassCastException(parentActivity.toString() + " must implement DownloadFileListener.");
+ }
+ }
+
+ @Override
+ public Dialog onCreateDialog(Bundle savedInstanceState) {
+ // Get the activity's layout inflater.
+ LayoutInflater layoutInflater = getActivity().getLayoutInflater();
+
+ // Use `AlertDialog.Builder` to create the `AlertDialog`. `R.style.lightAlertDialog` formats the color of the button text.
+ AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog);
+ dialogBuilder.setTitle(R.string.file_download);
+ // The parent view is `null` because it will be assigned by `AlertDialog`.
+ dialogBuilder.setView(layoutInflater.inflate(R.layout.download_file_dialog, null));
+
+ // Set an `onClick()` listener on the negative button.
+ dialogBuilder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // Do nothing if `Cancel` is clicked.
+ }
+ });
+
+ // Set an `onClick()` listener on the positive button
+ dialogBuilder.setPositiveButton(R.string.download, new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog, int which) {
+ // trigger `onDownloadFile()` and return the `DialogFragment` and the download URL to the parent activity.
+ downloadFileListener.onDownloadFile(DownloadFile.this, downloadUrl);
+ }
+ });
+
+
+ // Create an `AlertDialog` from the `AlertDialog.Builder`.
+ final AlertDialog alertDialog = dialogBuilder.create();
+
+ // Show the keyboard when `alertDialog` is displayed on the screen.
+ alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+
+ // We need to show `alertDialog` before we can modify the contents.
+ alertDialog.show();
+
+ // Set the text for `downloadFileSizeTextView`.
+ TextView downloadFileSizeTextView = (TextView) alertDialog.findViewById(R.id.download_file_size);
+ assert downloadFileSizeTextView != null; // Remove the warning of the following line that `downloadFileSizeTextView` might be null.
+ downloadFileSizeTextView.setText(fileSize);
+
+ // Set the text for `downloadFileNameTextView`.
+ EditText downloadFileNameTextView = (EditText) alertDialog.findViewById(R.id.download_file_name);
+ assert downloadFileNameTextView != null; // Remove the warning on the following line that `downloadFileNameTextView` might be null.
+ downloadFileNameTextView.setText(downloadFileName);
+
+ // Allow the `enter` key on the keyboard to save the file from `downloadFileNameTextView`.
+ downloadFileNameTextView.setOnKeyListener(new View.OnKeyListener() {
+ @Override
+ public boolean onKey (View v, int keyCode, KeyEvent event) {
+ // If the event is an `ACTION_DOWN` on the `enter` key, initiate the download.
+ if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
+ // trigger `onDownloadFile()` and return the `DialogFragment` and the URL to the parent activity.
+ downloadFileListener.onDownloadFile(DownloadFile.this, downloadUrl);
+ // Manually dismiss `alertDialog`.
+ alertDialog.dismiss();
+ // Consume the event.
+ return true;
+ } else { // If any other key was pressed, do not consume the event.
+ return false;
+ }
+ }
+ });
+
+
+ // `onCreateDialog` requires the return of an `AlertDialog`.
+ return alertDialog;
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java
index 61074703..ed6cc850 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java
@@ -38,8 +38,6 @@ import android.widget.ImageView;
public class EditBookmark extends DialogFragment {
// The public interface is used to send information back to the parent activity.
public interface EditBookmarkListener {
- void onCancelEditBookmark(DialogFragment dialogFragment);
-
void onSaveEditBookmark(DialogFragment dialogFragment);
}
@@ -77,8 +75,7 @@ public class EditBookmark extends DialogFragment {
dialogBuilder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- // Return the `DialogFragment` to the parent activity on cancel.
- editBookmarkListener.onCancelEditBookmark(EditBookmark.this);
+ // Do nothing. The `AlertDialog` will close automatically.
}
});
@@ -95,7 +92,7 @@ public class EditBookmark extends DialogFragment {
// Create an `AlertDialog` from the `AlertDialog.Builder`.
final AlertDialog alertDialog = dialogBuilder.create();
- // Show the keyboard when the `Dialog` is displayed on the screen.
+ // Show the keyboard when `alertDialog` is displayed on the screen.
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
// We need to show the `AlertDialog` before we can modify items in the layout.
@@ -122,10 +119,11 @@ public class EditBookmark extends DialogFragment {
// Allow the `enter` key on the keyboard to save the bookmark from `edit_bookmark_name_edittext`.
bookmarkNameEditText.setOnKeyListener(new View.OnKeyListener() {
+ @Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
- // If the event is a key-down on the "enter" button, select the PositiveButton `Save`.
+ // If the event is an `ACTION_DOWN` on the `enter` key, save the bookmark.
if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
- // Trigger `editBookmarkListener` and return the DialogFragment to the parent activity.
+ // Trigger `onSaveEditBookmark()` and return the `DialogFragment` to the parent activity.
editBookmarkListener.onSaveEditBookmark(EditBookmark.this);
// Manually dismiss `alertDialog`.
alertDialog.dismiss();
diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java
index 2becd6a1..70fb16e7 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java
@@ -38,8 +38,6 @@ import android.widget.ImageView;
public class EditBookmarkFolder extends DialogFragment {
// The public interface is used to send information back to the parent activity.
public interface EditBookmarkFolderListener {
- void onCancelEditBookmarkFolder(DialogFragment dialogFragment);
-
void onSaveEditBookmarkFolder(DialogFragment dialogFragment);
}
@@ -77,8 +75,7 @@ public class EditBookmarkFolder extends DialogFragment {
dialogBuilder.setNegativeButton(R.string.cancel, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
- // Return the `DialogFragment` to the parent activity on cancel.
- editBookmarkFolderListener.onCancelEditBookmarkFolder(EditBookmarkFolder.this);
+ // Do nothing. The `AlertDialog` will close automatically.
}
});
diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
index 2af787eb..4ac2ceed 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
@@ -72,7 +72,8 @@ import java.util.HashMap;
import java.util.Map;
// We need to use AppCompatActivity from android.support.v7.app.AppCompatActivity to have access to the SupportActionBar until the minimum API is >= 21.
-public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener, SslCertificateError.SslCertificateErrorListener {
+public class MainWebViewActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener, CreateHomeScreenShortcut.CreateHomeScreenSchortcutListener,
+ SslCertificateError.SslCertificateErrorListener, DownloadFile.DownloadFileListener {
// `favoriteIcon` is public static so it can be accessed from `CreateHomeScreenShortcut`, `BookmarksActivity`, `CreateBookmark`, `CreateBookmarkFolder`, and `EditBookmark`.
// It is also used in `onCreate()` and `onCreateHomeScreenShortcutCreate()`.
public static Bitmap favoriteIcon;
@@ -344,21 +345,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
// Allow the downloading of files.
mainWebView.setDownloadListener(new DownloadListener() {
- // Launch the Android download manager when a link leads to a download.
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
- DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
- DownloadManager.Request requestUri = new DownloadManager.Request(Uri.parse(url));
-
- // Add the URL as the description for the download.
- requestUri.setDescription(url);
-
- // Show the download notification after the download is completed.
- requestUri.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
-
- // Initiate the download and display a Snackbar.
- downloadManager.enqueue(requestUri);
- Snackbar.make(findViewById(R.id.mainWebView), R.string.download_started, Snackbar.LENGTH_SHORT).show();
+ // Show the `DownloadFile` `AlertDialog` and name this instance `@string/download`.
+ DialogFragment downloadFileDialogFragment = DownloadFile.fromUrl(url, contentDisposition, contentLength);
+ downloadFileDialogFragment.show(getFragmentManager(), getResources().getString(R.string.file_download));
}
});
@@ -828,7 +819,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
DialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut();
createHomeScreenShortcutDialogFragment.show(getFragmentManager(), getResources().getString(R.string.create_shortcut));
- //Everything else will be handled by CreateHomeScreenShortcut and the associated listeners below.
+ //Everything else will be handled by `CreateHomeScreenShortcut` and the associated listener below.
return true;
case R.id.refresh:
@@ -971,11 +962,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
invalidateOptionsMenu();
}
- @Override
- public void onCancelCreateHomeScreenShortcut(DialogFragment dialogFragment) {
- // Do nothing because the user selected "Cancel".
- }
-
@Override
public void onCreateHomeScreenShortcut(DialogFragment dialogFragment) {
// Get shortcutNameEditText from the alert dialog.
@@ -995,6 +981,32 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
sendBroadcast(placeBookmarkShortcut);
}
+ @Override
+ public void onDownloadFile(DialogFragment dialogFragment, String downloadUrl) {
+ DownloadManager downloadManager = (DownloadManager) getSystemService(DOWNLOAD_SERVICE);
+ DownloadManager.Request downloadRequest = new DownloadManager.Request(Uri.parse(downloadUrl));
+
+ // Get the file name from `dialogFragment`.
+ EditText downloadFileNameEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.download_file_name);
+ String fileName = downloadFileNameEditText.getText().toString();
+
+ // Set the download save in the the `DIRECTORY_DOWNLOADS`using `fileName`.
+ // Once we have `WRITE_EXTERNAL_STORAGE` permissions we can use `setDestinationInExternalPublicDir`.
+ downloadRequest.setDestinationInExternalFilesDir(this, "/", fileName);
+
+ // Allow `MediaScanner` to index the download if it is a media file.
+ downloadRequest.allowScanningByMediaScanner();
+
+ // Add the URL as the description for the download.
+ downloadRequest.setDescription(downloadUrl);
+
+ // Show the download notification after the download is completed.
+ downloadRequest.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED);
+
+ // Initiate the download and display a Snackbar.
+ downloadManager.enqueue(downloadRequest);
+ }
+
public void viewSslCertificate(View view) {
// Show the `ViewSslCertificate` `AlertDialog` and name this instance `@string/view_ssl_certificate`.
DialogFragment viewSslCertificateDialogFragment = new ViewSslCertificate();
diff --git a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java
index 52826504..e42b3926 100644
--- a/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java
+++ b/app/src/main/java/com/stoutner/privacybrowser/SslCertificateError.java
@@ -1,5 +1,5 @@
/**
- * Copyright 2015-2016 Soren Stoutner .
+ * Copyright 2016 Soren Stoutner .
*
* This file is part of Privacy Browser .
*
@@ -36,6 +36,7 @@ import android.widget.TextView;
import java.util.Date;
public class SslCertificateError extends DialogFragment{
+
private String primaryError;
private String urlWithError;
private String issuedToCName;
@@ -74,12 +75,13 @@ public class SslCertificateError extends DialogFragment{
argumentsBundle.putString("StartDate", startDateForBundle.toString());
argumentsBundle.putString("EndDate", endDateForBundle.toString());
- // Add the `Bundle` to this instance of `SslCertificateError`.
+ // Add `argumentsBundle` to this instance of `SslCertificateError`.
SslCertificateError thisSslCertificateErrorDialog = new SslCertificateError();
thisSslCertificateErrorDialog.setArguments(argumentsBundle);
return thisSslCertificateErrorDialog;
}
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
diff --git a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml
index 11469aff..c3e9e8c9 100644
--- a/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml
+++ b/app/src/main/res/layout/create_home_screen_shortcut_dialog.xml
@@ -32,9 +32,8 @@
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp" >
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/edit_bookmark_dialog.xml b/app/src/main/res/layout/edit_bookmark_dialog.xml
index 7bb2e454..039ba40d 100644
--- a/app/src/main/res/layout/edit_bookmark_dialog.xml
+++ b/app/src/main/res/layout/edit_bookmark_dialog.xml
@@ -91,9 +91,8 @@
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp" >
-
+
DOM Storage deleted
Open Navigation Drawer
Close Navigation Drawer
+ File Download
+ File name
+ Download
Favorite Icon
--
2.45.2