Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Be sure to add the `@aar` suffix.

```groovy
dependencies {
compile 'com.lorentzos.swipecards:library:X.X.X@aar'
implementation 'com.lorentzos.swipecards:library:X.X.X@aar'
}
```

Expand Down
13 changes: 11 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'


}
}

Expand All @@ -20,3 +18,14 @@ allprojects {
jcenter()
}
}

android {
buildToolsVersion '28.0.3'
compileSdkVersion 27

buildTypes {
release {}
debug {}
qa {}
}
}
8 changes: 4 additions & 4 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
buildToolsVersion "22.0.1"
buildToolsVersion "28.0.3"

defaultConfig {
applicationId "com.lorentzos.swipecards.example"
Expand All @@ -20,7 +20,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':library')
compile 'com.jakewharton:butterknife:5.1.2'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(':library')
implementation 'com.jakewharton:butterknife:9.0.0-rc1'
}
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'signing'

android {
compileSdkVersion Integer.parseInt(project.TARGET_SDK_VERSION)
buildToolsVersion "22.0.1"
buildToolsVersion '28.0.3'

defaultConfig {
minSdkVersion MIN_SDK_VERSION
Expand All @@ -21,7 +21,7 @@ android {
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
implementation fileTree(dir: 'libs', include: ['*.jar'])
}


Expand Down
196 changes: 98 additions & 98 deletions library/src/main/java/com/lorentzos/flingswipe/FlingCardListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,107 +72,109 @@ public FlingCardListener(View frame, Object itemAtPosition, float rotation_degre


public boolean onTouch(View view, MotionEvent event) {

switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:

// from http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
// Save the ID of this pointer

mActivePointerId = event.getPointerId(0);
float x = 0;
float y = 0;
boolean success = false;
try {
x = event.getX(mActivePointerId);
y = event.getY(mActivePointerId);
success = true;
} catch (IllegalArgumentException e) {
Log.w(TAG, "Exception in onTouch(view, event) : " + mActivePointerId, e);
}
if (success) {
// Remember where we started
aDownTouchX = x;
aDownTouchY = y;
//to prevent an initial jump of the magnifier, aposX and aPosY must
//have the values from the magnifier frame
if (aPosX == 0) {
aPosX = frame.getX();
if (!isAnimationRunning) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:

// from http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
// Save the ID of this pointer

mActivePointerId = event.getPointerId(0);
float x = 0;
float y = 0;
boolean success = false;
try {
x = event.getX(mActivePointerId);
y = event.getY(mActivePointerId);
success = true;
} catch (IllegalArgumentException e) {
Log.w(TAG, "Exception in onTouch(view, event) : " + mActivePointerId, e);
}
if (aPosY == 0) {
aPosY = frame.getY();
if (success) {
// Remember where we started
aDownTouchX = x;
aDownTouchY = y;
//to prevent an initial jump of the magnifier, aposX and aPosY must
//have the values from the magnifier frame
if (aPosX == 0) {
aPosX = frame.getX();
}
if (aPosY == 0) {
aPosY = frame.getY();
}

if (y < objectH / 2) {
touchPosition = TOUCH_ABOVE;
} else {
touchPosition = TOUCH_BELOW;
}
}

if (y < objectH / 2) {
touchPosition = TOUCH_ABOVE;
} else {
touchPosition = TOUCH_BELOW;
view.getParent().requestDisallowInterceptTouchEvent(true);
break;

case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
resetCardViewOnStack();
view.getParent().requestDisallowInterceptTouchEvent(false);
break;

case MotionEvent.ACTION_POINTER_DOWN:
break;

case MotionEvent.ACTION_POINTER_UP:
// Extract the index of the pointer that left the touch sensor
final int pointerIndex = (event.getAction() &
MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = event.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = event.getPointerId(newPointerIndex);
}
}
break;
case MotionEvent.ACTION_MOVE:

view.getParent().requestDisallowInterceptTouchEvent(true);
break;

case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
resetCardViewOnStack();
view.getParent().requestDisallowInterceptTouchEvent(false);
break;

case MotionEvent.ACTION_POINTER_DOWN:
break;

case MotionEvent.ACTION_POINTER_UP:
// Extract the index of the pointer that left the touch sensor
final int pointerIndex = (event.getAction() &
MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = event.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = event.getPointerId(newPointerIndex);
}
break;
case MotionEvent.ACTION_MOVE:
// Find the index of the active pointer and fetch its position
final int pointerIndexMove = event.findPointerIndex(mActivePointerId);
final float xMove = event.getX(pointerIndexMove);
final float yMove = event.getY(pointerIndexMove);

// Find the index of the active pointer and fetch its position
final int pointerIndexMove = event.findPointerIndex(mActivePointerId);
final float xMove = event.getX(pointerIndexMove);
final float yMove = event.getY(pointerIndexMove);
//from http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
// Calculate the distance moved
final float dx = xMove - aDownTouchX;
final float dy = yMove - aDownTouchY;

//from http://android-developers.blogspot.com/2010/06/making-sense-of-multitouch.html
// Calculate the distance moved
final float dx = xMove - aDownTouchX;
final float dy = yMove - aDownTouchY;

// Move the frame
aPosX += dx;
aPosY += dy;

// Move the frame
aPosX += dx;
aPosY += dy;
// calculate the rotation degrees
float distobjectX = aPosX - objectX;
float rotation = BASE_ROTATION_DEGREES * 2.f * distobjectX / parentWidth;
if (touchPosition == TOUCH_BELOW) {
rotation = -rotation;
}

// calculate the rotation degrees
float distobjectX = aPosX - objectX;
float rotation = BASE_ROTATION_DEGREES * 2.f * distobjectX / parentWidth;
if (touchPosition == TOUCH_BELOW) {
rotation = -rotation;
//in this area would be code for doing something with the view as the frame moves.
frame.setX(aPosX);
frame.setY(aPosY);
frame.setRotation(rotation);
mFlingListener.onScroll(getScrollProgressPercent());
break;

case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}

//in this area would be code for doing something with the view as the frame moves.
frame.setX(aPosX);
frame.setY(aPosY);
frame.setRotation(rotation);
mFlingListener.onScroll(getScrollProgressPercent());
break;

case MotionEvent.ACTION_CANCEL: {
mActivePointerId = INVALID_POINTER_ID;
view.getParent().requestDisallowInterceptTouchEvent(false);
break;
}
}

return true;
return true;
}
return false;
}

private float getScrollProgressPercent() {
Expand All @@ -187,11 +189,11 @@ private float getScrollProgressPercent() {
}

private boolean resetCardViewOnStack() {
if (movedBeyondLeftBorder()) {
if (movedBeyondLeftBorder() && mFlingListener.isLeftExitAvailable()) {
// Left Swipe
onSelected(true, getExitPoint(-objectW), 100);
mFlingListener.onScroll(-1.0f);
} else if (movedBeyondRightBorder()) {
} else if (movedBeyondRightBorder() && mFlingListener.isRightExitAvailable()) {
// Right Swipe
onSelected(false, getExitPoint(parentWidth), 100);
mFlingListener.onScroll(1.0f);
Expand Down Expand Up @@ -270,15 +272,15 @@ public void onAnimationEnd(Animator animation) {
* Starts a default left exit animation.
*/
public void selectLeft() {
if (!isAnimationRunning)
if (!isAnimationRunning && mFlingListener.isLeftExitAvailable())
onSelected(true, objectY, 200);
}

/**
* Starts a default right exit animation.
*/
public void selectRight() {
if (!isAnimationRunning)
if (!isAnimationRunning && mFlingListener.isRightExitAvailable())
onSelected(false, objectY, 200);
}

Expand Down Expand Up @@ -343,11 +345,9 @@ protected interface FlingListener {
void onClick(Object dataObject);

void onScroll(float scrollProgressPercent);
}

}




boolean isRightExitAvailable();

boolean isLeftExitAvailable();
}
}
Loading