From 6bea03b4cdec39221abe12da37a9d90c0f117718 Mon Sep 17 00:00:00 2001 From: douglasspgyn Date: Mon, 14 Aug 2017 14:30:25 -0300 Subject: [PATCH] - New option to customize the animation via XML and programmatically; --- .../github/doubletapview/DoubleTapView.java | 26 +++++++++++++++++++ .../github/doubletapview/GestureListener.java | 2 +- app/src/main/res/values/attrs.xml | 1 + 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/douglasspgyn/com/github/doubletapview/DoubleTapView.java b/app/src/main/java/douglasspgyn/com/github/doubletapview/DoubleTapView.java index 36f91f3..af24467 100644 --- a/app/src/main/java/douglasspgyn/com/github/doubletapview/DoubleTapView.java +++ b/app/src/main/java/douglasspgyn/com/github/doubletapview/DoubleTapView.java @@ -7,6 +7,7 @@ import android.graphics.drawable.Drawable; import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.LayerDrawable; +import android.support.annotation.AnimRes; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import android.util.AttributeSet; @@ -37,6 +38,8 @@ public class DoubleTapView extends RelativeLayout { private String animatedViewBackgroundColor; private Drawable animatedViewDrawable; private int animatedViewMeasure; + @AnimRes + private int animatedViewAnimation; public DoubleTapView(Context context, AttributeSet attrs) { super(context, attrs); @@ -74,6 +77,7 @@ private void getTypedArray(TypedArray typedArray) { animatedViewBackgroundColor = typedArray.getString(R.styleable.DoubleTapView_animatedViewBackgroundColor) != null ? typedArray.getString(R.styleable.DoubleTapView_animatedViewBackgroundColor) : "#" + Integer.toHexString(ContextCompat.getColor(getContext(), R.color.colorAccent)); animatedViewDrawable = typedArray.getDrawable(R.styleable.DoubleTapView_animatedViewDrawable) != null ? typedArray.getDrawable(R.styleable.DoubleTapView_animatedViewDrawable) : ContextCompat.getDrawable(context, R.drawable.transparent_view); animatedViewMeasure = (int) typedArray.getDimension(R.styleable.DoubleTapView_animatedViewMeasure, px); + animatedViewAnimation = typedArray.getResourceId(R.styleable.DoubleTapView_animatedViewAnimation, R.anim.bounce_in_out); typedArray.recycle(); } @@ -177,6 +181,16 @@ protected ImageView getAnimatedView() { return animatedView; } + + /** + * Getter used on GestureListener to get animation + * + * @return the animation that will animate + */ + protected int getAnimatedViewAnimation() { + return animatedViewAnimation; + } + /** * Getter used to change the Double Tap background * @@ -254,6 +268,18 @@ public DoubleTapView setAnimatedViewMeasure(int px) { return this; } + + /** + * Set the animated view animation + * + * @param animation animation resource + * @return current instance of the view + */ + public DoubleTapView setAnimatedViewAnimation(@AnimRes int animation) { + this.animatedViewAnimation = animation; + return this; + } + /** * Callback of double tap event */ diff --git a/app/src/main/java/douglasspgyn/com/github/doubletapview/GestureListener.java b/app/src/main/java/douglasspgyn/com/github/doubletapview/GestureListener.java index fecec07..7411183 100644 --- a/app/src/main/java/douglasspgyn/com/github/doubletapview/GestureListener.java +++ b/app/src/main/java/douglasspgyn/com/github/doubletapview/GestureListener.java @@ -27,7 +27,7 @@ public boolean onDown(MotionEvent e) { @Override public boolean onDoubleTap(MotionEvent e) { - Animation pulse = AnimationUtils.loadAnimation(context, R.anim.bounce_in_out); + Animation pulse = AnimationUtils.loadAnimation(context, doubleTapView.getAnimatedViewAnimation()); doubleTapView.getAnimatedView().startAnimation(pulse); if (doubleTapView.getDoubleTapEventListener() != null) { diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index e7079ef..9ee85fb 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -14,5 +14,6 @@ + \ No newline at end of file