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

bugfix: do not flip more than one page with one-touch #40

Merged
merged 1 commit into from
Dec 31, 2012
Merged
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
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