Javaど素人の自分がなんとか作り上げました(^^;
まず、本体のmokomokomoko.java
-
package com.simple_sys.Mokomokomoko;
-
-
import android.app.Activity;
-
import android.os.Bundle;
-
import android.view.Window;
-
-
public class Mokomokomoko extends Activity {
-
/** Called when the activity is first created. */
-
@Override
-
public void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
setContentView(new MokoView(this));
-
}
-
}
どこぞのサンプルをほぼまる写し・・・(^^;
続いて、上記から呼ばれる、MokoViewクラス
-
package com.simple_sys.Mokomokomoko;
-
import android.app.Activity;
-
import android.app.AlertDialog;
-
import android.content.res.Resources;
-
import android.content.Context;
-
import android.content.DialogInterface;
-
import android.graphics.Bitmap;
-
import android.graphics.BitmapFactory;
-
import android.graphics.Canvas;
-
import android.graphics.Color;
-
import android.graphics.Rect;
-
import android.media.MediaPlayer;
-
import android.view.View;
-
import android.view.MotionEvent;
-
import android.util.Log;
-
import android.media.MediaPlayer;
-
-
private Bitmap image;
-
private int max=17;
-
private int page=1;
-
private Resources r;
-
private String pkgname;
-
private MediaPlayer player;
-
private int touchStart;
-
private int touchEnd;
-
-
-
super(context);
-
r=context.getResources();
-
pkgname=context.getPackageName();
-
image=BitmapFactory.decodeResource(r,getResources().getIdentifier("moko"+page, "drawable", pkgname));
-
setFocusable(true);
-
}
-
-
@Override
-
-
int w=image.getWidth();
-
int h=image.getHeight();
-
Rect src=new Rect(0,0,w,h);
-
Rect dst=new Rect(0,0,getWidth(),getHeight());
-
canvas.drawBitmap(image,src,dst,null);
-
-
//メディアファイルの再生
-
try {
-
player=MediaPlayer.create(getContext(), getResources().getIdentifier("moko"+page+"s", "raw", pkgname));
-
player.prepare();
-
-
}
-
player.seekTo(0);
-
player.start();
-
-
}
-
-
@Override
-
public boolean onTouchEvent(MotionEvent event){
-
if (event.getAction()==MotionEvent.ACTION_DOWN){
-
//押された。押された時点での位置を取得
-
touchStart=(int)event.getX();
-
}
-
else if (event.getAction()==MotionEvent.ACTION_UP){
-
//離された
-
touchEnd=(int)event.getX();
-
-
if (touchStart>touchEnd){
-
//右から左に指が移動した(次のページへめくった)
-
this.page+=1;
-
if (this.page>this.max){this.page=1;}
-
} else {
-
//左から右に指が移動した(前のページをめくった)
-
this.page-=1;
-
if (this.page==0){this.page=this.max;}
-
}
-
-
image=BitmapFactory.decodeResource(r,getResources().getIdentifier("moko"+page, "drawable", pkgname));
-
invalidate();
-
-
-
}
-
return true;
-
}
-
-
-
-
}
一応、指でめくる機能はつけました。
あと、ページが表示されると同時に音声もなるようにしています。
画像と音声の情報ですが、本当はSDカードに入れて、簡単に入れ替えられるようにしたかったのですが、ちょっと力つきまして(^^;アプリケーションの中に埋め込む形になっています。
エラー処理とか手抜きまくりとは思いますが、とりあえず自分で作ったアプリがandoroid上で動くという目的は達成しました。
肝心の息子の反応は・・・今は、もこもこもこより電車の絵本に夢中・・・ f^_^;
次は電車アプリか? (^_^;)










