예제 #1
0
 private ShapeHolder createBall(float x, float y) {
   OvalShape circle = new OvalShape();
   circle.resize(BALL_SIZE, BALL_SIZE);
   ShapeDrawable drawable = new ShapeDrawable(circle);
   ShapeHolder shapeHolder = new ShapeHolder(drawable);
   shapeHolder.setX(x);
   shapeHolder.setY(y);
   return shapeHolder;
 }
예제 #2
0
 @Override
 protected void onResize(float width, float height) {
   // TODO Auto-generated method stub
   super.onResize(width, height);
   centerX = (int) width / 2;
   centerY = (int) height / 2;
 }
예제 #3
0
 @Override
 public void draw(Canvas canvas, Paint paint) {
   // TODO Auto-generated method stub
   super.draw(canvas, paint);
   mPaint.setStyle(Style.FILL);
   canvas.drawCircle(centerX, centerY, innerRadius, mPaint);
   mPaint.setStyle(Style.STROKE);
   canvas.drawCircle(centerX, centerY, outerRadius, mPaint);
 }
 private ShapeHolder addBall(float x, float y) {
   OvalShape circle = new OvalShape();
   circle.resize(50f, 50f);
   ShapeDrawable drawable = new ShapeDrawable(circle);
   ShapeHolder shapeHolder = new ShapeHolder(drawable);
   shapeHolder.setX(x - 25f);
   shapeHolder.setY(y - 25f);
   int red = (int) (Math.random() * 255);
   int green = (int) (Math.random() * 255);
   int blue = (int) (Math.random() * 255);
   int color = 0xff000000 | red << 16 | green << 8 | blue;
   Paint paint = drawable.getPaint(); // new Paint(Paint.ANTI_ALIAS_FLAG);
   int darkColor = 0xff000000 | red / 4 << 16 | green / 4 << 8 | blue / 4;
   RadialGradient gradient =
       new RadialGradient(37.5f, 12.5f, 50f, color, darkColor, Shader.TileMode.CLAMP);
   paint.setShader(gradient);
   shapeHolder.setPaint(paint);
   balls.add(shapeHolder);
   return shapeHolder;
 }