I have an application with an image's feed (Instagram style). I'm trying to show a quick image preview using long click over the image.
The main idea is show the image in a dialog when the user made a longclik, then modify zoom when the user move down/up his finger and close the preview when the finger is released.
In orden to archive that I have a onLongClick in the fragment's adapter like this:
holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
listener.onLongClick(item.getId());
return false;
}
});
Then, the fragment implements the listener and call the dialog like this:
@Override
public void onLongClick(long itemId) {
FullscreenPhotoPreviewDialog dialog = FullscreenPhotoPreviewDialog.newInstance(itemId);
dialog.show(getActivity().getSupportFragmentManager(), "FullscreenPhotoPreviewDialog");
}
Finally, the Dialog implements all the OnTouch logic to let the user make the zoom, without releasing the finger.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
switch(motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
float scale = 0;
if (motionEvent.getHistorySize() > 0)
scale = ((motionEvent.getY() > motionEvent.getHistoricalY(motionEvent.getHistorySize() - 1)) ? 0.1f : -0.1f);
FullscreenPhotoPreviewDialog.this.applyScale(scale);
break;
case MotionEvent.ACTION_UP:
FullscreenPhotoPreviewDialog.this.dismiss();
break;
}
return true;
}
});
}
The flow of open the dialog with the long click it's working ok. The problem it's with the onTouch. The long click isn't sending the ACTION_DOWN event to the onTouch. So I need to pull up, and the pull down again to start the onTouch.
There is any way to do this?. To automatically call the ACTION_DOWN from the long press?
Thanks and sorry for my english!