Android Open Source - MakeitRain Dolla Surface






From Project

Back to project page MakeitRain.

License

The source code is released under:

GNU General Public License

If you think the Android project MakeitRain 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 com.finlay.makeitrain;
/*from   www. j  av  a2s.  c om*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;

public class DollaSurface extends SurfaceView implements SurfaceHolder.Callback {
  private static final String TAG = "DollaSurface";

  private GameThread _Thread;
  private Paint _paint;
  private Rect _canvasBounds;
  private List<DollaBill> bills;

  public DollaSurface(Context context, AttributeSet attrs) {
    super(context, attrs);

    getHolder().addCallback(this);

    _Thread = new GameThread(getHolder(), this);
    _paint = new Paint();

    // Lists
    bills = new ArrayList<DollaBill>();

    setFocusable(true);  

  }


  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
    Log.v(TAG, "surfaceChanged");
    _canvasBounds = new Rect(0,0,width,height);
  }


  @Override
  public void surfaceCreated(SurfaceHolder holder) {
    Log.v(TAG, "surfaceCreated");

    _Thread.setRunning(true);
    _Thread.start();
  }


  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    Log.v(TAG, "surfaceDestroyed");

    boolean retry = true;
    _Thread.setRunning(false);
    while (retry) {
      try {
        _Thread.join();
        retry = false;
      } catch (InterruptedException e) {//keep on trying}
      }
    }
  }

  public void sendTouchEvent() {
    bills.add(new DollaBill(_canvasBounds,BitmapFactory.decodeResource(getResources(), R.drawable.dolla_bill)));
  }

  public void render(Canvas canvas) {
    // draw stuff
    _paint.setColor(Color.BLUE);
    canvas.drawRect(canvas.getClipBounds(), _paint);

    for (int i=bills.size()-1; i>=0; i--)
      bills.get(i).draw(canvas, _paint);
    
  }

  public void update() {
    // update stuff
    for (DollaBill bill : bills) {
      bill.update();
    }
    
    for (int i=0; i<bills.size(); i++) {
      if (!bills.get(i).AliveEh()) {
        bills.remove(i); i--;
      }
    }
  }


}




Java Source Code List

com.finlay.makeitrain.DollaBill.java
com.finlay.makeitrain.DollaSurface.java
com.finlay.makeitrain.GameThread.java
com.finlay.makeitrain.MainActivity.java