touch event in live wallpaper in Android

707 views Asked by At

I want to build aquarium app live wallpaper in Android in which I draw multiple Bitmap now I want add touch event and when I touch fish should react how I can know which particuler fish is touched how I can do taht

private void draw() {
    final SurfaceHolder holder = getSurfaceHolder();
    Canvas C = null;
    try {
        C = holder.lockCanvas();
        c.drawColor(Color.BLACK);
        if (c != null) {
            if (playingcounter3 == 20) {
                playingcounter3 = 0;
            }
            c.drawBitmap(fish_c[1][playingcounter3], x1, 200, null);
            if (x > width) {
                x = -f1_width - width / 7;

            }
        }
    } finally {
        if (c != null) holder.unlockCanvasAndPost(c);
    }
    handler.removeCallbacks(drawRunner);
    if (visible) {
        handler.postDelayed(drawRunner, 10);
    }
}
1

There are 1 answers

0
Alexander Fuchs On

You have to check the pixel values of an on touch event.

@Override
public void onTouchEvent(MotionEvent event) 
{
     if (event.getAction() == MotionEvent.ACTION_DOWN) 
     {                         
       event.getX();   
       event.getY();   
     }           

    super.onTouchEvent(event);
}