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