うまくいけば、これが私のアプリを完成させる最後のステップです。ビデオを再生する新しいアクティビティ(mp4)を呼び出すか、現在のアクティビティ内でビデオを再生する、クリック可能なキャンバス内のビットマップを作成する必要があります。
キャンバスとビットマップを表示するクラスは、サムネイルの完全な画像を表示するために何度も使用するクラスです。画像IDはインテントを介して渡されます。これが完全な画像アクティビティのコードです(私は非常に初心者で、このサイトや他のサイトを使用して一度に1ステップずつコードをつなぎ合わせたので、きれいでない場合はお詫びします):
public class full_image extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(new BitmapView(this));
getWindow().setBackgroundDrawableResource(R.drawable.bground);
getWindow().setWindowAnimations(0);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
class BitmapView extends View {
public BitmapView(Context context) {
super(context);
}
@Override
public void onDraw(Canvas canvas) {
int imgid = getIntent().getIntExtra("Full",0);
Bitmap fullimage = BitmapFactory.decodeResource(getResources(),imgid);
Bitmap playButton = BitmapFactory.decodeResource(getResources(), R.drawable.bt_play); //Added for Video
Display display = getWindowManager().getDefaultDisplay();
int fpWidth = fullimage.getWidth();
int fpHeight = fullimage.getHeight();
int playWidth = playButton.getWidth();
int playHeight = playButton.getHeight();
int screenWidth = display.getWidth();
int screenHeight = display.getHeight();
int leftPoint = screenWidth/2 - fpWidth/2;
int topPoint = screenHeight/2 - fpHeight/2;
int leftPlayPoint = screenWidth/2 - playWidth/2;
int topPlayPoint = screenHeight/2 - playHeight/2;
canvas.drawBitmap(fullimage,leftPoint,topPoint,null);
canvas.drawBitmap(playButton,leftPlayPoint,topPlayPoint,null);
}
}
}
可能であれば、playButtonだけにonClickListenerを格納したいのですが、それが簡単な場合は、キャンバス全体をクリック可能にすることで問題ありません(可能な場合でも)。
TouchEventを使用する提案があった別の質問を読みました。私はそのルートに行ってみましたが、うまくいきませんでした。これは正しい道であり、私はそれを機能させるためにそれをもっといじる必要がありますか?
ありがとう、J
追加のもの:
これが別の質問で見つけたコードの抜粋です。このコードを上記のコードのどこに配置しますか。
public boolean onTouchEvent(MotionEvent event){
int action = event.getAction();
int x = event.getX() // or getRawX();
int y = event.getY();
switch(action){
case MotionEvent.ACTION_DOWN:
if (x >= xOfYourBitmap && x < (xOfYourBitmap + yourBitmap.getWidth())
&& y >= yOfYourBitmap && y < (yOfYourBitmap + yourBitmap.getHeight())) {
//tada, if this is true, you've started your click inside your bitmap
}
break;
}
}