Update: I found a working answer, Android: how to make a clickable map image with each country producing a different action?
I was trying to do some tests with having different effects on different parts of an image being clicked: http://postimg.org/image/pwrcc7pyh/
For example when I click on Saudi Arabia which has a hex of FFFF00, getPixel(x, y) prints out -256 (I don't know if that's correct). The problem is that Yemen also prints out -256 but has a hex of 9EFA69. Does anyone know why this happens?
ImageButton ib = (ImageButton) findViewById(R.id.middle);
final Bitmap theBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.middle_east);
ib.setImageBitmap(theBitmap);
ib.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int eventPadTouch = event.getAction();
switch (eventPadTouch) {
case MotionEvent.ACTION_DOWN:
if (event.getX()>=0 & event.getY()>=0 & event.getX()<theBitmap.getWidth() & event.getY()<theBitmap.getHeight()) { // ** Makes sure that X and Y are not less than 0, and no more than the height and width of the image.
int pixColor = theBitmap.getPixel((int)event.getX(),(int)event.getY());
String country = null;
Log.e("MainActivity", pixColor + "");
if (pixColor == getResources().getColor(R.color.yellow)) country = "Saudi Arabia";
else if (pixColor == getResources().getColor(R.color.light_green)) country = "Yemen";
else if (pixColor == getResources().getColor(R.color.dark_yellow)) country = "Oman";
else if (pixColor == getResources().getColor(R.color.banana_yellow)) country = "Syria";
else if (pixColor == getResources().getColor(R.color.golden_yellow)) country = "Iraq";
if (country != null)
{
Log.e("MainActivty", country + " " + pixColor);
Toast t = Toast.makeText(MainActivity.this, country, Toast.LENGTH_SHORT);
t.show();
}
}
return true;
}
return false;
}
});
Thanks all:)