MySurfaceView.java :  » Game » douball » tw » edu » ntu » csie » r403 » Android Open Source

Android Open Source » Game » douball 
douball » tw » edu » ntu » csie » r403 » MySurfaceView.java
package tw.edu.ntu.csie.r403;

import java.util.ArrayList;

import tw.edu.ntu.csie.r403.douball.android.R;
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.view.View;

public class MySurfaceView extends View {
  ArrayList<MyRect> walls;
  
  public MySurfaceView(Context context) {
    super(context);
    
  }

  public MySurfaceView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    
  }

  public MySurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
    
  }
  @Override
  protected void onDraw(Canvas canvas) {
    walls = new ArrayList<MyRect>();
    walls.add(new MyRect(40, 0, 60, 180));
    walls.add(new MyRect(90, 0, 110, 180));
    super.onDraw(canvas);
    
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.back_m2); 
    Paint paint = new Paint();
    paint.setColor(Color.GRAY);
    for(int i=0 ; i< walls.size() ; i++) {
      MyRect obj = walls.get(i);
      //canvas.drawRect(obj.LeftTop.x, obj.LeftTop.y, obj.RightBottom.x, obj.RightBottom.y, paint);
      //Log.d("douball", obj.LeftTop.x +","+ obj.RightBottom.x+","+ obj.LeftTop.y+","+ obj.RightBottom.y);
      canvas.drawBitmap(bitmap,
          new Rect(0, 0, 200, 200),
          new Rect(obj.leftTop.x, obj.leftTop.y, obj.rightBottom.x, obj.rightBottom.y),
          paint);
    }
    
    
    
    canvas.drawBitmap(bitmap, 100, 100, paint);
  }
  
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.