I am trying to draw multi circle with different color by using the same Paint but change the paint color I am using for loop to this in ondraw However, it doesnt work. can anyone tell me wut am i doing wrong?
public class theGamev2 extends Activity { final static int POINTER = 0x102; final static int REDRAW = 0x101; Thread myRefreshThread = null; static int pointerCurrentXCoord; int pointerCurrentYCoord; int pointerInitialXCoord; int pointerInitialYCoord; int screenWidth; int screenHeight; int lengthPerPart; int pressTime; int releaseTime; Color color = new Color(); int tIME = 4; /** Called when the activity is first created. */ Ball mBall = null; Random r = new Random(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); initialCondition(); this.mBall = new Ball(this); setContentView(this.mBall); this.myRefreshThread = new Thread(new RefreshCountDown()); this.myRefreshThread.start (); } private void initialCondition() { // TODO Auto-generated method stub DisplayMetrics dm = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(dm); screenWidth = dm.widthPixels; screenHeight = dm.heightPixels; pointerInitialXCoord = screenWidth/8; pointerInitialYCoord = screenHeight/8; lengthPerPart = screenWidth/8; pointerCurrentXCoord = pointerInitialXCoord; pointerCurrentYCoord = pointerInitialYCoord; } class RefreshCountDown implements Runnable{ // @Override public void run() { while(!Thread.currentThread().isInterrupted()){ Message m = new Message(); m.what = theGamev2.REDRAW; theGamev2.this.mBallUpdateHandler.sendMessage(m); try { Thread.sleep(50); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } } } Handler mBallUpdateHandler = new Handler(){ /** Gets called on every message that is received */ // @Override public void handleMessage(Message msg) { switch (msg.what) { case theGamev2.POINTER: mBall.updatePointerCoord(); mBall.invalidate(); break; case theGamev2.REDRAW: // We identified the Message by its What-ID /*tIME = tIME + 1; */ mBall.updateBallAcc(); mBall.invalidate(); break; } super.handleMessage(msg); } }; public boolean onKeyUp(int keyCode, KeyEvent event) { Message m = new Message(); m.what = theGamev2.REDRAW; switch(keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: /* releaseTime = System.currentTimeMillis(); */ /*releaseTime = tIME; int pressedTime = (releaseTime - pressTime) * 5; */ this.mBall.createNewCircle(pointerCurrentXCoord, 30, tIME,color.rgb(r.nextInt(256), r.nextInt(256), r.nextInt(256))); tIME = 0; mBall.prepareCircleR = tIME; tIME = 4; break; default: return super.onKeyDown(keyCode, event); } this.mBallUpdateHandler.sendMessage(m); return true; } public boolean onKeyDown(int keyCode, KeyEvent event) { Message m = new Message(); m.what = theGamev2.POINTER; switch(keyCode){ case KeyEvent.KEYCODE_DPAD_CENTER: /*pressTime = System.currentTimeMillis();*/ /*pressTime = tIME; */ tIME = tIME + 2; if (tIME > 40) { tIME = 40; } mBall.prepareCircleR = tIME; break; case KeyEvent.KEYCODE_DPAD_LEFT: if(pointerCurrentXCoord == lengthPerPart) { pointerCurrentXCoord = pointerCurrentXCoord + (lengthPerPart * 6); } else if(pointerCurrentXCoord == (lengthPerPart * 5)) { pointerCurrentXCoord = pointerCurrentXCoord - (lengthPerPart * 2); } else { pointerCurrentXCoord = pointerCurrentXCoord - lengthPerPart; } break; case KeyEvent.KEYCODE_DPAD_RIGHT: if(pointerCurrentXCoord == (lengthPerPart * 3)) { pointerCurrentXCoord = pointerCurrentXCoord + (lengthPerPart * 2); } else if (pointerCurrentXCoord == (lengthPerPart * 7)) { pointerCurrentXCoord = pointerCurrentXCoord - (lengthPerPart * 6); } else { pointerCurrentXCoord = pointerCurrentXCoord + lengthPerPart; } break; default: return super.onKeyDown(keyCode, event); } this.mBallUpdateHandler.sendMessage(m); return true; } package game.balance2; import java.util.Random; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuffColorFilter; import android.graphics.Path.Direction; import android.view.View; public class Ball extends View{ /* public Ball(Context context,float x,float y,int r) { super(context); // TODO Auto-generated constructor stub Paint mPaint = new Paint(); mPaint.setColor(0xFF0000); Canvas mCanvas = new Canvas(); mCanvas.drawCircle(x,y,r,mPaint); } */ final int screenWidth = getWidth(); int x; static int y; int r; int c; int xAcc; int yAcc; int numberOfBalls = 0; int[] circleCoordsX = new int[100]; int[] circleCoordsY = new int[100]; int[] circleRadiusR = new int[100]; int[] circleColor = new int[100]; int prepareCircleX; int prepareCircleR; public Ball(Context context) { super(context); } protected void onDraw(Canvas canvas){ super.onDraw(canvas); Path circle = new Path(); Paint paint1 = new Paint(); Paint paint2 = new Paint(); Path pointer = new Path(); Path prepareCircle = new Path(); paint1.setColor(Color.RED); paint2.setColor(Color.BLUE); pointer.addCircle(theGamev2.pointerCurrentXCoord, 0, 20, Direction.CW); prepareCircle.addCircle(theGamev2.pointerCurrentXCoord, 30, prepareCircleR, Direction.CW); canvas.drawPath(pointer, paint1); canvas.drawPath(prepareCircle, paint2); for(int count = 0 ; count < numberOfBalls; count++) { x = circleCoordsX[count]; y = circleCoordsY[count]; r = circleRadiusR[count]; paint2.setColor(circleColor[count]); circle.addCircle(x,y,r, Direction.CW); canvas.drawPath(circle,paint2); } } --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---