Created
March 2, 2015 17:38
-
-
Save febinsathar/5927bf6f5dea687f42f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { | |
onSizeChanged(width, height, 0, 0); | |
} | |
@Override | |
public void surfaceCreated(SurfaceHolder holder) { | |
drawThread = new DrawThread(holder); | |
drawThread.setRunning(true); | |
drawThread.start(); | |
} | |
@Override | |
public void surfaceDestroyed(SurfaceHolder holder) { | |
boolean retry = true; | |
drawThread.setRunning(false); | |
while (retry) { | |
try { | |
drawThread.join(); | |
retry = false; | |
} catch (InterruptedException e) { | |
// we will try it again and again... | |
} | |
} | |
} | |
class DrawThread extends Thread { | |
private SurfaceHolder surfaceHolder; | |
private boolean running = false; | |
public DrawThread(SurfaceHolder surfaceHolder){ | |
this.surfaceHolder = surfaceHolder; | |
} | |
public void setRunning(boolean value){ | |
running = value; | |
} | |
@Override | |
public void run() { | |
Canvas c; | |
while (running) { | |
c = null; | |
try { | |
c = surfaceHolder.lockCanvas(null); | |
synchronized (surfaceHolder) { | |
draw(c); | |
} | |
} finally { | |
if (c != null) { | |
surfaceHolder.unlockCanvasAndPost(c); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment