classGFX

Last-modified: 2015-03-18 (水) 12:29:35
public class GFX extends Activity{

	MyBringBack ourView;
	WakeLock wL;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// wake-lock
		PowerManager pM  = (PowerManager)getSystemService(Context.POWER_SERVICE);
		wL = pM.newWakeLock(PowerManager.FULL_WAKE_LOCK, "whatever");

		super.onCreate(savedInstanceState);
		wL.acquire();
		ourView = new MyBringBack(this);
		setContentView(ourView);
	}

	@Override
	protected void onPause() {
		// TODO 自動生成されたメソッド・スタブ
		super.onPause();
		wL.release();
	}

	public class MyBringBack extends View{
		Bitmap gBall;
		float changingY;
		Typeface font;

		public MyBringBack(Context context) {
			super(context);
			gBall = BitmapFactory.decodeResource(getResources(), R.drawable.kuma_64);
			changingY = 0;
			font = Typeface.createFromAsset(context.getAssets(), "G-Unit.ttf");
		}

		@Override
		protected void onDraw(Canvas canvas) {
			// TODO 自動生成されたメソッド・スタブ
			super.onDraw(canvas);
			canvas.drawColor(Color.WHITE);

			Paint textPaint = new Paint();
			textPaint.setARGB(50, 254, 10, 50);
			textPaint.setTextAlign(Align.CENTER);
			textPaint.setTextSize(50);
			textPaint.setTypeface(font);
			canvas.drawText("mybringback", (canvas.getWidth()/2), 200, textPaint);

			canvas.drawBitmap(gBall, (canvas.getWidth()/2), changingY, null);
			if(changingY<canvas.getHeight()){
				changingY += 10;
			} else {
				changingY = 0;
			}
			Rect middleRect = new Rect();
			middleRect.set(0, 400, canvas.getWidth(), 550);
			Paint ourBlue = new Paint();
			ourBlue.setColor(Color.BLUE);
			canvas.drawRect(middleRect, ourBlue);

			invalidate();
		}
	}
}