48 lines
1.3 KiB
Java
48 lines
1.3 KiB
Java
package com.rubenvandeven.emotionhero;
|
|
|
|
import android.graphics.Canvas;
|
|
import android.view.SurfaceHolder;
|
|
|
|
/**
|
|
* Created by ruben on 16/06/17.
|
|
* see: http://blog.danielnadeau.io/2012/01/android-canvas-beginners-tutorial.html
|
|
*/
|
|
public class PanelThread extends Thread {
|
|
private SurfaceHolder _surfaceHolder;
|
|
private ScenarioView _panel;
|
|
private boolean _run = false;
|
|
|
|
|
|
public PanelThread(SurfaceHolder surfaceHolder, ScenarioView panel) {
|
|
_surfaceHolder = surfaceHolder;
|
|
_panel = panel;
|
|
}
|
|
|
|
|
|
public void setRunning(boolean run) { //Allow us to stop the thread
|
|
_run = run;
|
|
}
|
|
|
|
|
|
@Override
|
|
public void run() {
|
|
|
|
Canvas c;
|
|
while (_run) { //When setRunning(false) occurs, _run is
|
|
c = null; //set to false and loop ends, stopping thread
|
|
|
|
try {
|
|
c = _surfaceHolder.lockCanvas(null);
|
|
synchronized (_surfaceHolder) {
|
|
//Insert methods to modify positions of items in onDraw()
|
|
_panel.postInvalidate();
|
|
}
|
|
} finally {
|
|
if (c != null) {
|
|
_surfaceHolder.unlockCanvasAndPost(c);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|