I'm using PhotoView
https://github.com/chrisbanes/PhotoView
It on it's own already implements an OnTouchListener
on the ImageView
you give it.
Here is my problem tho I need to implement a OnLongTouchListener
as well and in it I need X & Y coordinates
of the touch event. The problem is I cannot get those from OnLongTouchListener->onLongClick(View ..)
which means I need to also implement my own OnTouchListener
get the X & Y
from MotionEvent
put them in class variable than do my thing in OnLongTouchListener
.
However my own OnTouchListener overrides PhotoViews listener removing the zoom & swipe functionality.
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import java.util.Observable;
import uk.co.senab.photoview.PhotoViewAttacher;
public class MapView extends Observable {
private MainActivity activity;
private PhotoViewAttacher photoView;
private Matrix viewMatrix;
protected ImageView view;
protected Bitmap bitmap;
public MapView(MainActivity activity) {
this.activity = activity;
view = (ImageView) activity.findViewById(R.id.map_view);
bitmap = BitmapFactory.decodeResource(activity.getResources(), R.drawable.floorplan);
photoView = new PhotoViewAttacher(view);
viewMatrix = view.getImageMatrix();
view.setOnTouchListener(new MapViewTouchListener());
view.setOnLongClickListener(new MapViewLongTouchListener());
}
private class MapViewLongTouchListener implements View.OnLongClickListener {
public boolean onLongClick(View v) {
Log.i("output", "Long press");
return true;
}
}
private class MapViewTouchListener implements View.OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
Log.i("output", "Touch");
return true;
}
}
}
Temporary solution. I created my own class and overrode the onTouch
method. Turns out PhotoViewAttacher
implements OnTouchListener
so i was able to get it working just reimplementing the method.
Solution was to simply extend the
PhotoViewAttacher
class implementOnLongClickListener
and pass it theMotionEvent
from internalonTouch
method.