Android Open Source - FallingBall Cell View






From Project

Back to project page FallingBall.

License

The source code is released under:

GNU General Public License

If you think the Android project FallingBall listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package edu.fmi.android.brickpong.view;
//from  w  ww .  j a  va2s.  c  o  m
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;
import edu.fmi.android.brickpong.R;

public class CellView extends View {

  /**
   * {@value}
   */
  @SuppressWarnings("unused")
  private static final String TAG = CellView.class.getSimpleName();

  /**
   * {@value}
   */
  public static final int WIDTH_CELL = 60;

  /**
   * {@value}
   */
  public static final int HEIGHT_CELL = 20;

  /**
   * {@value}
   */
  private static final int WIDTH_BORDER = 2;

  private final Paint cellPaint;

  private final RectF boundingRect;

  public CellView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    cellPaint = new Paint();
    cellPaint.setStrokeWidth(WIDTH_BORDER);

    boundingRect = new RectF();
  }

  public CellView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }

  public CellView(Context context) {
    this(context, null);
  }

  public void setX(final float positionX) {
    boundingRect.left = positionX;
    boundingRect.right = positionX + WIDTH_CELL;
  }

  public void setY(final float positionY) {
    boundingRect.top = positionY;
    boundingRect.bottom = positionY + HEIGHT_CELL;
  }

  public RectF getBoundingRect() {
    return boundingRect;
  }

  @Override
  protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    cellPaint.setStyle(Paint.Style.FILL);
    cellPaint.setColor(getResources().getColor(R.color.grey));
    canvas.drawRect(boundingRect, cellPaint);

    cellPaint.setStyle(Paint.Style.STROKE);
    cellPaint.setColor(getResources().getColor(R.color.light_grey));
    canvas.drawRect(boundingRect, cellPaint);
  }

}




Java Source Code List

edu.fmi.android.brickpong.GameActivity.java
edu.fmi.android.brickpong.GameItem.java
edu.fmi.android.brickpong.HomeActivity.java
edu.fmi.android.brickpong.SplashActivity.java
edu.fmi.android.brickpong.listeners.OnGameEventsListener.java
edu.fmi.android.brickpong.listeners.OnPositionChangedListener.java
edu.fmi.android.brickpong.utils.Direction.java
edu.fmi.android.brickpong.utils.ScreenUtil.java
edu.fmi.android.brickpong.utils.Vector.java
edu.fmi.android.brickpong.view.BallView.java
edu.fmi.android.brickpong.view.BorderView.java
edu.fmi.android.brickpong.view.CellView.java
edu.fmi.android.brickpong.view.FinishedGameView.java
edu.fmi.android.brickpong.view.GameLayout.java
edu.fmi.android.brickpong.view.PadView.java
edu.fmi.android.brickpong.view.ResultsView.java