Better grid item selector drawable.
This commit is contained in:
parent
bb1f6c0c4b
commit
3ea94d5c4a
23 changed files with 117 additions and 96 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue