Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
bugfix: do not flip more than one page with one-touch
Browse files Browse the repository at this point in the history
  • Loading branch information
siegfriedpammer committed Dec 29, 2012
1 parent bef1709 commit b80c562
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void reloadTexture(int frontIndex, View frontView, int backIndex, View ba
AphidLog.d("reloading texture: %s and %s; old views: %s, %s, front changed %s, back changed %s", frontView, backView, frontCards.getView(), backCards.getView(), frontChanged, backChanged);

if (AphidLog.ENABLE_DEBUG)
AphidLog.d("reloadTexture: activeIndex %d, front %d, back %d, angle %.1f", getPageIndexFromAngle(), frontIndex, backIndex, accumulatedAngle);
AphidLog.d("reloadTexture: activeIndex %d, front %d, back %d, angle %.1f", getPageIndexFromAngle(accumulatedAngle), frontIndex, backIndex, accumulatedAngle);
}
}

Expand Down Expand Up @@ -235,10 +235,14 @@ public void invalidateTexture() {
frontCards.abandonTexture();
backCards.abandonTexture();
}

private int lastPageIndex;

public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouchEvent) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// remember page we started on...
lastPageIndex = getPageIndexFromAngle(accumulatedAngle);
lastPosition = orientationVertical ? event.getY() : event.getX();
return isOnTouchEvent;
case MotionEvent.ACTION_MOVE:
Expand All @@ -262,8 +266,11 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc

if (Math.abs(angleDelta) > MAX_TOUCH_MOVE_ANGLE) //prevent large delta when moving too fast
angleDelta = Math.signum(angleDelta) * MAX_TOUCH_MOVE_ANGLE;

accumulatedAngle += angleDelta;

// do not flip more than one page with one touch...
if (Math.abs(getPageIndexFromAngle(accumulatedAngle + angleDelta) - lastPageIndex) <= 1) {
accumulatedAngle += angleDelta;
}

//Bounce the page for the first and the last page
if (frontCards.getIndex() == maxIndex - 1) { //the last page
Expand All @@ -272,7 +279,7 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc
} else if (accumulatedAngle < -MAX_TIP_ANGLE)
accumulatedAngle = -MAX_TIP_ANGLE;

int anglePageIndex = getPageIndexFromAngle();
int anglePageIndex = getPageIndexFromAngle(accumulatedAngle);

if (accumulatedAngle >= 0) {
if (anglePageIndex != frontCards.getIndex()) {
Expand Down Expand Up @@ -330,8 +337,8 @@ private void setState(int state) {
}
}

private int getPageIndexFromAngle() {
return ((int) accumulatedAngle) / 180;
private int getPageIndexFromAngle(float angle) {
return ((int) angle) / 180;
}

private float getDisplayAngle() {
Expand Down

0 comments on commit b80c562

Please sign in to comment.