@Override public boolean onTouch(View v, MotionEvent event) { int ex = (int) event.getX(); int ey = (int) event.getY(); System.out.println(event.getX() + "," + event.getY()); int selectIndex = -1; for (int i = 0; i < menuItems.length; i++) { System.out.println(x + " " + (y + i * 43)); if (Poke.inRect(ex, ey, x, y + i * 43, 125, 33)) { selectIndex = i; break; } } System.out.println(selectIndex); switch (selectIndex) { case 0: ddz.handler.sendEmptyMessage(DDZ.GAME); break; case 1: break; case 2: break; case 3: break; case 4: ddz.finish(); break; } return super.onTouchEvent(event); }
public MenuView(Context context, DDZ ddz) { super(context); this.ddz = ddz; menuItems = new Bitmap[5]; holder = getHolder(); back = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu); menuItems[0] = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu1); menuItems[1] = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu2); menuItems[2] = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu3); menuItems[3] = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu4); menuItems[4] = BitmapFactory.decodeResource(ddz.getResources(), R.drawable.menu5); // for(int i=0;i<menuItems.length;i++) // { // menuItems[0]=BitmapFactory.decodeFile("menu"+(i+1)+".png"); // } this.getHolder().addCallback(this); this.setOnTouchListener(this); }