Better grid item selector drawable.
This commit is contained in:
parent
bb1f6c0c4b
commit
3ea94d5c4a
23 changed files with 117 additions and 96 deletions
|
|
@ -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'
|
||||
}
|
||||
|
|
|
|||
|
|
@ -91,9 +91,6 @@ public class AlbumAdapter extends AbsMultiSelectAdapter<AlbumAdapter.ViewHolder,
|
|||
|
||||
final boolean isChecked = isChecked(album);
|
||||
holder.itemView.setActivated(isChecked);
|
||||
if (holder.selectedIndicator != null) {
|
||||
holder.selectedIndicator.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
if (holder.getAdapterPosition() == getItemCount() - 1) {
|
||||
if (holder.shortSeparator != null) {
|
||||
|
|
|
|||
|
|
@ -94,9 +94,6 @@ public class ArtistAdapter extends AbsMultiSelectAdapter<ArtistAdapter.ViewHolde
|
|||
|
||||
boolean isChecked = isChecked(artist);
|
||||
holder.itemView.setActivated(isChecked);
|
||||
if (holder.selectedIndicator != null) {
|
||||
holder.selectedIndicator.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
if (holder.getAdapterPosition() == getItemCount() - 1) {
|
||||
if (holder.shortSeparator != null) {
|
||||
|
|
|
|||
|
|
@ -45,10 +45,6 @@ public class MediaEntryViewHolder extends RecyclerView.ViewHolder implements Vie
|
|||
@Bind(R.id.short_separator)
|
||||
public View shortSeparator;
|
||||
|
||||
@Nullable
|
||||
@Bind(R.id.selected_indicator)
|
||||
public View selectedIndicator;
|
||||
|
||||
@Nullable
|
||||
@Bind(R.id.drag_view)
|
||||
public View dragView;
|
||||
|
|
|
|||
|
|
@ -91,9 +91,6 @@ public class SongAdapter extends AbsMultiSelectAdapter<SongAdapter.ViewHolder, S
|
|||
|
||||
boolean isChecked = isChecked(song);
|
||||
holder.itemView.setActivated(isChecked);
|
||||
if (holder.selectedIndicator != null) {
|
||||
holder.selectedIndicator.setVisibility(isChecked ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
if (holder.getAdapterPosition() == getItemCount() - 1) {
|
||||
if (holder.shortSeparator != null) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,15 @@ package com.kabouzeid.gramophone.util;
|
|||
import android.animation.Animator;
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.content.Context;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.RippleDrawable;
|
||||
import android.graphics.drawable.StateListDrawable;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.ColorInt;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.view.View;
|
||||
import android.view.animation.PathInterpolator;
|
||||
|
|
@ -16,15 +24,15 @@ public class ViewUtil {
|
|||
|
||||
public final static int PHONOGRAPH_ANIM_TIME = 1000;
|
||||
|
||||
public static Animator createBackgroundColorTransition(final View v, final int startColor, final int endColor) {
|
||||
public static Animator createBackgroundColorTransition(final View v, @ColorInt final int startColor, @ColorInt final int endColor) {
|
||||
return createColorAnimator(v, "backgroundColor", startColor, endColor);
|
||||
}
|
||||
|
||||
public static Animator createTextColorTransition(final TextView v, final int startColor, final int endColor) {
|
||||
public static Animator createTextColorTransition(final TextView v, @ColorInt final int startColor, @ColorInt final int endColor) {
|
||||
return createColorAnimator(v, "textColor", startColor, endColor);
|
||||
}
|
||||
|
||||
private static Animator createColorAnimator(Object target, String propertyName, int startColor, int endColor) {
|
||||
private static Animator createColorAnimator(Object target, String propertyName, @ColorInt int startColor, @ColorInt int endColor) {
|
||||
ObjectAnimator animator;
|
||||
if (Build.VERSION.SDK_INT >= 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);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
15
app/src/main/res/drawable-v21/rect_selector_strong.xml
Normal file
15
app/src/main/res/drawable-v21/rect_selector_strong.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ate_control_normal_light">
|
||||
|
||||
<item
|
||||
android:id="@android:id/mask"
|
||||
android:drawable="@android:color/white" />
|
||||
<item>
|
||||
<selector>
|
||||
<item
|
||||
android:drawable="@color/ate_control_normal_light"
|
||||
android:state_activated="true" />
|
||||
</selector>
|
||||
</item>
|
||||
|
||||
</ripple>
|
||||
15
app/src/main/res/drawable-v21/rect_selector_strong_dark.xml
Normal file
15
app/src/main/res/drawable-v21/rect_selector_strong_dark.xml
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ate_control_normal_dark">
|
||||
|
||||
<item
|
||||
android:id="@android:id/mask"
|
||||
android:drawable="@android:color/white" />
|
||||
<item>
|
||||
<selector>
|
||||
<item
|
||||
android:drawable="@color/ate_control_normal_dark"
|
||||
android:state_activated="true" />
|
||||
</selector>
|
||||
</item>
|
||||
|
||||
</ripple>
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?android:colorControlHighlight">
|
||||
android:color="@color/ripple_material_light">
|
||||
|
||||
<item
|
||||
android:id="@android:id/mask"
|
||||
android:drawable="@drawable/round_ripple_selector_mask" />
|
||||
android:drawable="@drawable/round_selector_mask" />
|
||||
|
||||
</ripple>
|
||||
8
app/src/main/res/drawable-v21/round_selector_dark.xml
Normal file
8
app/src/main/res/drawable-v21/round_selector_dark.xml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="@color/ripple_material_dark">
|
||||
|
||||
<item
|
||||
android:id="@android:id/mask"
|
||||
android:drawable="@drawable/round_selector_mask" />
|
||||
|
||||
</ripple>
|
||||
9
app/src/main/res/drawable/rect_selector_strong.xml
Normal file
9
app/src/main/res/drawable/rect_selector_strong.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@color/ate_control_normal_light" android:state_activated="true" android:state_pressed="true" />
|
||||
<item android:drawable="@color/ate_control_normal_light" android:state_activated="true" />
|
||||
<item android:drawable="@color/ate_control_normal_light" android:state_pressed="true" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
|
||||
</selector>
|
||||
9
app/src/main/res/drawable/rect_selector_strong_dark.xml
Normal file
9
app/src/main/res/drawable/rect_selector_strong_dark.xml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item android:drawable="@color/ate_control_normal_dark" android:state_activated="true" android:state_pressed="true" />
|
||||
<item android:drawable="@color/ate_control_normal_dark" android:state_activated="true" />
|
||||
<item android:drawable="@color/ate_control_normal_dark" android:state_pressed="true" />
|
||||
<item android:drawable="@android:color/transparent" />
|
||||
|
||||
</selector>
|
||||
|
|
@ -16,7 +16,12 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareLayout
|
||||
android:id="@+id/image_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
@ -25,11 +30,13 @@
|
|||
android:transitionName="@string/transition_album_art"
|
||||
tools:ignore="UnusedAttribute" />
|
||||
|
||||
</com.kabouzeid.gramophone.views.WidthFitSquareLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/image"
|
||||
android:layout_below="@+id/image_container"
|
||||
android:elevation="@dimen/toolbar_elevation"
|
||||
android:minHeight="@dimen/title_view_height"
|
||||
android:orientation="vertical"
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
|||
|
|
@ -3,9 +3,8 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_margin="2dp"
|
||||
android:foreground="?attr/rectSelector">
|
||||
android:foreground="?rectSelectorStrong">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
@ -14,11 +13,19 @@
|
|||
android:orientation="vertical"
|
||||
tools:ignore="UnusedAttribute,UselessParent">
|
||||
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareImageView
|
||||
<com.kabouzeid.gramophone.views.WidthFitSquareLayout
|
||||
android:id="@+id/image_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/image"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop" />
|
||||
android:scaleType="centerCrop"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
</com.kabouzeid.gramophone.views.WidthFitSquareLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/palette_color_container"
|
||||
|
|
@ -48,15 +55,4 @@
|
|||
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/selected_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:paddingBottom="68dp"
|
||||
app:srcCompat="@drawable/ic_done_black_24dp"
|
||||
android:tint="?android:colorBackground"
|
||||
android:visibility="gone"
|
||||
tools:ignore="ContentDescription,MissingPrefix" />
|
||||
|
||||
</FrameLayout>
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
|
|
@ -1,29 +1,17 @@
|
|||
<resources>
|
||||
|
||||
<style name="Theme.Phonograph" parent="Theme.Phonograph.Base">
|
||||
<item name="roundSelector">@drawable/round_ripple_selector</item>
|
||||
<item name="rectSelector">@drawable/rect_ripple_selector_dark</item>
|
||||
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
|
||||
<item name="android:windowSharedElementsUseOverlay">false</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Phonograph.Light" parent="Theme.Phonograph.Base.Light">
|
||||
<item name="roundSelector">@drawable/round_ripple_selector</item>
|
||||
<item name="rectSelector">@drawable/rect_ripple_selector</item>
|
||||
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
|
||||
<item name="android:windowSharedElementsUseOverlay">false</item>
|
||||
</style>
|
||||
|
||||
<style name="Theme.Phonograph.Black" parent="Theme.Phonograph.Base.Black">
|
||||
<item name="roundSelector">@drawable/round_ripple_selector</item>
|
||||
<item name="rectSelector">@drawable/rect_ripple_selector_dark</item>
|
||||
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
|
||||
<item name="android:windowSharedElementsUseOverlay">false</item>
|
||||
</style>
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
<attr name="roundSelector" format="reference" />
|
||||
<attr name="rectSelector" format="reference" />
|
||||
<attr name="rectSelectorStrong" format="reference" />
|
||||
|
||||
<attr name="defaultFooterColor" format="color" />
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
<item name="roundSelector">@drawable/round_selector_dark</item>
|
||||
<item name="rectSelector">@drawable/rect_selector_dark</item>
|
||||
<item name="rectSelectorStrong">@drawable/rect_selector_strong_dark</item>
|
||||
|
||||
<item name="cardBackgroundColor">@color/grey_800</item>
|
||||
|
||||
|
|
@ -38,6 +39,7 @@
|
|||
|
||||
<item name="roundSelector">@drawable/round_selector</item>
|
||||
<item name="rectSelector">@drawable/rect_selector</item>
|
||||
<item name="rectSelectorStrong">@drawable/rect_selector_strong</item>
|
||||
|
||||
<item name="cardBackgroundColor">@color/white</item>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue