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

Commit 5c97861

Browse files
committed
Try to reduce flickers. #52
1 parent ef17e02 commit 5c97861

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed
49 Bytes
Binary file not shown.

FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public class FlipCards {
5050

5151
private FlipViewController controller;
5252

53-
private boolean visible = false;
53+
private volatile boolean visible = false;
54+
private volatile boolean waitForFirstDraw = false;
5455

5556
private int maxIndex = 0;
5657

@@ -72,6 +73,10 @@ public void setVisible(boolean visible) {
7273
this.visible = visible;
7374
}
7475

76+
public void setWaitForFirstDraw(boolean waitForFirstDraw) {
77+
this.waitForFirstDraw = waitForFirstDraw;
78+
}
79+
7580
boolean refreshPageView(View view) {
7681
boolean match = false;
7782
if (frontCards.getView() == view) {
@@ -231,6 +236,11 @@ public synchronized void draw(FlipRenderer renderer, GL10 gl) {
231236
backCards.getBottomCard().draw(gl);
232237
}
233238
}
239+
240+
if (waitForFirstDraw) {
241+
waitForFirstDraw = false;
242+
controller.sendMessage(FlipViewController.MSG_ANIMATION_READY);
243+
}
234244
}
235245

236246
public void invalidateTexture() {

FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipRenderer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
5555
created = true;
5656

5757
cards.invalidateTexture();
58-
flipViewController.reloadTexture();
58+
flipViewController.sendMessage(FlipViewController.MSG_SURFACE_CREATED);
5959

6060
if (AphidLog.ENABLE_DEBUG)
6161
AphidLog.d("onSurfaceCreated");

FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipViewController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public static interface ViewFlipListener {
4848

4949
private static final int MAX_RELEASED_VIEW_SIZE = 1;
5050

51-
private static final int MSG_SURFACE_CREATED = 1;
51+
static final int MSG_SURFACE_CREATED = 1;
52+
static final int MSG_ANIMATION_READY = 2;
5253

5354
private Handler handler = new Handler(new Handler.Callback() {
5455
@Override
@@ -58,6 +59,11 @@ public boolean handleMessage(Message msg) {
5859
contentHeight = 0;
5960
requestLayout();
6061
return true;
62+
} else if (msg.what == MSG_ANIMATION_READY) {
63+
if (inFlipAnimation) {
64+
AphidLog.i("First draw is ready, hide real views");
65+
updateVisibleView(-1);
66+
}
6167
}
6268
return false;
6369
}
@@ -73,7 +79,7 @@ public boolean handleMessage(Message msg) {
7379
@ViewDebug.ExportedProperty
7480
private int flipOrientation;
7581

76-
private boolean inFlipAnimation = false;
82+
private volatile boolean inFlipAnimation = false;
7783

7884
//AdapterView Related
7985
private Adapter adapter;
@@ -382,9 +388,9 @@ int getContentWidth() {
382388
int getContentHeight() {
383389
return contentHeight;
384390
}
385-
386-
void reloadTexture() {
387-
handler.sendMessage(Message.obtain(handler, MSG_SURFACE_CREATED));
391+
392+
void sendMessage(int message) {
393+
handler.sendMessage(Message.obtain(handler, message));
388394
}
389395

390396
//--------------------------------------------------------------------------------------------------------------------
@@ -518,14 +524,8 @@ void showFlipAnimation() {
518524
inFlipAnimation = true;
519525

520526
cards.setVisible(true);
527+
cards.setWaitForFirstDraw(true);
521528
surfaceView.requestRender();
522-
523-
handler.postDelayed(new Runnable() { //use a delayed message to avoid flicker, the perfect solution would be sending a message from the GL thread
524-
public void run() {
525-
if (inFlipAnimation)
526-
updateVisibleView(-1);
527-
}
528-
}, 100);
529529
}
530530
}
531531

0 commit comments

Comments
 (0)