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

Commit

Permalink
Try to reduce flickers. #52
Browse files Browse the repository at this point in the history
  • Loading branch information
openaphid committed Jan 31, 2013
1 parent ef17e02 commit 5c97861
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 14 deletions.
Binary file modified FlipView/Demo/APK/Aphid-FlipView-Demo.apk
Binary file not shown.
12 changes: 11 additions & 1 deletion FlipView/FlipLibrary/src/com/aphidmobile/flip/FlipCards.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public class FlipCards {

private FlipViewController controller;

private boolean visible = false;
private volatile boolean visible = false;
private volatile boolean waitForFirstDraw = false;

private int maxIndex = 0;

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

public void setWaitForFirstDraw(boolean waitForFirstDraw) {
this.waitForFirstDraw = waitForFirstDraw;
}

boolean refreshPageView(View view) {
boolean match = false;
if (frontCards.getView() == view) {
Expand Down Expand Up @@ -231,6 +236,11 @@ public synchronized void draw(FlipRenderer renderer, GL10 gl) {
backCards.getBottomCard().draw(gl);
}
}

if (waitForFirstDraw) {
waitForFirstDraw = false;
controller.sendMessage(FlipViewController.MSG_ANIMATION_READY);
}
}

public void invalidateTexture() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void onSurfaceCreated(GL10 gl, EGLConfig config) {
created = true;

cards.invalidateTexture();
flipViewController.reloadTexture();
flipViewController.sendMessage(FlipViewController.MSG_SURFACE_CREATED);

if (AphidLog.ENABLE_DEBUG)
AphidLog.d("onSurfaceCreated");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ public static interface ViewFlipListener {

private static final int MAX_RELEASED_VIEW_SIZE = 1;

private static final int MSG_SURFACE_CREATED = 1;
static final int MSG_SURFACE_CREATED = 1;
static final int MSG_ANIMATION_READY = 2;

private Handler handler = new Handler(new Handler.Callback() {
@Override
Expand All @@ -58,6 +59,11 @@ public boolean handleMessage(Message msg) {
contentHeight = 0;
requestLayout();
return true;
} else if (msg.what == MSG_ANIMATION_READY) {
if (inFlipAnimation) {
AphidLog.i("First draw is ready, hide real views");
updateVisibleView(-1);
}
}
return false;
}
Expand All @@ -73,7 +79,7 @@ public boolean handleMessage(Message msg) {
@ViewDebug.ExportedProperty
private int flipOrientation;

private boolean inFlipAnimation = false;
private volatile boolean inFlipAnimation = false;

//AdapterView Related
private Adapter adapter;
Expand Down Expand Up @@ -382,9 +388,9 @@ int getContentWidth() {
int getContentHeight() {
return contentHeight;
}

void reloadTexture() {
handler.sendMessage(Message.obtain(handler, MSG_SURFACE_CREATED));
void sendMessage(int message) {
handler.sendMessage(Message.obtain(handler, message));
}

//--------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -518,14 +524,8 @@ void showFlipAnimation() {
inFlipAnimation = true;

cards.setVisible(true);
cards.setWaitForFirstDraw(true);
surfaceView.requestRender();

handler.postDelayed(new Runnable() { //use a delayed message to avoid flicker, the perfect solution would be sending a message from the GL thread
public void run() {
if (inFlipAnimation)
updateVisibleView(-1);
}
}, 100);
}
}

Expand Down

0 comments on commit 5c97861

Please sign in to comment.