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

Commit

Permalink
Limit the max angle change by touch movement
Browse files Browse the repository at this point in the history
  • Loading branch information
openaphid committed Dec 8, 2012
1 parent a1030ea commit 03a5bb2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Binary file modified FlipView/Demo/APK/Aphid-FlipView-Demo.apk
Binary file not shown.
15 changes: 12 additions & 3 deletions FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public class FlipCards {
private static final float ACCELERATION = 0.618f;
@SuppressWarnings("unused")
private static final float TIP_SPEED = 1f;

private static final float MOVEMENT_RATE = 1.5f;
private static final int MAX_TIP_ANGLE = 60;
private static final int MAX_TOUCH_MOVE_ANGLE = 15;

private static final int STATE_INIT = 0;
private static final int STATE_TOUCH = 1;
Expand Down Expand Up @@ -236,20 +238,27 @@ public synchronized boolean handleTouchEvent(MotionEvent event, boolean isOnTouc
if (state == STATE_TOUCH) {
forward = delta > 0; // We only want to know the direction of the last movement
controller.showFlipAnimation();
final float angleDelta ;

float angleDelta ;
if(orientationVertical){
angleDelta = 180 * delta / controller.getContentHeight() * MOVEMENT_RATE;
} else {
angleDelta = 180 * delta / controller.getContentWidth() * MOVEMENT_RATE;
}
if (Math.abs(angleDelta) > MAX_TOUCH_MOVE_ANGLE) //prevent large delta when moving too fast
angleDelta = Math.signum(angleDelta) * MAX_TOUCH_MOVE_ANGLE;

angle += angleDelta;
if (backCards.getIndex() == -1) {

//Bounce the page for the first and the last page
if (backCards.getIndex() == -1) { //the last page
if (angle >= MAX_TIP_ANGLE)
angle = MAX_TIP_ANGLE;
} else if (backCards.getIndex() == 0) {
} else if (backCards.getIndex() == 0) { //the first page
if (angle <= 180 - MAX_TIP_ANGLE)
angle = 180 - MAX_TIP_ANGLE;
}

if (angle < 0) {
if (frontCards.getIndex() > 0) {
activeIndex = frontCards.getIndex() - 1; //xxx
Expand Down

0 comments on commit 03a5bb2

Please sign in to comment.