]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Add a forward and back history list. Resolves https://redmine.stoutner.com/issues/24.
authorSoren Stoutner <soren@stoutner.com>
Wed, 9 Nov 2016 18:07:32 +0000 (11:07 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 9 Nov 2016 18:07:32 +0000 (11:07 -0700)
15 files changed:
.idea/misc.xml
app/src/main/assets/de/about_licenses.html
app/src/main/assets/en/about_licenses.html
app/src/main/assets/en/images/ic_list.png [new file with mode: 0644]
app/src/main/java/com/stoutner/privacybrowser/DownloadFile.java
app/src/main/java/com/stoutner/privacybrowser/History.java [new file with mode: 0644]
app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java [new file with mode: 0644]
app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java [new file with mode: 0644]
app/src/main/res/drawable/history.xml [new file with mode: 0644]
app/src/main/res/layout/url_history_dialog.xml [new file with mode: 0644]
app/src/main/res/layout/url_history_item_linearlayout.xml [new file with mode: 0644]
app/src/main/res/menu/webview_navigation_menu.xml
app/src/main/res/values-de/strings.xml
app/src/main/res/values/strings.xml

index 95f0f031062694350692a50d7adca27d559d5d41..1caa1363c93b174a058995cdabc9773e123ab3bc 100644 (file)
@@ -37,7 +37,7 @@
     <ConfirmationsSetting value="0" id="Add" />
     <ConfirmationsSetting value="0" id="Remove" />
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">
index 0ca96583cccd1fabd4a366f7fb5e41e0ed18f835..b09cce6339ac28e568ead9b784a41b87178dda6b 100644 (file)
@@ -72,6 +72,8 @@
 
 <p><img class="icon" src="../en/images/ic_bookmark_border.png"> ic_bookmark_border.</p>
 
+<p><img class="icon" src="../en/images/ic_close.png"> ic_close.</p>
+
 <p><img class="icon" src="../en/images/ic_create_new_folder.png"> ic_create_new_folder.</p>
 
 <p><img class="icon" src="../en/images/ic_delete.png"> ic_download.</p>
 
 <p><img class="icon" src="../en/images/ic_exit_to_app.png"> ic_exit_to_app.</p>
 
+<p><img class="icon" src="../en/images/ic_expand_less.png"> ic_expand_less.</p>
+
+<p><img class="icon" src="../en/images/ic_expand_more.png"> ic_expand_more.</p>
+
 <p><img class="icon" src="../en/images/ic_file_download.png"> ic_file_download.</p>
 
 <p><img class="icon" src="../en/images/ic_folder.png"> ic_folder.</p>
 
 <p><img class="icon" src="../en/images/ic_language.png"> ic_language.</p>
 
+<p><img class="icon" src="../en/images/ic_list.png"> ic_list.</p>
+
 <p><img class="icon" src="../en/images/ic_select_all.png"> ic_select_all.</p>
 
 <p><img class="icon" src="../en/images/ic_settings.png"> ic_settings.</p>
 
 <p><img class="icon" src="../en/images/ic_web.png"> ic_web.</p>
 
-<p><img class="icon" src="../en/images/ic_expand_less.png"> ic_expand_less.</p>
-
-<p><img class="icon" src="../en/images/ic_expand_more.png"> ic_expand_more.</p>
-
-<p><img class="icon" src="../en/images/ic_close.png"> ic_close.</p>
-
 <br/>
 
 <p><img class="left" src="../en/images/cookie.png"> Cookie wurde von Google erstellt.
index 3ee97602c7f410f83e678dc36cea71eba0b63be0..13edb7ea84ddae2141946097a08c9d1e7d7bbce2 100644 (file)
@@ -69,6 +69,8 @@
 
 <p><img class="icon" src="images/ic_bookmark_border.png"> ic_bookmark_border.</p>
 
+<p><img class="icon" src="images/ic_close.png"> ic_close.</p>
+
 <p><img class="icon" src="images/ic_create_new_folder.png"> ic_create_new_folder.</p>
 
 <p><img class="icon" src="images/ic_delete.png"> ic_download.</p>
 
 <p><img class="icon" src="images/ic_exit_to_app.png"> ic_exit_to_app.</p>
 
+<p><img class="icon" src="images/ic_expand_less.png"> ic_expand_less.</p>
+
+<p><img class="icon" src="images/ic_expand_more.png"> ic_expand_more.</p>
+
 <p><img class="icon" src="images/ic_file_download.png"> ic_file_download.</p>
 
 <p><img class="icon" src="images/ic_folder.png"> ic_folder.</p>
@@ -91,6 +97,8 @@
 
 <p><img class="icon" src="images/ic_language.png"> ic_language.</p>
 
+<p><img class="icon" src="images/ic_list.png"> ic_list.</p>
+
 <p><img class="icon" src="images/ic_select_all.png"> ic_select_all.</p>
 
 <p><img class="icon" src="images/ic_settings.png"> ic_settings.</p>
 
 <p><img class="icon" src="images/ic_web.png"> ic_web.</p>
 
-<p><img class="icon" src="images/ic_expand_less.png"> ic_expand_less.</p>
-
-<p><img class="icon" src="images/ic_expand_more.png"> ic_expand_more.</p>
-
-<p><img class="icon" src="images/ic_close.png"> ic_close.</p>
-
 <br/>
 
 <p><img class="left" src="images/cookie.png"> cookie was created by Google.
diff --git a/app/src/main/assets/en/images/ic_list.png b/app/src/main/assets/en/images/ic_list.png
new file mode 100644 (file)
index 0000000..786df41
Binary files /dev/null and b/app/src/main/assets/en/images/ic_list.png differ
index 8e04cf64f29bfa279a96343fc3f929f67415ec26..1a68f71fd82dd479365d7a91c82b2ba11434c5fa 100644 (file)
@@ -101,10 +101,11 @@ public class DownloadFile extends AppCompatDialogFragment {
     // `downloadFileListener` is used in `onAttach()` and `onCreateDialog()`.
     private DownloadFileListener downloadFileListener;
 
-    // Check to make sure tha the parent activity implements the listener.
     @Override
     public void onAttach(Context context) {
         super.onAttach(context);
+
+        // Check to make sure the parent activity implements the listener.
         try {
             downloadFileListener = (DownloadFileListener) context;
         } catch (ClassCastException exception) {
@@ -112,25 +113,28 @@ public class DownloadFile extends AppCompatDialogFragment {
         }
     }
 
-    // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
-    @SuppressLint("InflateParams")
     @Override
     @NonNull
+    // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
+    @SuppressLint("InflateParams")
     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);
+
+        // Set the title.
         dialogBuilder.setTitle(R.string.save_as);
-        // The parent view is `null` because it will be assigned by `AlertDialog`.
+
+        // Set the view.  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.
+                // Do nothing if `Cancel` is clicked.  The `Dialog` will automatically close.
             }
         });
 
@@ -143,7 +147,6 @@ public class DownloadFile extends AppCompatDialogFragment {
             }
         });
 
-
         // Create an `AlertDialog` from the `AlertDialog.Builder`.
         final AlertDialog alertDialog = dialogBuilder.create();
 
@@ -184,7 +187,6 @@ public class DownloadFile extends AppCompatDialogFragment {
             }
         });
 
-
         // `onCreateDialog` requires the return of an `AlertDialog`.
         return alertDialog;
     }
diff --git a/app/src/main/java/com/stoutner/privacybrowser/History.java b/app/src/main/java/com/stoutner/privacybrowser/History.java
new file mode 100644 (file)
index 0000000..0548c2b
--- /dev/null
@@ -0,0 +1,35 @@
+/**
+ * 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.graphics.Bitmap;
+
+// Create a `History` object.
+class History {
+    // Create the `History` package-local variables.
+    Bitmap entryFavoriteIcon;
+    String entryUrl;
+
+    History(Bitmap entryFavoriteIcon, String entryUrl){
+        // Populate the package-local variables.
+        this.entryFavoriteIcon = entryFavoriteIcon;
+        this.entryUrl = entryUrl;
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java b/app/src/main/java/com/stoutner/privacybrowser/HistoryArrayAdapter.java
new file mode 100644 (file)
index 0000000..414f5fc
--- /dev/null
@@ -0,0 +1,80 @@
+/**
+ * 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.content.Context;
+import android.support.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.ArrayAdapter;
+import android.widget.ImageView;
+import android.widget.TextView;
+
+import java.util.ArrayList;
+
+class HistoryArrayAdapter extends ArrayAdapter<History> {
+
+    // `currentPage` is used in `HistoryArrayAdapter` and `getView()`.
+    private int currentPage;
+
+    HistoryArrayAdapter(Context context, ArrayList<History> historyArrayList, int currentPageId) {
+        // We need to call `super` from the base `ArrayAdapter`.  `0` is the `textViewResourceId`.
+        super(context, 0, historyArrayList);
+
+        // Store `currentPageId` in the class variable.
+        currentPage = currentPageId;
+    }
+
+    @Override
+    @NonNull
+    public View getView(int position, View convertView, @NonNull ViewGroup parent) {
+        // Inflate the view if it is `null`.
+        if (convertView == null) {
+            // `false` does not attach `url_history_item_linearlayout` to `parent`.
+            convertView = LayoutInflater.from(getContext()).inflate(R.layout.url_history_item_linearlayout, parent, false);
+        }
+
+        // Get handles for `favoriteIconImageView` and `urlTextView`.
+        ImageView favoriteIconImageView = (ImageView) convertView.findViewById(R.id.history_favorite_icon_imageview);
+        TextView urlTextView = (TextView) convertView.findViewById(R.id.history_url_textview);
+
+        // Get the URL history for this position.
+        History history = getItem(position);
+
+        // Remove the lint warning below that `history` might be `null`.
+        assert history != null;
+
+        // Set `favoriteIconImageView` and `urlTextView`.
+        favoriteIconImageView.setImageBitmap(history.entryFavoriteIcon);
+        urlTextView.setText(history.entryUrl);
+
+        // Set the URL text for `currentPage` to be grey.
+        if (position == currentPage) {
+            urlTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.grey_500));
+        } else {
+            urlTextView.setTextColor(ContextCompat.getColor(getContext(), R.color.black));
+        }
+
+        // Return the modified `convertView`.
+        return convertView;
+    }
+}
\ No newline at end of file
index 69ac5441e4831e920c61ba67aa27b8630e0616fd..779d2d69b91a0e1c6d299c4dab2315439a063a75 100644 (file)
@@ -62,6 +62,7 @@ import android.view.inputmethod.InputMethodManager;
 import android.webkit.CookieManager;
 import android.webkit.DownloadListener;
 import android.webkit.SslErrorHandler;
+import android.webkit.WebBackForwardList;
 import android.webkit.WebChromeClient;
 import android.webkit.WebStorage;
 import android.webkit.WebView;
@@ -84,7 +85,7 @@ 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, DownloadFile.DownloadFileListener, DownloadImage.DownloadImageListener {
+        SslCertificateError.SslCertificateErrorListener, DownloadFile.DownloadFileListener, DownloadImage.DownloadImageListener, UrlHistory.UrlHistoryListener {
 
     // `appBar` is public static so it can be accessed from `OrbotProxyHelper`.
     // It is also used in `onCreate()`, `onOptionsItemSelected()`, and `closeFindOnPage()`.
@@ -294,6 +295,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         final Menu navigationMenu = navigationView.getMenu();
         final MenuItem navigationBackMenuItem = navigationMenu.getItem(1);
         final MenuItem navigationForwardMenuItem = navigationMenu.getItem(2);
+        final MenuItem navigationHistoryMenuItem = navigationMenu.getItem(3);
 
         // The `DrawerListener` allows us to update the Navigation Menu.
         drawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
@@ -311,9 +313,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
 
             @Override
             public void onDrawerStateChanged(int newState) {
-                // Update the back and forward menu items every time the drawer opens.
+                // Update the `Back`, `Forward`, and `History` menu items every time the drawer opens.
                 navigationBackMenuItem.setEnabled(mainWebView.canGoBack());
                 navigationForwardMenuItem.setEnabled(mainWebView.canGoForward());
+                navigationHistoryMenuItem.setEnabled((mainWebView.canGoBack() || mainWebView.canGoForward()));
 
                 // Hide the keyboard so we can see the navigation menu.  `0` indicates no additional flags.
                 inputMethodManager.hideSoftInputFromWindow(mainWebView.getWindowToken(), 0);
@@ -878,7 +881,7 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 return true;
 
             case R.id.addToHomescreen:
-                // Show the `CreateHomeScreenShortcut` `AlertDialog` and name this instance `@string/create_shortcut`.
+                // Show the `CreateHomeScreenShortcut` `AlertDialog` and name this instance `R.string.create_shortcut`.
                 AppCompatDialogFragment createHomeScreenShortcutDialogFragment = new CreateHomeScreenShortcut();
                 createHomeScreenShortcutDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.create_shortcut));
 
@@ -929,6 +932,15 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
                 }
                 break;
 
+            case R.id.history:
+                // Gte the `WebBackForwardList`.
+                WebBackForwardList webBackForwardList = mainWebView.copyBackForwardList();
+
+                // Show the `UrlHistory` `AlertDialog` and name this instance `R.string.history`.  `this` is the `Context`.
+                AppCompatDialogFragment urlHistoryDialogFragment = UrlHistory.loadBackForwardList(this, webBackForwardList);
+                urlHistoryDialogFragment.show(getSupportFragmentManager(), getResources().getString(R.string.history));
+                break;
+
             case R.id.bookmarks:
                 // Launch BookmarksActivity.
                 Intent bookmarksIntent = new Intent(this, BookmarksActivity.class);
@@ -1270,6 +1282,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         sslErrorHandler.proceed();
     }
 
+    @Override
+    public void onUrlHistoryEntrySelected(int moveBackOrForwardSteps) {
+        // Load the history entry.
+        mainWebView.goBackOrForward(moveBackOrForwardSteps);
+    }
+
     // Override onBackPressed to handle the navigation drawer and mainWebView.
     @Override
     public void onBackPressed() {
diff --git a/app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java b/app/src/main/java/com/stoutner/privacybrowser/UrlHistory.java
new file mode 100644 (file)
index 0000000..d2d4fec
--- /dev/null
@@ -0,0 +1,240 @@
+/**
+ * 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.annotation.SuppressLint;
+import android.app.Dialog;
+import android.content.Context;
+import android.content.DialogInterface;
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
+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.annotation.NonNull;
+import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AlertDialog;
+import android.support.v7.app.AppCompatDialogFragment;
+import android.util.Base64;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.webkit.WebBackForwardList;
+import android.widget.AdapterView;
+import android.widget.ListView;
+
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+
+public class UrlHistory extends AppCompatDialogFragment{
+
+    // `historyArrayList`  and `currentPageId` pass information from `onCreate()` to `onCreateDialog()`.
+    private ArrayList<History> historyArrayList = new ArrayList<>();
+    private int currentPageId;
+
+    public static UrlHistory loadBackForwardList(Context context, WebBackForwardList webBackForwardList) {
+        // Create `argumentsBundle`.
+        Bundle argumentsBundle = new Bundle();
+
+        // Store `currentPageIndex`.
+        int currentPageIndex = webBackForwardList.getCurrentIndex();
+
+        // Setup `urlArrayList` and `iconArrayList`.
+        ArrayList<String> urlArrayList = new ArrayList<>();
+        ArrayList<String> iconBase64StringArrayList = new ArrayList<>();
+
+        // Get the default favorite icon `Drawable`.
+        Drawable defaultFavoriteIconDrawable = ContextCompat.getDrawable(context, R.drawable.world);
+
+        // Convert `defaultFavoriteIconDrawable` to a `BitmapDrawable`.
+        BitmapDrawable defaultFavoriteIconBitmapDrawable = (BitmapDrawable) defaultFavoriteIconDrawable;
+
+        // Extract a `Bitmap` from `defaultFavoriteIconBitmapDrawable`.
+        Bitmap defaultFavoriteIcon = defaultFavoriteIconBitmapDrawable.getBitmap();
+
+        // Populate `urlArrayList` and `iconArrayList` from `webBackForwardList`.
+        for (int i=0; i < webBackForwardList.getSize(); i++) {
+            // Store the URL.
+            urlArrayList.add(webBackForwardList.getItemAtIndex(i).getUrl());
+
+            // Create a variable to store the icon `Bitmap`.
+            Bitmap iconBitmap;
+
+            // Store the icon `Bitmap`.
+            if (webBackForwardList.getItemAtIndex(i).getFavicon() == null) {
+                // If `webBackForwardList` does not have a favorite icon, use Privacy Browser's default world icon.
+                iconBitmap = defaultFavoriteIcon;
+            } else {  // Get the icon from `webBackForwardList`.
+                iconBitmap = webBackForwardList.getItemAtIndex(i).getFavicon();
+            }
+
+            // Create a `ByteArrayOutputStream`.
+            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+
+            // Convert the favorite icon `Bitmap` to a `ByteArrayOutputStream`.  `100` is the compression quality, which is ignored by `PNG`.
+            iconBitmap.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
+
+            // Convert the favorite icon `ByteArrayOutputStream` to a `byte[]`.
+            byte[] byteArray = byteArrayOutputStream.toByteArray();
+
+            // Encode the favorite icon `byte[]` as a Base64 `String`.
+            String iconBase64String = Base64.encodeToString(byteArray, Base64.DEFAULT);
+
+            // Store the favorite icon Base64 `String` in `iconBase64StringArrayList`.
+            iconBase64StringArrayList.add(iconBase64String);
+        }
+
+        // Store the variables in the `Bundle`.
+        argumentsBundle.putInt("Current_Page", currentPageIndex);
+        argumentsBundle.putStringArrayList("URL_History", urlArrayList);
+        argumentsBundle.putStringArrayList("Favorite_Icons", iconBase64StringArrayList);
+
+        // Add `argumentsBundle` to this instance of `UrlHistory`.
+        UrlHistory thisUrlHistoryDialog = new UrlHistory();
+        thisUrlHistoryDialog.setArguments(argumentsBundle);
+        return thisUrlHistoryDialog;
+    }
+
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        // Get the `ArrayLists` from the `Arguments`.
+        ArrayList<String> urlStringArrayList = getArguments().getStringArrayList("URL_History");
+        ArrayList<String> favoriteIconBase64StringArrayList = getArguments().getStringArrayList("Favorite_Icons");
+
+        // Remove the lint warning below that the `ArrayLists` might be `null`.
+        assert urlStringArrayList != null;
+        assert favoriteIconBase64StringArrayList != null;
+
+        // Populate `historyArrayList`.  We go down from `urlStringArrayList.size()` so that the newest entries are at the top.  `-1` is needed because `historyArrayList` is zero-based.
+        for (int i=urlStringArrayList.size() -1; i >= 0; i--) {
+            // Decode the favorite icon Base64 `String` to a `byte[]`.
+            byte[] favoriteIconByteArray = Base64.decode(favoriteIconBase64StringArrayList.get(i), Base64.DEFAULT);
+
+            // Convert the favorite icon `byte[]` to a `Bitmap`.  `0` is the starting offset.
+            Bitmap favoriteIconBitmap = BitmapFactory.decodeByteArray(favoriteIconByteArray, 0, favoriteIconByteArray.length);
+
+            // Store the favorite icon and the URL in `historyEntry`.
+            History historyEntry = new History(favoriteIconBitmap, urlStringArrayList.get(i));
+
+            // Add this history entry to `historyArrayList`.
+            historyArrayList.add(historyEntry);
+        }
+
+        // Get the original current page ID.
+        int originalCurrentPageId = getArguments().getInt("Current_Page");
+
+        // Subtract `originalCurrentPageId` from the array size because we reversed the order of the array so that the newest entries are at the top.  `-1` is needed because the array is zero-based.
+        currentPageId = urlStringArrayList.size() - 1 - originalCurrentPageId;
+    }
+
+    // The public interface is used to send information back to the parent activity.
+    public interface UrlHistoryListener {
+        // Send back the number of steps to move forward or back.
+        void onUrlHistoryEntrySelected(int moveBackOrForwardSteps);
+    }
+
+    // `urlHistoryListener` is used in `onAttach()` and `onCreateDialog()`.
+    private UrlHistoryListener urlHistoryListener;
+
+    @Override
+    public void onAttach(Context context) {
+        super.onAttach(context);
+
+        // Check to make sure tha the parent activity implements the listener.
+        try {
+            urlHistoryListener = (UrlHistoryListener) context;
+        } catch (ClassCastException exception) {
+            throw new ClassCastException(context.toString() + " must implement UrlHistoryListener.");
+        }
+    }
+
+    @Override
+    @NonNull
+    // `@SuppressLing("InflateParams")` removes the warning about using `null` as the parent view group when inflating the `AlertDialog`.
+    @SuppressLint("InflateParams")
+    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);
+
+        // Set the title.
+        dialogBuilder.setTitle(R.string.history);
+
+        // Set the view.  The parent view is `null` because it will be assigned by `AlertDialog`.
+        dialogBuilder.setView(layoutInflater.inflate(R.layout.url_history_dialog, null));
+
+        // Set an `onClick()` listener on the negative button.
+        dialogBuilder.setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
+            @Override
+            public void onClick(DialogInterface dialog, int which) {
+                // Do nothing if `Close` is clicked.  The `Dialog` will automatically close.
+            }
+        });
+
+        // Create an `AlertDialog` from the `AlertDialog.Builder`.
+        final AlertDialog alertDialog = dialogBuilder.create();
+
+        // We need to show `alertDialog` before we can modify the contents.
+        alertDialog.show();
+
+        // Instantiate a `HistoryArrayAdapter`.
+        final HistoryArrayAdapter historyArrayAdapter = new HistoryArrayAdapter(getContext(), historyArrayList, currentPageId);
+
+        // Get a handle for `listView`.
+        ListView listView = (ListView) alertDialog.findViewById(R.id.history_listview);
+
+        // Remove the warning below that `listView` might be `null`.
+        assert listView != null;
+
+        // Set the adapter on `listView`.
+        listView.setAdapter(historyArrayAdapter);
+
+        // Listen for clicks on entries in `listView`.
+        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
+            @Override
+            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+                // Convert the `long` `id` to an `int`.
+                int itemId = (int) id;
+
+                // Only enable the click if it is not on the `currentPageId`.
+                if (itemId != currentPageId) {
+                    // Get the history entry for this `itemId`.
+                    History historyEntry = historyArrayAdapter.getItem(itemId);
+
+                    // Remove the lint warning below that `historyEntry` might be `null`.
+                    assert historyEntry != null;
+
+                    // Send the history entry URL to be loaded in `mainWebView`.
+                    urlHistoryListener.onUrlHistoryEntrySelected(currentPageId - itemId);
+
+                    // Dismiss the `Dialog`.
+                    alertDialog.dismiss();
+                }
+            }
+        });
+
+        // `onCreateDialog` requires the return of an `AlertDialog`.
+        return alertDialog;
+    }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/history.xml b/app/src/main/res/drawable/history.xml
new file mode 100644 (file)
index 0000000..83e95cb
--- /dev/null
@@ -0,0 +1,19 @@
+<!-- history.xml comes from the Android Material icon set, where it is called ic_list.
+    It is released under the Apache License 2.0. -->
+
+<!-- `tools:ignore="VectorRaster"` removes the lint warning about `android:autoMirrored="true" not applying to API < 21. -->
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0"
+    android:autoMirrored="true"
+    tools:ignore="VectorRaster" >
+
+    <!-- We have to use a hard coded color code until API >= 21.  Then we can use `@color`. -->
+    <path
+        android:fillColor="#FF000000"
+        android:pathData="M3,13h2v-2L3,11v2zM3,17h2v-2L3,15v2zM3,9h2L5,7L3,7v2zM7,13h14v-2L7,11v2zM7,17h14v-2L7,15v2zM7,7v2h14L21,7L7,7z" />
+</vector>
diff --git a/app/src/main/res/layout/url_history_dialog.xml b/app/src/main/res/layout/url_history_dialog.xml
new file mode 100644 (file)
index 0000000..0a32dfc
--- /dev/null
@@ -0,0 +1,25 @@
+<?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/>. -->
+
+<ListView
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@+id/history_listview"
+    android:layout_height="wrap_content"
+    android:layout_width="wrap_content" />
\ No newline at end of file
diff --git a/app/src/main/res/layout/url_history_item_linearlayout.xml b/app/src/main/res/layout/url_history_item_linearlayout.xml
new file mode 100644 (file)
index 0000000..bcd02ae
--- /dev/null
@@ -0,0 +1,47 @@
+<?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
+    android:id="@+id/history_item_linearlayout"
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_height="wrap_content"
+    android:layout_width="match_parent"
+    android:orientation="horizontal"
+    android:background="@drawable/bookmarks_list_selector" >
+
+    <ImageView
+        android:id="@+id/history_favorite_icon_imageview"
+        android:layout_height="30dp"
+        android:layout_width="30dp"
+        android:layout_gravity="center_vertical"
+        android:layout_marginStart="10dp"
+        tools:ignore="ContentDescription" />
+
+    <TextView
+        android:id="@+id/history_url_textview"
+        android:layout_height="wrap_content"
+        android:layout_width="wrap_content"
+        android:textColor="@color/black"
+        android:textSize="16sp"
+        android:layout_margin="10dp"
+        android:maxLines="1"
+        android:ellipsize="end"/>
+</LinearLayout>
\ No newline at end of file
index 756013c3ae2200cdc54382da99202bd6ee7421f8..de2c0a5d3abc901c7bfdcb37d76bdf206efcb5d9 100644 (file)
         android:icon="@drawable/forward"
         android:orderInCategory="30" />
 
+    <item
+        android:id="@+id/history"
+        android:title="@string/history"
+        android:icon="@drawable/history"
+        android:orderInCategory="40" />
+
     <!-- If a group has an id, a line is drawn above it in the navigation view. -->
     <group
         android:id="@+id/navigationGroup1" >
             android:id="@+id/bookmarks"
             android:title="@string/bookmarks"
             android:icon="@drawable/bookmarks"
-            android:orderInCategory="40" />
+            android:orderInCategory="50" />
 
         <item
             android:id="@+id/downloads"
             android:title="@string/downloads"
             android:icon="@drawable/downloads"
-            android:orderInCategory="50" />
+            android:orderInCategory="60" />
     </group>
 
     <group
             android:id="@+id/settings"
             android:title="@string/settings"
             android:icon="@drawable/settings"
-            android:orderInCategory="60" />
+            android:orderInCategory="70" />
 
         <item
             android:id="@+id/guide"
             android:title="@string/guide"
             android:icon="@drawable/guide"
-            android:orderInCategory="70" />
+            android:orderInCategory="80" />
 
         <item
             android:id="@+id/about"
             android:title="@string/about"
             android:icon="@drawable/about"
-            android:orderInCategory="80" />
+            android:orderInCategory="90" />
     </group>
 
     <!-- If a group has an id, a line is drawn above it in the navigation view. -->
@@ -82,6 +88,6 @@
             android:id="@+id/clearAndExit"
             android:title="@string/clear_and_exit"
             android:icon="@drawable/exit"
-            android:orderInCategory="90" />
+            android:orderInCategory="100" />
     </group>
 </menu>
\ No newline at end of file
index f9560d07219943e3ff0d63cf4452436453901b7b..5ba95cf3dbef2c04dd46092a720a0230bb229769 100644 (file)
@@ -91,6 +91,7 @@
     <string name="home">Startseite</string>
     <string name="back">Zurück</string>
     <string name="forward">Vorwärts</string>
+    <string name="history">Verlauf</string>
     <string name="bookmarks">Lesezeichen</string>
     <string name="downloads">Downloads</string>
     <string name="settings">Einstellungen</string>
index f92bd8397b31574c9459094616009db85fbc69d3..26f41f3b3eb429b9550e5c02bb4b3af59f092b4f 100644 (file)
@@ -90,6 +90,7 @@
     <string name="home">Home</string>
     <string name="back">Back</string>
     <string name="forward">Forward</string>
+    <string name="history">History</string>
     <string name="bookmarks">Bookmarks</string>
     <string name="downloads">Downloads</string>
     <string name="settings">Settings</string>