<w>coordinatorlayout</w>
<w>displayorder</w>
<w>dname</w>
+ <w>downloadfile</w>
<w>eadd</w>
<w>edittext</w>
<w>exynos</w>
This is accomplished by including a <a href="https://en.wikipedia.org/wiki/Do_Not_Track">DNT (Do Not Track) header</a> with web requests.
This header is enabled by default in Privacy Browser, although if desired it can be disabled in the settings.</p>
-<p>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.</p>
+<p>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.</p>
<h3>Advertisements</h3>
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.
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.
}
}
- @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`.
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.
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);
}
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.
}
});
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);
}
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.
}
});
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.
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.
}
});
// 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.
--- /dev/null
+/**
+ * Copyright 2016 Soren Stoutner <soren@stoutner.com>.
+ *
+ * This file is part of Privacy Browser <https://www.stoutner.com/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 <http://www.gnu.org/licenses/>.
+ */
+
+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
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);
}
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.
}
});
// 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.
// 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();
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);
}
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.
}
});
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;
// 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));
}
});
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:
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.
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();
/**
- * Copyright 2015-2016 Soren Stoutner <soren@stoutner.com>.
+ * Copyright 2016 Soren Stoutner <soren@stoutner.com>.
*
* This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
*
import java.util.Date;
public class SslCertificateError extends DialogFragment{
+
private String primaryError;
private String urlWithError;
private String issuedToCName;
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);
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp" >
- <!-- `android:imeOptions="actionGo"` sets the keyboard to have a "go" key instead of a "new line" key.
- `android:inputType="textUri"` disables spell check in the EditText.
- We can't use `android:imeOptions=flagNoExtractUi"` because it disables tapping to select in landscape orientation on small devices.-->
+ <!-- `android:imeOptions="actionGo"` sets the keyboard to have a `go` key instead of a `new line` key.
+ `android:inputType="textUri"` disables spell check in the `EditText`. -->
<android.support.design.widget.TextInputEditText
android:id="@+id/shortcut_name_edittext"
android:layout_height="wrap_content"
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?>
+
+<!--
+ Copyright 2016 Soren Stoutner <soren@stoutner.com>.
+
+ This file is part of Privacy Browser <https://www.stoutner.com/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 <http://www.gnu.org/licenses/>. -->
+
+<LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:orientation="vertical"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:padding="6dp">
+
+
+ <!-- `android.support.design.widget.TextInputLayout` makes the `android:hint` float above the `EditText`. -->
+ <android.support.design.widget.TextInputLayout
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent" >
+
+ <!-- `android:imeOptions="actionsGo"` sets the keyboard to have a `go` key instead of a `new line` key.
+ `android:inputType="textUri"` disables spell check in the `EditText`. -->
+ <android.support.design.widget.TextInputEditText
+ android:id="@+id/download_file_name"
+ android:layout_height="wrap_content"
+ android:layout_width="match_parent"
+ android:hint="@string/file_name"
+ android:imeOptions="actionGo"
+ android:inputType="textUri" />
+ </android.support.design.widget.TextInputLayout>
+
+ <TextView
+ android:id="@+id/download_file_size"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ android:layout_marginEnd="3dp"
+ android:layout_gravity="end" />
+</LinearLayout>
\ No newline at end of file
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp" >
- <!-- `android:imeOptions="actionGo"` sets the keyboard to have a "go" key instead of a "new line" key.
- `android:inputType="textUri"` disables spell check in the EditText.
- `android:singleLine="true"` is not needed in a Dialog.-->
+ <!-- `android:imeOptions="actionGo"` sets the keyboard to have a `go` key instead of a `new line` key.
+ `android:inputType="textUri"` disables spell check in the `EditText`. -->
<android.support.design.widget.TextInputEditText
android:id="@+id/edit_bookmark_name_edittext"
android:layout_height="wrap_content"
<string name="dom_storage_deleted">DOM Storage deleted</string>
<string name="open_navigation">Open Navigation Drawer</string>
<string name="close_navigation">Close Navigation Drawer</string>
+ <string name="file_download">File Download</string>
+ <string name="file_name">File name</string>
+ <string name="download">Download</string>
<!-- Custom App Bar. -->
<string name="favorite_icon">Favorite Icon</string>