]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/commitdiff
Fix crashing when creating or editing bookmarks with no favorite icon. Fixes https...
authorSoren Stoutner <soren@stoutner.com>
Wed, 17 Aug 2016 17:34:23 +0000 (10:34 -0700)
committerSoren Stoutner <soren@stoutner.com>
Wed, 17 Aug 2016 17:34:23 +0000 (10:34 -0700)
12 files changed:
app/src/main/assets/about_licenses.html
app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java
app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java
app/src/main/java/com/stoutner/privacybrowser/EditBookmarkFolder.java
app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
app/src/main/res/drawable-hdpi/world.png [new file with mode: 0644]
app/src/main/res/drawable-mdpi/folder_dark_blue.xml [deleted file]
app/src/main/res/drawable-mdpi/world.png [new file with mode: 0644]
app/src/main/res/drawable-xhdpi/world.png [new file with mode: 0644]
app/src/main/res/drawable-xxhdpi/world.png [new file with mode: 0644]
app/src/main/res/drawable/folder_dark_blue.xml [new file with mode: 0644]
app/src/main/res/drawable/world.xml [deleted file]

index f09fbb4257b637e305ddc22c81098af40b2c5299..9bd93d46e6358a36710022237a96c296fd779974 100644 (file)
@@ -57,6 +57,8 @@
     <img class="left" src="images/javascript_enabled.png" height="32" width="32">
     are derived from ic_security and ic_language. Modifications were made by Soren Stoutner in 2016.</p>
 
+<p>The following icons are unchanged except for layout information like color and size.  Some of them have been renamed to match their use in the code.  The original icons and names are shown below.</p>
+
 <p><img class="icon" src="images/ic_language.png"> ic_language.</p>
 
 <p><img class="icon" src="images/ic_home.png"> ic_home.</p>
index 9b9bfb71dc11e385c3316ef606079be1d36f2890..834889cbb8fa22743cd3d137b7b071e0a6a16a28 100644 (file)
@@ -33,7 +33,6 @@ import android.os.Bundle;
 import android.support.design.widget.FloatingActionButton;
 import android.support.design.widget.Snackbar;
 import android.support.v4.app.NavUtils;
-import android.support.v4.content.ContextCompat;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.widget.Toolbar;
@@ -542,8 +541,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
         EditText createBookmarkUrlEditText = (EditText) dialogFragment.getDialog().findViewById(R.id.create_bookmark_url_edittext);
         String bookmarkUrlString = createBookmarkUrlEditText.getText().toString();
 
-        // Convert the favoriteIcon Bitmap to a byte array.  `0` is for lossless compression (the only option for a PNG).
+        // Convert the favoriteIcon Bitmap to a byte array.
         ByteArrayOutputStream favoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
+        // `0` is for lossless compression (the only option for a PNG).
         MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, favoriteIconByteArrayOutputStream);
         byte[] favoriteIconByteArray = favoriteIconByteArrayOutputStream.toByteArray();
 
@@ -577,19 +577,20 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
             String cannotCreateFolder = getResources().getString(R.string.cannot_create_folder) + " \"" + folderNameString + "\"";
             Snackbar.make(findViewById(R.id.bookmarks_coordinatorlayout), cannotCreateFolder, Snackbar.LENGTH_INDEFINITE).show();
         } else {  // Create the folder.
-            // Get the new folder icon.
+            // Get the new folder icon `Bitmap`.
             RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon_radiobuttion);
             Bitmap folderIconBitmap;
             if (defaultFolderIconRadioButton.isChecked()) {
-                // Get the default folder icon drawable and convert it to a `Bitmap`.  `this` specifies the current context.
-                Drawable folderIconDrawable = ContextCompat.getDrawable(this, R.drawable.folder_blue_bitmap);
+                // Get the default folder icon `ImageView` from the `Dialog` and convert it to a `Bitmap`.
+                ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.create_folder_default_icon);
+                Drawable folderIconDrawable = folderIconImageView.getDrawable();
                 BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
                 folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-            } else {
+            } else {  // Assign `favoriteIcon` from the `WebView`.
                 folderIconBitmap = MainWebViewActivity.favoriteIcon;
             }
 
-            // Convert the folder `Bitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
+            // Convert `folderIconBitmap` to a byte array.  `0` is for lossless compression (the only option for a PNG).
             ByteArrayOutputStream folderIconByteArrayOutputStream = new ByteArrayOutputStream();
             folderIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, folderIconByteArrayOutputStream);
             byte[] folderIconByteArray = folderIconByteArrayOutputStream.toByteArray();
@@ -630,15 +631,9 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
 
         if (currentBookmarkIconRadioButton.isChecked()) {  // Update the bookmark without changing the favorite icon.
             bookmarksDatabaseHandler.updateBookmark(selectedBookmarkDatabaseId, bookmarkNameString, bookmarkUrlString);
-        } else {  // Update the bookmark and the favorite icon.
-            // Get the new favorite icon from the `Dialog` and convert it into a `Bitmap`.
-            ImageView newFavoriteIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_bookmark_web_page_favorite_icon);
-            Drawable newFavoriteIconDrawable = newFavoriteIconImageView.getDrawable();
-            Bitmap newFavoriteIconBitmap = ((BitmapDrawable) newFavoriteIconDrawable).getBitmap();
-
-            // Convert `newFavoriteIconBitmap` into a Byte Array.
+        } else {  // Update the bookmark using the `WebView` favorite icon.
             ByteArrayOutputStream newFavoriteIconByteArrayOutputStream = new ByteArrayOutputStream();
-            newFavoriteIconBitmap.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
+            MainWebViewActivity.favoriteIcon.compress(Bitmap.CompressFormat.PNG, 0, newFavoriteIconByteArrayOutputStream);
             byte[] newFavoriteIconByteArray = newFavoriteIconByteArrayOutputStream.toByteArray();
 
             //  Update the bookmark and the favorite icon.
@@ -676,11 +671,10 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
             // Get the `RadioButtons` from the `Dialog`.
             RadioButton currentFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_current_icon_radiobutton);
             RadioButton defaultFolderIconRadioButton = (RadioButton) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon_radiobutton);
-            Bitmap folderIconBitmap;
 
-            // Prepare the favorite icon.
+            // Check if the favorite icon has changed.
             if (currentFolderIconRadioButton.isChecked()) {
-                // Update the folder name if it has changed.
+                // Update the folder name if it has changed without modifying the favorite icon.
                 if (!newFolderNameString.equals(oldFolderNameString)) {
                     bookmarksDatabaseHandler.updateFolder(selectedFolderDatabaseId, oldFolderNameString, newFolderNameString);
 
@@ -688,13 +682,16 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma
                     updateBookmarksListView(currentFolder);
                     bookmarksListView.setSelection(selectedBookmarkPosition);
                 }
-            } else {  // Prepare the new favorite icon.
+            } else {  // Update the folder icon.
+                // Get the new folder icon `Bitmap`.
+                Bitmap folderIconBitmap;
                 if (defaultFolderIconRadioButton.isChecked()) {
-                    // Get the default folder icon drawable and convert it to a `Bitmap`.  `this` specifies the current context.
-                    Drawable folderIconDrawable = ContextCompat.getDrawable(this, R.drawable.folder_blue_bitmap);
+                    // Get the default folder icon `ImageView` from the `Drawable` and convert it to a `Bitmap`.
+                    ImageView folderIconImageView = (ImageView) dialogFragment.getDialog().findViewById(R.id.edit_folder_default_icon);
+                    Drawable folderIconDrawable = folderIconImageView.getDrawable();
                     BitmapDrawable folderIconBitmapDrawable = (BitmapDrawable) folderIconDrawable;
                     folderIconBitmap = folderIconBitmapDrawable.getBitmap();
-                } else {  // Use the web page favorite icon.
+                } else {  // Get the web page icon `ImageView` from the `Dialog`.
                     folderIconBitmap = MainWebViewActivity.favoriteIcon;
                 }
 
index 8343ace2ff3818dd3afb149604de1698a45459b3..61074703e2fd6871d60352eb418e35c27411467d 100644 (file)
@@ -26,8 +26,6 @@ import android.content.DialogInterface;
 import android.database.Cursor;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.drawable.BitmapDrawable;
-import android.graphics.drawable.Drawable;
 import android.os.Bundle;
 // If we don't use `android.support.v7.app.AlertDialog` instead of `android.app.AlertDialog` then the dialog will be covered by the keyboard.
 import android.support.v7.app.AlertDialog;
index c27b963dc3f7436ed53cc8b5457fe34a1aa41faf..2becd6a1c321d48965238e4d087bb7284a6321ec 100644 (file)
@@ -111,9 +111,9 @@ public class EditBookmarkFolder extends DialogFragment {
         currentIconImageView.setImageBitmap(currentIconBitmap);
 
         // Get a `Bitmap` of the favorite icon from `MainWebViewActivity` and display it in `edit_folder_web_page_favorite_icon`.
-        ImageView webPageFavoriteIcon = (ImageView) alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon);
-        assert webPageFavoriteIcon != null;  // Remove the warning below that `webPageFavoriteIcon` might be null.
-        webPageFavoriteIcon.setImageBitmap(MainWebViewActivity.favoriteIcon);
+        ImageView webPageFavoriteIconImageView = (ImageView) alertDialog.findViewById(R.id.edit_folder_web_page_favorite_icon);
+        assert webPageFavoriteIconImageView != null;  // Remove the warning below that `webPageFavoriteIcon` might be null.
+        webPageFavoriteIconImageView.setImageBitmap(MainWebViewActivity.favoriteIcon);
 
         // Load the text for `edit_folder_name_edittext`.
         EditText folderNameEditText = (EditText) alertDialog.findViewById(R.id.edit_folder_name_edittext);
index f10c2e45f561d0640f50fc92c22b4e4addbdcfac..bdafa3c9ff527aeb66af3e55222f941cbbd58093 100644 (file)
@@ -27,12 +27,15 @@ import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
+import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.Drawable;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.design.widget.NavigationView;
 import android.support.design.widget.Snackbar;
+import android.support.v4.content.ContextCompat;
 import android.support.v4.view.GravityCompat;
 import android.support.v4.widget.DrawerLayout;
 import android.support.v4.widget.SwipeRefreshLayout;
@@ -413,6 +416,14 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation
         // Load the initial website.
         mainWebView.loadUrl(formattedUrlString);
 
+        // Load the default favorite icon if it is null.
+        if (favoriteIcon == null) {
+            // We have to use `ContextCompat` until API >= 21.
+            Drawable favoriteIconDrawable = ContextCompat.getDrawable(getApplicationContext(), R.drawable.world);
+            BitmapDrawable favoriteIconBitmapDrawable = (BitmapDrawable) favoriteIconDrawable;
+            favoriteIcon = favoriteIconBitmapDrawable.getBitmap();
+        }
+
         // Initialize AdView for the free flavor and request an ad.  If this is not the free flavor BannerAd.requestAd() does nothing.
         adView = findViewById(R.id.adView);
         BannerAd.requestAd(adView);
diff --git a/app/src/main/res/drawable-hdpi/world.png b/app/src/main/res/drawable-hdpi/world.png
new file mode 100644 (file)
index 0000000..fcfe815
Binary files /dev/null and b/app/src/main/res/drawable-hdpi/world.png differ
diff --git a/app/src/main/res/drawable-mdpi/folder_dark_blue.xml b/app/src/main/res/drawable-mdpi/folder_dark_blue.xml
deleted file mode 100644 (file)
index ffa9477..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-<!-- folder_dark_blue.xml.xml comes from the Android Material icon set, where it is called ic_folder.
-  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>. -->
-
-<vector
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:height="24dp"
-    android:width="24dp"
-    android:viewportHeight="24.0"
-    android:viewportWidth="24.0" >
-
-    <path
-        android:fillColor="#FF0D47A1"
-        android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
-</vector>
diff --git a/app/src/main/res/drawable-mdpi/world.png b/app/src/main/res/drawable-mdpi/world.png
new file mode 100644 (file)
index 0000000..21b4cb2
Binary files /dev/null and b/app/src/main/res/drawable-mdpi/world.png differ
diff --git a/app/src/main/res/drawable-xhdpi/world.png b/app/src/main/res/drawable-xhdpi/world.png
new file mode 100644 (file)
index 0000000..6ba09e6
Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/world.png differ
diff --git a/app/src/main/res/drawable-xxhdpi/world.png b/app/src/main/res/drawable-xxhdpi/world.png
new file mode 100644 (file)
index 0000000..f6faee5
Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/world.png differ
diff --git a/app/src/main/res/drawable/folder_dark_blue.xml b/app/src/main/res/drawable/folder_dark_blue.xml
new file mode 100644 (file)
index 0000000..ffa9477
--- /dev/null
@@ -0,0 +1,14 @@
+<!-- folder_dark_blue.xml.xml comes from the Android Material icon set, where it is called ic_folder.
+  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>. -->
+
+<vector
+    xmlns:android="http://schemas.android.com/apk/res/android"
+    android:height="24dp"
+    android:width="24dp"
+    android:viewportHeight="24.0"
+    android:viewportWidth="24.0" >
+
+    <path
+        android:fillColor="#FF0D47A1"
+        android:pathData="M10,4H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2h-8l-2,-2z"/>
+</vector>
diff --git a/app/src/main/res/drawable/world.xml b/app/src/main/res/drawable/world.xml
deleted file mode 100644 (file)
index a472dca..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<!-- world.xml is part of the Android Material icon set, where it is named ic_language.
-  It is released under the CC-BY license <https://creativecommons.org/licenses/by/4.0/>.
-  Changes to fill color and size were made by Soren Stoutner <soren@stoutner.com> in 2016. -->
-
-<vector
-    xmlns:android="http://schemas.android.com/apk/res/android"
-    android:height="26dp"
-    android:width="26dp"
-    android:viewportHeight="24.0"
-    android:viewportWidth="24.0" >
-
-    <path
-        android:fillColor="#FF9E9E9E"
-        android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zm6.93,6h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2H4.26zm0.82,2h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zm2.95,-8H5.08c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14H9.66c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zm0.25,5.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z" />
-</vector>
\ No newline at end of file