I'm coming in from Java, it won't "Repaint", by that I mean it won't move my bitmap to where someone clicks on the screen. There's nothing wrong with my code, logcat doesn't tell me nothing, the weird thing is it worked fine yesterday but now for some reason it won't work.
Activity.class
package com.example.alex.something;
import android.app.Activity;
import android.os.Bundle;
public class Animation extends Activity {
private AnimationThread a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
a = new AnimationThread(this);
setContentView(a);
}
@Override
protected void onPause() {
super.onPause();
a.pause();
}
@Override
protected void onResume() {
super.onResume();
a.resume();
}
}
AnimationThread.class
package com.example.alex.something;
import android.content.Context;
import android.view.*;
import android.graphics.*;
public class AnimationThread extends SurfaceView implements Runnable{
private Thread thread = null;
private SurfaceHolder holder;
private Boolean runnable = false;
private Bitmap ball;
private float x,y;
public AnimationThread(Context context) {
super(context);
ball = BitmapFactory.decodeResource(getResources(),R.drawable.redball);
x=0; y=0;
holder = getHolder();
}
@Override
public void run() {
while(runnable==true){
if(!holder.getSurface().isValid()){
continue;
}
Canvas c = holder.lockCanvas();
c.drawBitmap(ball,x-ball.getWidth()/2,y-ball.getHeight()/2,null);
holder.unlockCanvasAndPost(c);
}
}
public void pause(){
runnable=false;
while(true){
try{
thread.join();
}
catch(InterruptedException e){
e.getStackTrace();
}
}
}
public void resume(){
runnable=true;
thread = new Thread(this);
thread.start();
}
public MotionListener getListener(){MotionListener a = new MotionListener(); return a;}
private class MotionListener implements OnTouchListener{
@Override
public boolean onTouch(View v, MotionEvent event) {
x= event.getX();
y= event.getY();
return false;
}
}
}
Again as far as I know there's nothing wrong with my code, maybe someone more experienced might be able to see something, also is it possible something maybe wrong with my emulator, it worked fine yesterday?