2929import android .widget .RelativeLayout ;
3030import android .widget .TextView ;
3131
32+ import static in .shadowfax .proswipebutton .Constants .BTN_INIT_RADIUS ;
33+ import static in .shadowfax .proswipebutton .Constants .BTN_MORPHED_RADIUS ;
34+ import static in .shadowfax .proswipebutton .Constants .DEFAULT_SWIPE_DISTANCE ;
35+ import static in .shadowfax .proswipebutton .Constants .DEFAULT_TEXT_SIZE ;
36+ import static in .shadowfax .proswipebutton .Constants .MORPH_ANIM_DURATION ;
3237import static in .shadowfax .proswipebutton .UiUtils .animateFadeHide ;
3338import static in .shadowfax .proswipebutton .UiUtils .animateFadeShow ;
3439import static in .shadowfax .proswipebutton .UiUtils .dpToPx ;
@@ -48,10 +53,6 @@ public class ProSwipeButton extends RelativeLayout {
4853 private ImageView arrow2 ;
4954 private LinearLayout arrowHintContainer ;
5055 private ProgressBar progressBar ;
51- private static final float DEFAULT_TEXT_SIZE = dpToPx (14 );
52- private static final int BTN_INIT_RADIUS = dpToPx (2 );
53- private static final int BTN_MORPHED_RADIUS = dpToPx (100 );
54- private static final int MORPH_ANIM_DURATION = 500 ;
5556
5657 //// TODO: 26/10/17 Add touch blocking
5758
@@ -70,6 +71,7 @@ public class ProSwipeButton extends RelativeLayout {
7071 private float textSize = DEFAULT_TEXT_SIZE ;
7172 @ Nullable
7273 private OnSwipeListener swipeListener = null ;
74+ private float swipeDistance = DEFAULT_SWIPE_DISTANCE ;
7375
7476 public ProSwipeButton (Context context ) {
7577 super (context );
@@ -168,7 +170,7 @@ public boolean onTouch(View v, MotionEvent event) {
168170 return true ;
169171 case MotionEvent .ACTION_UP :
170172 //Release logic here
171- if (arrowHintContainer .getX () + arrowHintContainer .getWidth () > getWidth () * 0.85 ) {
173+ if (arrowHintContainer .getX () + arrowHintContainer .getWidth () > getWidth () * swipeDistance ) {
172174 // swipe completed, fly the hint away!
173175 animateFadeHide (context , arrowHintContainer );
174176 if (swipeListener != null )
@@ -429,6 +431,26 @@ public float getTextSize() {
429431 return this .textSize ;
430432 }
431433
434+ /**
435+ * How much of the button must the user swipe to trigger the OnSwipeListener successfully
436+ *
437+ * @param swipeDistance float from 0.0 to 1.0 where 1.0 means user must swipe the button fully from end to end. Default is 0.85.
438+ */
439+ public void setSwipeDistance (@ Dimension float swipeDistance ) {
440+ if (swipeDistance > 1.0f ) {
441+ swipeDistance = 1.0f ;
442+ }
443+ if (swipeDistance < 0.0f ) {
444+ swipeDistance = 0.0f ;
445+ }
446+ this .swipeDistance = swipeDistance ;
447+ }
448+
449+ @ Dimension
450+ public float getSwipeDistance () {
451+ return this .swipeDistance ;
452+ }
453+
432454 public void setOnSwipeListener (@ Nullable OnSwipeListener customSwipeListener ) {
433455 this .swipeListener = customSwipeListener ;
434456 }
0 commit comments