I have an image which shows different toasts when touched in different sections. Here is the code.
public class MainActivity extends Activity implements OnTouchListener
{
String xcoordinate, ycoordinate;
Integer xint, yint;
Double xdoub, ydoub;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View touchView = findViewById(R.id.lyt);
touchView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event)
{
xcoordinate = String.valueOf(event.getX());
ycoordinate = String.valueOf(event.getY());
xdoub = Double.valueOf(xcoordinate);
ydoub = Double.valueOf(ycoordinate);
xint = xdoub.intValue();
yint = ydoub.intValue();
Toast.makeText(getApplicationContext(), "Touch coordinates : " +
String.valueOf(event.getX()) + "x and " + String.valueOf(event.getY()) + "y", Toast.LENGTH_SHORT).show();
LaunchPopup();
return true;
}
});
}
public void LaunchPopup()
{
if(xint > 243 && xint < 307 && yint > 315 && yint < 410)
{
Toast.makeText(getApplicationContext(), "Center", Toast.LENGTH_SHORT).show();
}
else if(xint > 330 && xint < 394 && yint > 24 && yint < 122)
{
Toast.makeText(getApplicationContext(), "Manual 68 Section", Toast.LENGTH_SHORT).show();
}
else if(xint > 330 && xint < 394 && yint > 154 && yint < 250)
{
Toast.makeText(getApplicationContext(), "Manual 79 Section", Toast.LENGTH_SHORT).show();
}
else if(xint > 330 && xint < 394 && yint > 314 && yint < 410)
{
Toast.makeText(getApplicationContext(), "Manual 17 Section", Toast.LENGTH_SHORT).show();
}
else if(xint > 330 && xint < 394 && yint > 458 && yint < 554)
{
Toast.makeText(getApplicationContext(), "Manual 45 Section", Toast.LENGTH_SHORT).show();
}
else if(xint > 330 && xint < 394 && yint > 602 && yint < 700)
{
Toast.makeText(getApplicationContext(), "Group Task Section", Toast.LENGTH_SHORT).show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
return false;
}
}
Now its working fine when the image is fit to screen. But what I want is to add zoom feature to the image without loosing the main function of particular toast on particular sections of the image. Is there any way to do this.? I mean is there anything by which I can represent the ratio of the zoom with the change in x and y coordinates.? So that the image should still do the same action when touched in that particular section even after zoom.?