if i leave the setBackgroundDrawable() call out of the V constructor,
i get black background with a line drawn from the lower right corner
to the top left corner; and where ever i move the "cursor" afterwards
(all as expected), but when i have that method call, i only get the
initial x=y=0 line drawn on top of the background image and moving the
"cursor" doesn't do anything
what's up with that?
// code starts here
public class V extends SurfaceView implements SurfaceHolder.Callback {
private CThread mThread; // class declaration after this one
public int x;
public int y;
public V(Context context) {
super(context);
SurfaceHolder holder = getHolder();
holder.addCallback(this);
mThread = new CThread(holder,this);
x = 0;
y = 0;
setBackgroundDrawable(getResources().getDrawable(R.drawable.bg));
}
@Override
public void onDraw(Canvas canvas)
{
Paint paint = new Paint();
paint.setColor(Color.WHITE);
canvas.drawLine(x, y, getWidth(), getHeight(), paint);
}
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
x = (int) event.getX();
y = (int) event.getY();
default: break;
}
return true;
}
public void surfaceCreated(SurfaceHolder holder) {
mThread.setRunning(true);
mThread.start();
}
/* sufraceDestroyed etc */
} // end class declaration
public class CThread extends Thread {
private SurfaceHolder mSurfaceHolder;
private V mView;
private boolean mRun = false;
public CThread(SurfaceHolder surfaceHolder, V view) {
mSurfaceHolder = surfaceHolder;
mView = view;
}
public void setRunning(boolean run) {
mRun = run;
}
@Override
public void run() {
Canvas c;
while (mRun) {
c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
mView.onDraw(c);
}
} finally {
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
To unsubscribe from this group, send email to
android-beginners+unsubscribegooglegroups.com or reply to this email with the
words "REMOVE ME" as the subject.