diff --git a/proswipebutton/build.gradle b/proswipebutton/build.gradle index 0e3f990..7e71efa 100644 --- a/proswipebutton/build.gradle +++ b/proswipebutton/build.gradle @@ -13,7 +13,7 @@ ext { siteUrl = 'https://github.com/shadowfaxtech/proSwipeButton' gitUrl = 'https://github.com/shadowfaxtech/proSwipeButton.git' - libraryVersion = '1.2' + libraryVersion = '1.2.2' developerId = 'developerId' developerName = 'Ishaan Garg' @@ -30,8 +30,8 @@ android { defaultConfig { minSdkVersion 15 targetSdkVersion 26 - versionCode 6 - versionName "1.2" + versionCode 8 + versionName "1.2.2" vectorDrawables.useSupportLibrary = true testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java b/proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java index 11a61e9..978f9ed 100644 --- a/proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java +++ b/proswipebutton/src/main/java/in/shadowfax/proswipebutton/ProSwipeButton.java @@ -42,7 +42,10 @@ * Created by shadow-admin on 24/10/17. */ -public class ProSwipeButton extends RelativeLayout { +public class ProSwipeButton extends RelativeLayout implements View.OnTouchListener { + + private static final int EXPANDED = 240; + private static final int LOADING = 604; private Context context; private View view; @@ -53,6 +56,7 @@ public class ProSwipeButton extends RelativeLayout { private ImageView arrow2; private LinearLayout arrowHintContainer; private ProgressBar progressBar; + private int state = EXPANDED; //// TODO: 26/10/17 Add touch blocking @@ -115,6 +119,7 @@ private void setAttrs(Context context, AttributeSet attrs) { public void init() { LayoutInflater inflater = LayoutInflater.from(context); view = inflater.inflate(R.layout.view_proswipebtn, this, true); + setOnTouchListener(this); } @Override @@ -136,56 +141,51 @@ protected void onFinishInflate() { gradientDrawable.setCornerRadius(btnRadius); setBackgroundColor(bgColorInt); updateBackground(); - setupTouchListener(); } - private void setupTouchListener() { - setOnTouchListener(new OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - switch (event.getAction()) { - case MotionEvent.ACTION_DOWN: - return true; - case MotionEvent.ACTION_MOVE: - // Movement logic here - if (event.getX() > arrowHintContainer.getWidth() / 2 && - event.getX() + arrowHintContainer.getWidth() / 2 < getWidth() && - (event.getX() < arrowHintContainer.getX() + arrowHintContainer.getWidth() || arrowHintContainer.getX() != 0)) { - // snaps the hint to user touch, only if the touch is within hint width or if it has already been displaced - arrowHintContainer.setX(event.getX() - arrowHintContainer.getWidth() / 2); - } - - if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() && - arrowHintContainer.getX() + arrowHintContainer.getWidth() / 2 < getWidth()) { - // allows the hint to go up to a max of btn container width - arrowHintContainer.setX(getWidth() - arrowHintContainer.getWidth()); - } - - if (event.getX() < arrowHintContainer.getWidth() / 2 && - arrowHintContainer.getX() > 0) { - // allows the hint to go up to a min of btn container starting - arrowHintContainer.setX(0); - } - - return true; - case MotionEvent.ACTION_UP: - //Release logic here - if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() * swipeDistance) { - // swipe completed, fly the hint away! - performSuccessfulSwipe(); - } else if (arrowHintContainer.getX() <= 0) { - // upon click without swipe - startFwdAnim(); - } else { - // swipe not completed, pull back the hint - animateHintBack(); - } - return true; + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + return true; + case MotionEvent.ACTION_MOVE: + // Movement logic here + if (event.getX() > arrowHintContainer.getWidth() / 2 && + event.getX() + arrowHintContainer.getWidth() / 2 < getWidth() && + (event.getX() < arrowHintContainer.getX() + arrowHintContainer.getWidth() || arrowHintContainer.getX() != 0)) { + // snaps the hint to user touch, only if the touch is within hint width or if it has already been displaced + arrowHintContainer.setX(event.getX() - arrowHintContainer.getWidth() / 2); } - return false; - } - }); + if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() && + arrowHintContainer.getX() + arrowHintContainer.getWidth() / 2 < getWidth()) { + // allows the hint to go up to a max of btn container width + arrowHintContainer.setX(getWidth() - arrowHintContainer.getWidth()); + } + + if (event.getX() < arrowHintContainer.getWidth() / 2 && + arrowHintContainer.getX() > 0) { + // allows the hint to go up to a min of btn container starting + arrowHintContainer.setX(0); + } + + return true; + case MotionEvent.ACTION_UP: + //Release logic here + if (arrowHintContainer.getX() + arrowHintContainer.getWidth() > getWidth() * swipeDistance) { + // swipe completed, fly the hint away! + performSuccessfulSwipe(); + } else if (arrowHintContainer.getX() <= 0) { + // upon click without swipe + startFwdAnim(); + } else { + // swipe not completed, pull back the hint + animateHintBack(); + } + return true; + } + + return false; } private void performSuccessfulSwipe() { @@ -260,6 +260,7 @@ public void performOnSwipe() { } public void morphToCircle() { + state = LOADING; animateFadeHide(context, arrowHintContainer); setOnTouchListener(null); ObjectAnimator cornerAnimation = @@ -297,7 +298,8 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) { } private void morphToRect() { - setupTouchListener(); + state = EXPANDED; + setOnTouchListener(this); ObjectAnimator cornerAnimation = ObjectAnimator.ofFloat(gradientDrawable, "cornerRadius", BTN_MORPHED_RADIUS, BTN_INIT_RADIUS); @@ -399,6 +401,14 @@ private void tintArrowHint() { arrow2.setColorFilter(arrowColorInt, PorterDuff.Mode.MULTIPLY); } + public int getState() { + return state; + } + + public void setState(int state) { + this.state = state; + } + public interface OnSwipeListener { void onSwipeConfirm(); } @@ -487,4 +497,8 @@ public void setOnSwipeListener(@Nullable OnSwipeListener customSwipeListener) { this.swipeListener = customSwipeListener; } + public OnSwipeListener getOnSwipeListener() { + return this.swipeListener; + } + }