Skip to content

Commit

Permalink
- New option to customize the animation via XML and programmatically;
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasspgyn committed Aug 14, 2017
1 parent 826d48d commit 6bea03b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<attr name="animatedViewMeasure" format="dimension"/>
<attr name="animatedViewDrawable" format="reference"/>
<attr name="animatedViewBackgroundColor" format="color"/>
<attr name="animatedViewAnimation" format="reference"/>
</declare-styleable>
</resources>

0 comments on commit 6bea03b

Please sign in to comment.