Skip to content

Commit 9360a86

Browse files
committed
code refactor
1 parent b93a6fb commit 9360a86

File tree

5 files changed

+43
-49
lines changed

5 files changed

+43
-49
lines changed

PageFlip/src/main/java/com/eschao/android/widget/pageflip/PageFlip.java

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* @author escchao
5151
*/
5252
public class PageFlip {
53-
final static String TAG = "PageFlip";
53+
final static String TAG = "PageFlip";
5454

5555
// default pixels of mesh vertex
5656
private final static int DEFAULT_MESH_VERTEX_PIXELS = 10;
@@ -229,7 +229,7 @@ public class PageFlip {
229229
*/
230230
public PageFlip(Context context) {
231231
mContext = context;
232-
mScroller = new Scroller(context, new AccelerateInterpolator(), true);
232+
mScroller = new Scroller(context);
233233
mFlipState = PageFlipState.END_FLIP;
234234
mIsVertical = false;
235235
mViewRect = new GLViewRect();
@@ -277,9 +277,6 @@ public PageFlip(Context context) {
277277
FOLD_BASE_SHADOW_START_ALPHA,
278278
FOLD_BASE_SHADOW_END_COLOR,
279279
FOLD_BASE_SHADOW_END_ALPHA);
280-
281-
// init default scroller
282-
mScroller = new Scroller(context);
283280
}
284281

285282
/**
@@ -599,7 +596,7 @@ private void createPages() {
599596
* @param touchX x of finger down point
600597
* @param touchY y of finger down point
601598
*/
602-
public void onFingerDown(float touchX, float touchY) {
599+
public void onFingerDown(float touchX, float touchY) {
603600
// covert to OpenGL coordinate
604601
touchX = mViewRect.toOpenGLX(touchX);
605602
touchY = mViewRect.toOpenGLY(touchY);
@@ -628,7 +625,7 @@ else if (mPages[SECOND_PAGE] != null &&
628625
mTouchP.set(touchX, touchY);
629626
mFlipState = PageFlipState.BEGIN_FLIP;
630627
}
631-
}
628+
}
632629

633630
/**
634631
* Handle finger moving event
@@ -638,7 +635,7 @@ else if (mPages[SECOND_PAGE] != null &&
638635
* @return true if moving will trigger to draw a new frame for page flip,
639636
* False means the movement should be ignored.
640637
*/
641-
public boolean onFingerMove(float touchX, float touchY) {
638+
public boolean onFingerMove(float touchX, float touchY) {
642639
touchX = mViewRect.toOpenGLX(touchX);
643640
touchY = mViewRect.toOpenGLY(touchY);
644641

@@ -1010,7 +1007,7 @@ else if (mIsVertical) {
10101007
computeVertexesWhenSlope();
10111008
}
10121009

1013-
return isAnimating;
1010+
return isAnimating;
10141011
}
10151012

10161013
/**
@@ -1026,7 +1023,7 @@ public boolean isAnimating() {
10261023
* Abort animating
10271024
*/
10281025
public void abortAnimating() {
1029-
mScroller.abortAnimation();
1026+
mScroller.abortAnimation();
10301027
if (mFlipState == PageFlipState.FORWARD_FLIP) {
10311028
mFlipState = PageFlipState.END_WITH_FORWARD;
10321029
}
@@ -1055,7 +1052,7 @@ public boolean isStartedFlip() {
10551052
* @return true if flip is ended
10561053
*/
10571054
public boolean isEndedFlip() {
1058-
return mFlipState == PageFlipState.END_FLIP ||
1055+
return mFlipState == PageFlipState.END_FLIP ||
10591056
mFlipState == PageFlipState.END_WITH_RESTORE ||
10601057
mFlipState == PageFlipState.END_WITH_BACKWARD ||
10611058
mFlipState == PageFlipState.END_WITH_FORWARD;
@@ -1129,7 +1126,7 @@ public void drawFlipFrame() {
11291126
/**
11301127
* Draw frame with full page
11311128
*/
1132-
public void drawPageFrame() {
1129+
public void drawPageFrame() {
11331130
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
11341131
glUseProgram(mVertexProgram.mProgramRef);
11351132
glUniformMatrix4fv(mVertexProgram.mMVPMatrixLoc, 1, false,
@@ -1143,7 +1140,7 @@ public void drawPageFrame() {
11431140
if (mPages[SECOND_PAGE] != null) {
11441141
mPages[SECOND_PAGE].drawFullPage(mVertexProgram, true);
11451142
}
1146-
}
1143+
}
11471144

11481145
/**
11491146
* Compute max mesh count and allocate vertexes buffer
@@ -1291,22 +1288,22 @@ private void computeVertexesWhenVertical() {
12911288
/**
12921289
* Compute key vertexes when page flip is slope
12931290
*/
1294-
private void computeKeyVertexesWhenSlope() {
1291+
private void computeKeyVertexesWhenSlope() {
12951292
final float oX = mPages[FIRST_PAGE].originP.x;
12961293
final float oY = mPages[FIRST_PAGE].originP.y;
12971294

1298-
float dX = mMiddleP.x - oX;
1299-
float dY = mMiddleP.y - oY;
1300-
1295+
float dX = mMiddleP.x - oX;
1296+
float dY = mMiddleP.y - oY;
1297+
13011298
// compute key points on X axis
13021299
float r0 = 1 - mSemiPerimeterRatio;
13031300
float r1 = 1 + mSemiPerimeterRatio;
1304-
mXFoldP.set(mMiddleP.x + dY * dY / dX, oY);
1301+
mXFoldP.set(mMiddleP.x + dY * dY / dX, oY);
13051302
mXFoldP0.set(oX + (mXFoldP.x - oX) * r0, mXFoldP.y);
13061303
mXFoldP1.set(oX + r1 * (mXFoldP.x - oX), mXFoldP.y);
13071304

13081305
// compute key points on Y axis
1309-
mYFoldP.set(oX, mMiddleP.y + dX * dX / dY);
1306+
mYFoldP.set(oX, mMiddleP.y + dX * dX / dY);
13101307
mYFoldP0.set(mYFoldP.x, oY + (mYFoldP.y - oY) * r0);
13111308
mYFoldP1.set(mYFoldP.x, oY + r1 * (mYFoldP.y - oY));
13121309

@@ -1322,7 +1319,7 @@ private void computeKeyVertexesWhenSlope() {
13221319

13231320
// compute mesh count
13241321
computeMeshCount();
1325-
}
1322+
}
13261323

13271324
/**
13281325
* Compute back vertex and edge shadow vertex of fold page

PageFlip/src/main/java/com/eschao/android/widget/pageflip/PageFlipState.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@
2121
* @author eschao
2222
*/
2323
public enum PageFlipState {
24-
BEGIN_FLIP,
25-
FORWARD_FLIP,
26-
BACKWARD_FLIP,
27-
RESTORE_FLIP,
28-
END_FLIP,
29-
END_WITH_FORWARD,
30-
END_WITH_BACKWARD,
31-
END_WITH_RESTORE,
24+
BEGIN_FLIP,
25+
FORWARD_FLIP,
26+
BACKWARD_FLIP,
27+
RESTORE_FLIP,
28+
END_FLIP,
29+
END_WITH_FORWARD,
30+
END_WITH_BACKWARD,
31+
END_WITH_RESTORE,
3232
}

PageFlip/src/main/java/com/eschao/android/widget/pageflip/ShadowVertexes.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -188,16 +188,14 @@ public ShadowVertexes setVertexes(int offset,
188188
*/
189189
public ShadowVertexes addVertexesBackward(float startX, float startY,
190190
float endX, float endY) {
191-
mBackward -= 8;
192-
int i = mBackward;
193-
mVertexes[i++] = startX;
194-
mVertexes[i++] = startY;
195-
mVertexes[i++] = mColor.startColor;
196-
mVertexes[i++] = mColor.startAlpha;
197-
mVertexes[i++] = endX;
198-
mVertexes[i++] = endY;
199-
mVertexes[i++] = mColor.endColor;
200-
mVertexes[i] = mColor.endAlpha;
191+
mVertexes[--mBackward] = mColor.endAlpha;
192+
mVertexes[--mBackward] = mColor.endColor;
193+
mVertexes[--mBackward] = endY;
194+
mVertexes[--mBackward] = endX;
195+
mVertexes[--mBackward] = mColor.startAlpha;
196+
mVertexes[--mBackward] = mColor.startColor;
197+
mVertexes[--mBackward] = startY;
198+
mVertexes[--mBackward] = startX;
201199
return this;
202200
}
203201

Sample/src/main/java/com/eschao/android/widget/sample/pageflip/SampleActivity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
145145
editor.putInt(Constants.PREF_DURATION, 2000);
146146
break;
147147
case R.id.animation_5s:
148-
mPageFlipView.setAnimateDuration(25000);
148+
mPageFlipView.setAnimateDuration(5000);
149149
editor.putInt(Constants.PREF_DURATION, 5000);
150150
break;
151151
case R.id.auoto_page:

gradle.properties

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
1-
# Project-wide Gradle settings.
2-
3-
# IDE (e.g. Android Studio) users:
4-
# Gradle settings configured through the IDE *will override*
5-
# any settings specified in this file.
6-
1+
## Project-wide Gradle settings.
2+
#
73
# For more details on how to configure your build environment visit
84
# http://www.gradle.org/docs/current/userguide/build_environment.html
9-
5+
#
106
# Specifies the JVM arguments used for the daemon process.
117
# The setting is particularly useful for tweaking memory settings.
12-
# Default value: -Xmx10248m -XX:MaxPermSize=256m
8+
# Default value: -Xmx1024m -XX:MaxPermSize=256m
139
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14-
10+
#
1511
# When configured, Gradle will run in incubating parallel mode.
1612
# This option should only be used with decoupled projects. More details, visit
1713
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18-
# org.gradle.parallel=true
14+
# org.gradle.parallel=true
15+
#Sat Dec 24 22:22:36 CST 2016
16+
systemProp.http.proxyHost=127.0.0.1
17+
systemProp.http.proxyPort=1080

0 commit comments

Comments
 (0)