From bf644cc5270aca79529a87f19cbd04d3f5313f32 Mon Sep 17 00:00:00 2001 From: Soren Stoutner Date: Tue, 12 Jul 2016 11:48:13 -0700 Subject: [PATCH] Add the ability to select all bookmarks. --- app/build.gradle | 4 +- app/src/main/AndroidManifest.xml | 3 +- app/src/main/assets/about_licenses.html | 2 + app/src/main/assets/images/ic_select_all.png | Bin 0 -> 973 bytes .../privacybrowser/BookmarksActivity.java | 58 +++++++++++++++++- .../privacybrowser/CreateBookmark.java | 2 +- .../CreateHomeScreenShortcut.java | 2 +- .../stoutner/privacybrowser/EditBookmark.java | 2 +- app/src/main/res/drawable/select_all.xml | 14 +++++ .../res/layout/about_coordinatorlayout.xml | 6 +- .../layout/bookmarks_coordinatorlayout.xml | 6 +- .../res/layout/guide_coordinatorlayout.xml | 6 +- .../res/layout/main_coordinatorlayout.xml | 4 +- .../main/res/menu/bookmarks_context_menu.xml | 7 +++ ...options.xml => bookmarks_options_menu.xml} | 6 +- app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 24 +++----- 17 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 app/src/main/assets/images/ic_select_all.png create mode 100644 app/src/main/res/drawable/select_all.xml rename app/src/main/res/menu/{menu_bookmarks_options.xml => bookmarks_options_menu.xml} (87%) diff --git a/app/build.gradle b/app/build.gradle index 9b770e4e..8b0f695b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -54,6 +54,6 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:design:23.4.0' - // Only compile com.google.android.gms:play-services-ads for the free version. - freeCompile 'com.google.android.gms:play-services-ads:9.2.0' + // Only compile `com.google.android.gms:play-services-ads` for the free flavor. + freeCompile 'com.google.android.gms:play-services-ads:9.2.1' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 246393e9..17fb93ab 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -49,7 +49,6 @@ @@ -86,7 +85,7 @@ diff --git a/app/src/main/assets/about_licenses.html b/app/src/main/assets/about_licenses.html index 6ff69285..bb6fa1a2 100644 --- a/app/src/main/assets/about_licenses.html +++ b/app/src/main/assets/about_licenses.html @@ -80,6 +80,8 @@

ic_edit.

ic_download.

+ +

ic_select_all


GNU General Public License

diff --git a/app/src/main/assets/images/ic_select_all.png b/app/src/main/assets/images/ic_select_all.png new file mode 100644 index 0000000000000000000000000000000000000000..92aab4e2f40c82c0d17352de384b4c411d8c3f17 GIT binary patch literal 973 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1|$#LC7uRSEX7WqAsj$Z!;#Vf4nJ zsJsMW#sHP)KY)UgC9V-A!TD(=<%vb94CUqJdYO6I#mR{Use1WE>9gP2NHH)ldwIGz zhE&XXd)GEQ#8IN{VRWzNCuWyF8Ycf3Sf_UM&b<|>64unzvDa72(S>{VjjrBav$}?< z)4CM&v>wR|T+9%B6Wr1ucHGIeFzvkc?3{bQn{p4mDK7Jq`=+w_aO4CP&q*+(wVi(k z`#i?(1ADuk-(%k=Zs&D2H050AlWA%9)}PqJUbD=){PTg5qs6OzOitY4i(x*;7+v@C z=QXzDw^nRp+FftgcX94{>jS9?nx7nID<5w7dm#IP&Hn$NuAXNpV60%5>Eh|rIiUDJ zH8%U|F}??u1qNCMs~B!K9zPHgFz;V(*SnbfZjNrP1EsslvP{aD!j+qpxHj-xNKaU7 z^}KO!t+NuBL3{m&wXK{9+wwhJ82i{$GAz`8v$=>Y_ER9U17`~K)9+@P{=a;9?;O7) z>5Qh<8Qy12PRWWZ&#wQnETC7Cd%_%6k8?~a>5P*$Gn|ZUc%tJ_B&M*lW9os9r%wv) z>dxA7d3}w#xAvhmNZb;e^2K+Af3Q}F7VP2aW7y4geA>PF3ucOK_sT6?eIx8x)xS6< zWRsCi=#JphyL;e=>Vt^LJ1H*Sdjwe{K5u=&n~^eqW(6mvqaa%K7BT3Wxo)$lTkX!B z$8|L$0_tRBgMmKjE%JW=3Z*wYPT18$6F|1wBkt+%m?pD6W;@`N_)K-z`T+gFs`{px z^LMI>X~g&G-hFc`>7Vw2nTO7#*%``h_nN!BTF7Zz91 z1WpT99rmX$?@xPq?(6oB4JT|H^BWf*cz(d=?>p@Ro(geMiM^U%Yzt<*`}IV=tuU-H z`T*kt-;{zQ%P!dKGKx1!AJ8danz1Z;YtT&5UFDbfOa7oIt``njxgN@xNAkf@z2 literal 0 HcmV?d00001 diff --git a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java index 108dcc04..b6e67c89 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/BookmarksActivity.java @@ -108,14 +108,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // `editBookmarkMenuItem` is used in `onCreateActionMode()` and `onItemCheckedStateChanged`. MenuItem editBookmarkMenuItem; + // `selectAllBookmarks` is used in `onCreateActionMode()` and `onItemCheckedStateChanges`. + MenuItem selectAllBookmarks; + @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { // Inflate the menu for the contextual app bar and set the title. getMenuInflater().inflate(R.menu.bookmarks_context_menu, menu); mode.setTitle(R.string.bookmarks); - // Get a handle for `R.id.edit_bookmark`. + // Get a handle for `R.id.edit_bookmark` and `R.id.select_all_bookmarks`. editBookmarkMenuItem = menu.findItem(R.id.edit_bookmark); + selectAllBookmarks = menu.findItem(R.id.context_menu_select_all_bookmarks); return true; } @@ -137,11 +141,18 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma mode.setSubtitle(numberOfSelectedBookmarks + " " + getString(R.string.selected)); // Show the `Edit` option only if 1 bookmark is selected. - if (numberOfSelectedBookmarks == 1) { + if (numberOfSelectedBookmarks < 2) { editBookmarkMenuItem.setVisible(true); } else { editBookmarkMenuItem.setVisible(false); } + + // Do not show `Select All` if all the bookmarks are already checked. + if (bookmarksListView.getCheckedItemIds().length == bookmarksListView.getCount()) { + selectAllBookmarks.setVisible(false); + } else { + selectAllBookmarks.setVisible(true); + } } @Override @@ -210,6 +221,14 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma // Close the contextual app bar. mode.finish(); break; + + case R.id.context_menu_select_all_bookmarks: + int numberOfBookmarks = bookmarksListView.getCount(); + + for (int i = 0; i < numberOfBookmarks; i++) { + bookmarksListView.setItemChecked(i, true); + } + break; } // Consume the click. return true; @@ -234,6 +253,41 @@ public class BookmarksActivity extends AppCompatActivity implements CreateBookma }); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + //Inflate the menu. + getMenuInflater().inflate(R.menu.bookmarks_options_menu, menu); + + return true; + } + + @Override + public boolean onPrepareOptionsMenu(Menu menu) { + super.onPrepareOptionsMenu(menu); + + return true; + } + + @Override + public boolean onOptionsItemSelected(MenuItem menuItem) { + int menuItemId = menuItem.getItemId(); + + switch (menuItemId) { + case android.R.id.home: + NavUtils.navigateUpFromSameTask(this); + break; + + case R.id.options_menu_select_all_bookmarks: + int numberOfBookmarks = bookmarksListView.getCount(); + + for (int i = 0; i < numberOfBookmarks; i++) { + bookmarksListView.setItemChecked(i, true); + } + break; + } + return true; + } + @Override public void onCreateBookmarkCancel(DialogFragment createBookmarkDialogFragment) { // Do nothing because the user selected `Cancel`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java index 64714358..c5acd035 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateBookmark.java @@ -62,7 +62,7 @@ public class CreateBookmark extends DialogFragment { Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), MainWebViewActivity.favoriteIcon); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder createBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder createBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); createBookmarkDialogBuilder.setTitle(R.string.create_bookmark); createBookmarkDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is `null` because it will be assigned by `AlertDialog`. diff --git a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java index ea225ca3..71e84ab3 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java +++ b/app/src/main/java/com/stoutner/privacybrowser/CreateHomeScreenShortcut.java @@ -64,7 +64,7 @@ public class CreateHomeScreenShortcut extends DialogFragment { LayoutInflater customDialogInflater = getActivity().getLayoutInflater(); // Use AlertDialog.Builder to create the AlertDialog. The style formats the color of the button text. - AlertDialog.Builder createHomeScreenShorcutDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder createHomeScreenShorcutDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); createHomeScreenShorcutDialogBuilder.setTitle(R.string.create_shortcut); createHomeScreenShorcutDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is "null" because it will be assigned by AlertDialog. diff --git a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java index 27d522b8..8eee58d6 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java +++ b/app/src/main/java/com/stoutner/privacybrowser/EditBookmark.java @@ -77,7 +77,7 @@ public class EditBookmark extends DialogFragment { Drawable favoriteIconDrawable = new BitmapDrawable(getResources(), favoriteIconBitmap); // Use `AlertDialog.Builder` to create the `AlertDialog`. The style formats the color of the button text. - AlertDialog.Builder editBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowser_AlertDialog); + AlertDialog.Builder editBookmarkDialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog); editBookmarkDialogBuilder.setTitle(R.string.edit_bookmark); editBookmarkDialogBuilder.setIcon(favoriteIconDrawable); // The parent view is `null` because it will be assigned by `AlertDialog`. diff --git a/app/src/main/res/drawable/select_all.xml b/app/src/main/res/drawable/select_all.xml new file mode 100644 index 00000000..24205a5b --- /dev/null +++ b/app/src/main/res/drawable/select_all.xml @@ -0,0 +1,14 @@ + + + + + + diff --git a/app/src/main/res/layout/about_coordinatorlayout.xml b/app/src/main/res/layout/about_coordinatorlayout.xml index 46fe2497..a0d221e6 100644 --- a/app/src/main/res/layout/about_coordinatorlayout.xml +++ b/app/src/main/res/layout/about_coordinatorlayout.xml @@ -41,7 +41,7 @@ android:layout_height="wrap_content" android:layout_width="match_parent" android:background="@color/blue" - android:theme="@style/PrivacyBrowser.AppBarOverlay" > + android:theme="@style/AppBarOverlay" > + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/AppBarOverlay" > + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/DarkAppBar" + app:popupTheme="@style/LightPopupOverlay" /> + android:theme="@style/AppBarOverlay" > + app:popupTheme="@style/LightPopupOverlay" /> diff --git a/app/src/main/res/menu/bookmarks_context_menu.xml b/app/src/main/res/menu/bookmarks_context_menu.xml index 6b2fc748..98b790ad 100644 --- a/app/src/main/res/menu/bookmarks_context_menu.xml +++ b/app/src/main/res/menu/bookmarks_context_menu.xml @@ -35,4 +35,11 @@ android:orderInCategory="20" android:icon="@drawable/delete" app:showAsAction="ifRoom" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_bookmarks_options.xml b/app/src/main/res/menu/bookmarks_options_menu.xml similarity index 87% rename from app/src/main/res/menu/menu_bookmarks_options.xml rename to app/src/main/res/menu/bookmarks_options_menu.xml index 97d6487b..856594ce 100644 --- a/app/src/main/res/menu/menu_bookmarks_options.xml +++ b/app/src/main/res/menu/bookmarks_options_menu.xml @@ -23,9 +23,9 @@ xmlns:app="http://schemas.android.com/apk/res-auto"> \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 5b5ad90d..69424458 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -82,6 +82,7 @@ Selected Edit Delete + Select All 1 Bookmark Deleted Bookmarks Deleted Undo diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 0b1697e7..25ca3a0d 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -26,35 +26,31 @@ @color/blue - - - - \ No newline at end of file -- 2.45.2