From 3ea94d5c4a325e0d2935c070fd74a2dce0309fc5 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Sun, 28 Feb 2016 22:51:48 +0100 Subject: [PATCH] Better grid item selector drawable. --- app/build.gradle | 2 +- .../adapter/album/AlbumAdapter.java | 3 -- .../adapter/artist/ArtistAdapter.java | 3 -- .../adapter/base/MediaEntryViewHolder.java | 4 -- .../gramophone/adapter/song/SongAdapter.java | 3 -- .../kabouzeid/gramophone/util/ViewUtil.java | 27 ++++++++++++-- .../views/WidthFitSquareImageView.java | 37 ------------------- ..._ripple_selector.xml => rect_selector.xml} | 2 +- ...lector_dark.xml => rect_selector_dark.xml} | 0 .../res/drawable-v21/rect_selector_strong.xml | 15 ++++++++ .../rect_selector_strong_dark.xml | 15 ++++++++ ...ripple_selector.xml => round_selector.xml} | 4 +- .../res/drawable-v21/round_selector_dark.xml | 8 ++++ ...ector_mask.xml => round_selector_mask.xml} | 0 .../res/drawable/rect_selector_strong.xml | 9 +++++ .../drawable/rect_selector_strong_dark.xml | 9 +++++ .../res/layout/activity_album_tag_editor.xml | 23 ++++++++---- .../res/layout/activity_song_tag_editor.xml | 2 +- app/src/main/res/layout/item_grid.xml | 30 +++++++-------- .../res/layout/item_grid_card_horizontal.xml | 2 +- app/src/main/res/values-v21/styles.xml | 12 ------ app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/styles_parents.xml | 2 + 23 files changed, 117 insertions(+), 96 deletions(-) delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/views/WidthFitSquareImageView.java rename app/src/main/res/drawable-v21/{rect_ripple_selector.xml => rect_selector.xml} (87%) rename app/src/main/res/drawable-v21/{rect_ripple_selector_dark.xml => rect_selector_dark.xml} (100%) create mode 100644 app/src/main/res/drawable-v21/rect_selector_strong.xml create mode 100644 app/src/main/res/drawable-v21/rect_selector_strong_dark.xml rename app/src/main/res/drawable-v21/{round_ripple_selector.xml => round_selector.xml} (51%) create mode 100644 app/src/main/res/drawable-v21/round_selector_dark.xml rename app/src/main/res/drawable-v21/{round_ripple_selector_mask.xml => round_selector_mask.xml} (100%) create mode 100644 app/src/main/res/drawable/rect_selector_strong.xml create mode 100644 app/src/main/res/drawable/rect_selector_strong_dark.xml diff --git a/app/build.gradle b/app/build.gradle index b8e3e801..535d97e0 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -143,5 +143,5 @@ dependencies { compile 'com.github.bumptech.glide:glide:3.7.0' compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar' compile 'com.github.kabouzeid:RecyclerView-FastScroll:v1.6-kmod' - compile 'com.heinrichreimersoftware:material-intro:1.0' + compile 'com.heinrichreimersoftware:material-intro:a89e1099e5' } diff --git a/app/src/main/java/com/kabouzeid/gramophone/adapter/album/AlbumAdapter.java b/app/src/main/java/com/kabouzeid/gramophone/adapter/album/AlbumAdapter.java index 678cff0e..a086b12d 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/adapter/album/AlbumAdapter.java +++ b/app/src/main/java/com/kabouzeid/gramophone/adapter/album/AlbumAdapter.java @@ -91,9 +91,6 @@ public class AlbumAdapter extends AbsMultiSelectAdapter= Build.VERSION_CODES.LOLLIPOP) { animator = ObjectAnimator.ofArgb(target, propertyName, startColor, endColor); @@ -40,6 +48,19 @@ public class ViewUtil { return animator; } + public static Drawable createSelectorDrawable(Context context, @ColorInt int color) { + final StateListDrawable baseSelector = new StateListDrawable(); + baseSelector.addState(new int[]{android.R.attr.state_activated}, new ColorDrawable(color)); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + return new RippleDrawable(ColorStateList.valueOf(color), baseSelector, new ColorDrawable(Color.WHITE)); + } + + baseSelector.addState(new int[]{}, new ColorDrawable(Color.TRANSPARENT)); + baseSelector.addState(new int[]{android.R.attr.state_pressed}, new ColorDrawable(color)); + return baseSelector; + } + public static boolean hitTest(View v, int x, int y) { final int tx = (int) (ViewCompat.getTranslationX(v) + 0.5f); final int ty = (int) (ViewCompat.getTranslationY(v) + 0.5f); diff --git a/app/src/main/java/com/kabouzeid/gramophone/views/WidthFitSquareImageView.java b/app/src/main/java/com/kabouzeid/gramophone/views/WidthFitSquareImageView.java deleted file mode 100644 index 595c2ba2..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/views/WidthFitSquareImageView.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.kabouzeid.gramophone.views; - -import android.annotation.TargetApi; -import android.content.Context; -import android.os.Build; -import android.util.AttributeSet; -import android.widget.ImageView; - -/** - * @author Karim Abou Zeid (kabouzeid) - */ -public class WidthFitSquareImageView extends ImageView { - - public WidthFitSquareImageView(Context context) { - super(context); - } - - public WidthFitSquareImageView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public WidthFitSquareImageView(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - } - - @TargetApi(Build.VERSION_CODES.LOLLIPOP) - public WidthFitSquareImageView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { - super(context, attrs, defStyleAttr, defStyleRes); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - //noinspection SuspiciousNameCombination - super.onMeasure(widthMeasureSpec, widthMeasureSpec); - } - -} diff --git a/app/src/main/res/drawable-v21/rect_ripple_selector.xml b/app/src/main/res/drawable-v21/rect_selector.xml similarity index 87% rename from app/src/main/res/drawable-v21/rect_ripple_selector.xml rename to app/src/main/res/drawable-v21/rect_selector.xml index 01fc385f..f12d9ce1 100644 --- a/app/src/main/res/drawable-v21/rect_ripple_selector.xml +++ b/app/src/main/res/drawable-v21/rect_selector.xml @@ -1,5 +1,5 @@ + android:color="@color/ripple_material_light"> + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/rect_selector_strong_dark.xml b/app/src/main/res/drawable-v21/rect_selector_strong_dark.xml new file mode 100644 index 00000000..fdeae459 --- /dev/null +++ b/app/src/main/res/drawable-v21/rect_selector_strong_dark.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/round_ripple_selector.xml b/app/src/main/res/drawable-v21/round_selector.xml similarity index 51% rename from app/src/main/res/drawable-v21/round_ripple_selector.xml rename to app/src/main/res/drawable-v21/round_selector.xml index b565a03a..09c5b530 100644 --- a/app/src/main/res/drawable-v21/round_ripple_selector.xml +++ b/app/src/main/res/drawable-v21/round_selector.xml @@ -1,8 +1,8 @@ + android:color="@color/ripple_material_light"> + android:drawable="@drawable/round_selector_mask" /> \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/round_selector_dark.xml b/app/src/main/res/drawable-v21/round_selector_dark.xml new file mode 100644 index 00000000..0619a3df --- /dev/null +++ b/app/src/main/res/drawable-v21/round_selector_dark.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/round_ripple_selector_mask.xml b/app/src/main/res/drawable-v21/round_selector_mask.xml similarity index 100% rename from app/src/main/res/drawable-v21/round_ripple_selector_mask.xml rename to app/src/main/res/drawable-v21/round_selector_mask.xml diff --git a/app/src/main/res/drawable/rect_selector_strong.xml b/app/src/main/res/drawable/rect_selector_strong.xml new file mode 100644 index 00000000..87e00890 --- /dev/null +++ b/app/src/main/res/drawable/rect_selector_strong.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rect_selector_strong_dark.xml b/app/src/main/res/drawable/rect_selector_strong_dark.xml new file mode 100644 index 00000000..f53f1923 --- /dev/null +++ b/app/src/main/res/drawable/rect_selector_strong_dark.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_album_tag_editor.xml b/app/src/main/res/layout/activity_album_tag_editor.xml index 6965f950..4892cdd4 100644 --- a/app/src/main/res/layout/activity_album_tag_editor.xml +++ b/app/src/main/res/layout/activity_album_tag_editor.xml @@ -16,20 +16,27 @@ android:layout_width="match_parent" android:layout_height="match_parent"> - + android:layout_height="match_parent"> + + + + - + android:foreground="?rectSelectorStrong"> - + android:layout_height="match_parent"> + + + + - - diff --git a/app/src/main/res/layout/item_grid_card_horizontal.xml b/app/src/main/res/layout/item_grid_card_horizontal.xml index 50f0b297..09000be5 100644 --- a/app/src/main/res/layout/item_grid_card_horizontal.xml +++ b/app/src/main/res/layout/item_grid_card_horizontal.xml @@ -5,7 +5,7 @@ android:layout_height="148dp" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" - android:foreground="?attr/rectSelector" + android:foreground="?attr/rectSelectorStrong" app:cardBackgroundColor="?cardBackgroundColor"> diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 09e8c2fe..93cdc8a0 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -3,6 +3,7 @@ + diff --git a/app/src/main/res/values/styles_parents.xml b/app/src/main/res/values/styles_parents.xml index 5b6ce262..da9184c3 100644 --- a/app/src/main/res/values/styles_parents.xml +++ b/app/src/main/res/values/styles_parents.xml @@ -10,6 +10,7 @@ @drawable/round_selector_dark @drawable/rect_selector_dark + @drawable/rect_selector_strong_dark @color/grey_800 @@ -38,6 +39,7 @@ @drawable/round_selector @drawable/rect_selector + @drawable/rect_selector_strong @color/white