Created
October 15, 2014 23:37
-
-
Save akira-sasaki/048e60d335f35163184d to your computer and use it in GitHub Desktop.
Taiko001
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package gclue.com.taiko; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.content.res.Resources; | |
import android.graphics.Bitmap; | |
import android.graphics.BitmapFactory; | |
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.Paint; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.view.View; | |
public class MyActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
// TaikoViewのインスタンス化. | |
TaikoView mTaikoView = new TaikoView(this); | |
// TaikoViewを画面に設定. | |
setContentView(mTaikoView); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.my, menu); | |
return true; | |
} | |
@Override | |
public boolean onOptionsItemSelected(MenuItem item) { | |
/* | |
Handle action bar item clicks here. The action bar will | |
automatically handle clicks on the Home/Up button, so long | |
as you specify a parent activity in AndroidManifest.xml. | |
*/ | |
int id = item.getItemId(); | |
if (id == R.id.action_settings) { | |
return true; | |
} | |
return super.onOptionsItemSelected(item); | |
} | |
} | |
/** | |
* 太鼓の画像を表示するView. | |
*/ | |
class TaikoView extends View { | |
/** 太鼓画像データを保持する. */ | |
private Bitmap mTaikoImage; | |
/** 太鼓画像の原点(左上)のx座標を保持する. */ | |
private int mTaikoX = 100; | |
/** 太鼓画像の原点(左上)のy座標を保持する. */ | |
private int mTaikoY = 50; | |
/** | |
* コンストラクタ. | |
* @param context コンテキスト | |
*/ | |
public TaikoView( Context context ) { | |
super(context); | |
// イベント取得できるようにFocusを有効にする. | |
setFocusable( true ); | |
// Resourceインスタンスの生成. | |
Resources res = this.getContext().getResources(); | |
// 画像の読み込み(/res/drawable-hdpi/taiko.png). | |
mTaikoImage = BitmapFactory.decodeResource(res, R.drawable.taiko); | |
} | |
/** | |
* 描画処理. | |
*/ | |
@Override | |
protected void onDraw( Canvas canvas ) { | |
// 背景色を設定する. | |
canvas.drawColor( Color.BLACK ); | |
// Bitmapイメージの描画. | |
Paint mPaint = new Paint(); | |
canvas.drawBitmap( mTaikoImage, mTaikoX, mTaikoY, mPaint ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment