开发者

Disabling onTap when using pinch to zoom

I have a map view which has overlay items on top of them. The overlay items have an action when they are taped on. The problem is when I use pinch to zoom if it my fingers happen to be at a location of an item when I l开发者_开发技巧ift them the onTap() is called. how could i prevent this?

Thanks, Jason


implement the motioneventListener instead of your current eventListener for your overlayItem and check the pointer count

@Override
public boolean onTouchEvent(final MotionEvent event)
{
    if(event.getPointerCount() == 1)
    { 
     // do onTap stuff 
    }
}


Here is the solution I got to in the end If it is any help to anyone:

    private static Method           GetPointCountMethod;
    private boolean                 mIsTouchMove    = false;

    private static boolean mTapable = true;

    static {
        // Check if the getPointerCount method is availabe (aka api level 5)
        try {
            GetPointCountMethod = MotionEvent.class.getMethod("getPointerCount");
            /* success, this is a newer device */
        }
        catch (NoSuchMethodException nsme) {
            /* failure, must be older device */
        }
    };

// Invoke the getPointCount Method if it exists
    private int getPointCount(MotionEvent event)
    {
        try {
            return (Integer) GetPointCountMethod.invoke(event);
        }
        catch (IllegalArgumentException e) {

            e.printStackTrace();
        }
        catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        return -1;
    }


    @Override
    public boolean dispatchTouchEvent(MotionEvent event)
    {
        // Set the tappable to be only when the map is realy just tapped and not moved or zoomed
        if (event.getAction() == MotionEvent.ACTION_UP) {
            if (GetPointCountMethod != null) {
                if (getPointCount(event) == 1) {

                    if (mIsTouchMove) {
                        mIsTouchMove = false;
                    }
                    else {
                        mTapable  = true;
                        // Finaly - a Tap! : 
                    }
                }
            }
        }
        else if (event.getAction() == MotionEvent.ACTION_MOVE) {
            mTapable  = (false);
            mIsTouchMove = true;
        }
        // let the rest do their job
        return super.dispatchTouchEvent(event);
    }

There is still no support for 1.6 and that is why this is still open ill wait to see if there is a way to do it also in 1.6

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜