GithubHelp home page GithubHelp logo

Comments (12)

yevon avatar yevon commented on July 30, 2024

I have a view pager and it works correctly, the drawback is that you should be able to detect if imageView is zoomed for desactive viewPager paging. If not, you cannot move or zoom to left/right.

from gesture-imageview.

petar-bogdanov avatar petar-bogdanov commented on July 30, 2024

How are you placing it in the ViewPager? With an image, or loaded with an AsyncTask? Do you have a custom OnTouchListener?

from gesture-imageview.

yevon avatar yevon commented on July 30, 2024

I have a custom ViewPager that can disable paging. Then i just use a GestureImageView. I have modified the gesture imageView to have a function called isZoomed(). Then i put a touchListener to theGestureImageView, and if it isZoomed() i do ViewPager.setPagingEnabled(false), else setPagingEnabled(true). That way you can't pass to the next /prior image if it is zoomed.

This code has a litlle problem, if you do a double tap to disable zoom, its not detected, so isZoomed is not false and you would not be able to switch to next image. If you do pinch to disable zoom works perfect.
It need to put isZoomed = false somwhere in code, i have to discover where.


public class ViewPagerDisable extends ViewPager {

private boolean enabled;

public ViewPagerDisable(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.enabled = true;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (this.enabled) {
        return super.onTouchEvent(event);
    }

    return false;
}

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    if (this.enabled) {
        return super.onInterceptTouchEvent(event);
    }

    return false;
}

public void setPagingEnabled(boolean enabled) {
    this.enabled = enabled;
}

}

In gestureImageView.java...

public boolean isZoomed() {
boolean result = false;
if(gestureImageViewTouchListener != null){
result = gestureImageViewTouchListener.isZoomed();
}
return result;
}


In GestureImageViewTouchListener.java modify this...

private boolean isZoomed = false;

public boolean isZoomed() {
    return isZoomed;
}

public void setZoomed(boolean isZoomed) {
    this.isZoomed = isZoomed;
}

protected void handleScale(float scale, float x, float y) {

    currentScale = scale;

    if(currentScale > maxScale) {
        currentScale = maxScale;
        isZoomed = true;
    }
    else if (currentScale < minScale) {
        currentScale = minScale;
        isZoomed = false;
    }
    else {
        isZoomed = true;
        next.x = x;
        next.y = y;
    }

    calculateBoundaries();

    image.setScale(currentScale);
    image.setPosition(next.x, next.y);

    if(imageListener != null) {
        imageListener.onScale(currentScale);
        imageListener.onPosition(next.x, next.y);
    }

    image.redraw();
}

from gesture-imageview.

petar-bogdanov avatar petar-bogdanov commented on July 30, 2024

Thank you, that's very helpful.

from gesture-imageview.

soyangel avatar soyangel commented on July 30, 2024

Apart from changes you metioned I have assigned isZoomed here, and seems to work when zooming in/out with double tap:

In GestureImageViewTouchListener:

    zoomAnimation.setZoomAnimationListener(new ZoomAnimationListener() {
        @Override
        public void onZoom(float scale, float x, float y) {
            if(scale <= maxScale && scale >= minScale) {
                handleScale(scale, x, y);
            }
        }

        @Override
        public void onComplete() {
            inZoom = false;
            handleUp();
            isZoomed = zoomAnimation.getZoom() > 1.0;   // CHANGED LINE
        }
    });

from gesture-imageview.

yevon avatar yevon commented on July 30, 2024

I have been 2 week in holidays. I have just tried it, works perfect your fix! Thanks!

from gesture-imageview.

kirich1409 avatar kirich1409 commented on July 30, 2024

I solve problem with setting zoom after pinch.
Add string in GestureImageViewTouchListener

public boolean onTouch(View v, MotionEvent event)
{
if (!inZoom)
{
if (!tapDetector.onTouchEvent(event))
{...
if (event.getAction() == MotionEvent.ACTION_UP)
{
handleUp();
isZoomed = !(lastScale == startingScale); //NEW
}
...

from gesture-imageview.

brk3 avatar brk3 commented on July 30, 2024

If it helps anyone I've combined the various changes mentioned above and put them on this branch: https://github.com/brk3/gesture-imageview/compare/topic/issue-30-isZoomed (Don't have time to format a pull request right now, also the code uses tabs which is really annoying - I can't get my editor to match up properly.)

Update People struggling with this lib should check out PhotoView by Chris Banes. It handles ViewPager and fixes a lot of other issues I've been experiencing.

from gesture-imageview.

httpdispatch avatar httpdispatch commented on July 30, 2024

@brk3 thanks, i've created pull request based on your code modifications

from gesture-imageview.

longdw avatar longdw commented on July 30, 2024

Thanks all of you,your response solved my problem!!!

from gesture-imageview.

jonasasx avatar jonasasx commented on July 30, 2024

I've found out very interesting solution!

    @Override
    public boolean onTouch(View v, MotionEvent event) {
+       if (isZoomed())
+           image.getParent().requestDisallowInterceptTouchEvent(true);
+   private boolean zoomed;
+   public boolean isZoomed() {
+       return zoomed;
+   }
+   public void setZoomed(boolean zoomed) {
+       this.zoomed = zoomed;
+   }

and @kirich1409's:

    if (event.getAction() == MotionEvent.ACTION_UP) {
        handleUp();
+       this.zoomed = !(lastScale == startingScale);
    }

from gesture-imageview.

ipip2005 avatar ipip2005 commented on July 30, 2024

@jonasasx
Thank you for your advice and it almost worked out but
this line:
this.zoomed = !(lastScale == startingScale);
sometimes these two variables are not equal when the image was totally zoomed out
probably could change to:
zoomed = !(Math.abs(lastScale - startingScale) < 0.01);

from gesture-imageview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.