Using java Syntax Highlighting
- public class Painting extends Thread {
- /** Reference to the View and the context */
- private SurfaceHolder surfaceHolder;
- private Context context;
- /** State */
- private boolean wait;
- private boolean run;
- /** Dimensions */
- private int width;
- private int height;
- /** Time tracking */
- private long previousTime;
- boolean first = true;
- Bitmap hole;
- int degree;
- public Painting(Context con , SurfaceHolder surf)
- {
- context = con;
- surfaceHolder = surf;
- this.wait = true;
- Log.i("Live Test","UnInitialized");
- Drawable d = (con.getResources().getDrawable(R.drawable.vlack));
- hole = ((BitmapDrawable)d).getBitmap();
- hole.prepareToDraw();
- if(hole != null)
- Log.i("Live Test","Initialized");
- run = true;wait = false;
- degree = 0;
- }
- @Override
- public void run()
- {
- while (run) {
- this.run = true;
- Canvas c = null;
- Log.i("Live Test","Draw Color");
- while (run) {
- try {
- c = this.surfaceHolder.lockCanvas();
- synchronized (this.surfaceHolder) {
- doDraw(c);
- }
- } finally {
- if (c != null) {
- this.surfaceHolder.unlockCanvasAndPost(c);
- Log.i("Live Test","Unlocked And Posted");
- }
- }
- // pause if no need to animate
- synchronized (this) {
- if (wait) {
- try {
- wait();
- } catch (Exception e) {
- Log.i("Live Test","Error wait");
- }
- }
- }
- }
- }
- }
- public void setSurfaceSize(int width, int height) {
- this.width = width;
- this.height = height;
- synchronized(this) {
- this.notify();
- }
- }
- private void doDraw(Canvas canvas) {
- if(first)
- {
- canvas.save();
- canvas.drawColor(0x60444444);
- canvas.drawBitmap(hole, 80,80,null);
- canvas.restore();
- first = false;
- }
- else
- {
- long currentTime = System.currentTimeMillis();
- long elapsed = currentTime - previousTime;
- if (elapsed > 20) {
- canvas.save();
- degree+= 5;
- if(degree>359)degree = degree -358;
- canvas.rotate((float) degree);
- canvas.restore();
- Log.i("Live Test","rotated");
- }
- previousTime = currentTime;
- }
- }
- }
Parsed in 0.040 seconds, using GeSHi 1.0.8.4
So I am trying to rotate the bitmap and show it again so it looks like its sucking and all.
Also I have removed Basic onPause onResume Functions so that you guys can understand the code easily. I know there is something basic I am missing, but What?


