Skip to content

Commit

Permalink
- Find ImageViewTouch even if not the selected view/item
Browse files Browse the repository at this point in the history
- Send all events to gellery instead of sending UP events when handled byt ImageViewTouch.
  This makes the gallery more responsive and less jumps. The downside is that the zommed image scroll makes the gallery scroll as well.
  I need to find a better way to disable the gallery scrolling when scrolling a zoomed image.
  • Loading branch information
[email protected] committed Oct 21, 2012
1 parent 9c8cec6 commit 7c22635
Showing 1 changed file with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
package it.sephiroth.android.library.imagezoom;

import android.content.Context;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Gallery;

public class GalleryTouch extends Gallery {

public GalleryTouch(Context context, AttributeSet attrs) {
super(context, attrs);
}

public GalleryTouch(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}

public GalleryTouch(Context context) {
super(context);
}
Expand Down Expand Up @@ -34,7 +45,14 @@ public boolean onTouchEvent(MotionEvent event) {
// if (gallery.getSelectedItemPosition() == movedItemIndex && !inMove) {
// if (!inGallery && gallery.getSelectedItemPosition() == movedItemIndex) {
if (getSelectedItemPosition() == movedItemIndex) {
ImageViewTouch imageViewTouch = (ImageViewTouch) getSelectedItem();
int imageViewTouchId = getImageViewTouchId();
View selectedView = getSelectedView();
ImageViewTouch imageViewTouch;
if (imageViewTouchId == 0) {
imageViewTouch = (ImageViewTouch) selectedView;
}else {
imageViewTouch = (ImageViewTouch) selectedView.findViewById(imageViewTouchId);
}
boolean handled = imageViewTouch.onTouchEvent(event);
Log.d("", "handled: " + handled);
if (handled) {
Expand All @@ -43,7 +61,7 @@ public boolean onTouchEvent(MotionEvent event) {
// this.handled = true;

// Cancel the the gallery action if the ImgeViewTouch is working
event.setAction(MotionEvent.ACTION_UP);
// event.setAction(MotionEvent.ACTION_UP);
super.onTouchEvent(event);
return true;
}
Expand All @@ -56,4 +74,8 @@ public boolean onTouchEvent(MotionEvent event) {
// return false;
return super.onTouchEvent(event);
}

protected int getImageViewTouchId() {
return 0;
}
}

0 comments on commit 7c22635

Please sign in to comment.