Skip to content

Add Orientation #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions proswipebutton/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -260,6 +260,7 @@ public void performOnSwipe() {
}

public void morphToCircle() {
state = LOADING;
animateFadeHide(context, arrowHintContainer);
setOnTouchListener(null);
ObjectAnimator cornerAnimation =
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -487,4 +497,8 @@ public void setOnSwipeListener(@Nullable OnSwipeListener customSwipeListener) {
this.swipeListener = customSwipeListener;
}

public OnSwipeListener getOnSwipeListener() {
return this.swipeListener;
}

}