Example usage for com.google.gwt.dom.client Touch getPageY

List of usage examples for com.google.gwt.dom.client Touch getPageY

Introduction

In this page you can find the example usage for com.google.gwt.dom.client Touch getPageY.

Prototype

public final int getPageY() 

Source Link

Document

Gets the touch y-position within the browser document.

Usage

From source file:ca.wimsc.client.common.widgets.google.Scroller.java

License:Apache License

/**
 * The object has been dragged to a new position.
 * /*from   w  w w. j  a  v a  2 s. com*/
 * @param e
 *            The touchmove event.
 */
@Override
public void onDragMove(TouchEvent e) {
    com.google.gwt.dom.client.Touch touch = TouchHandler.getTouchFromEvent(e);
    Point touchCoord = new Point(touch.getPageX(), touch.getPageY());

    assert touchStartPosition != null : "Touch start not set";
    assert contentStartOffset != null : "Content start not set";

    Point touchStart = touchStartPosition;
    Point contentStart = contentStartOffset;

    Point diffXY = touchCoord.minus(touchStart);
    Point newXY = contentStart.plus(diffXY);

    // If they are dragging beyond bounds of frame then we will start
    // backing off on the effect of their drag.
    newXY.y = adjustValue(newXY.y, minPoint.y);

    // If horizontal scrolling is enabled and the content is wider than
    // the frame, then we should calculate a new X position.
    if (shouldScrollHorizontally()) {
        newXY.x = adjustValue(newXY.x, minPoint.x);
    } else {
        newXY.x = 0;
    }

    setContentOffset(newXY.x, newXY.y);
}

From source file:ca.wimsc.client.common.widgets.google.Scroller.java

License:Apache License

/**
 * Touch has begun on the scrollable area. Prepare the scrollable area for possible movement.
 * //from ww w  .j  av  a 2s.c o m
 * @param e
 *            The touchstart event.
 * @return True if the object is eligible for dragging.
 */
@Override
public boolean onTouchStart(TouchEvent e) {
    reconfigure();
    Touch touch = TouchHandler.getTouchFromEvent(e);

    // Save the initial position of touch and content.
    touchStartPosition = new Point(touch.getPageX(), touch.getPageY());
    contentStartOffset = new Point(contentOffset);

    // If the content is currently decelerating then we should stop it
    // immediately.
    momentum.stop();

    // Content should be snapped back in to place at this point if it is
    // currently
    // offset.
    snapContentOffsetToBounds();

    // Returning true here indicates that we are accepting a drag sequence.
    return true;
}

From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java

License:Apache License

/**
 * Touch end handler./*from   w  w  w.ja v a 2s .c o m*/
 *
 * @param e The touchend event.
 */
private void onEnd(TouchEvent e) {
    touching = false;
    if (touchDelegate != null) {
        touchDelegate.onTouchEnd(e);
    }

    if (!tracking || dragDelegate == null) {
        return;
    }

    com.google.gwt.dom.client.Touch touch = getLastTouch();
    Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY());

    if (dragging) {
        endTime = e.getTimeStamp();
        endTouchPosition = touchCoordinate;
        dragDelegate.onDragEnd(e);

        if ((Math.abs(endTouchPosition.x - startTouchPosition.x) > CLICK_BUST_THRESHOLD)
                || (Math.abs(endTouchPosition.y - startTouchPosition.y) > CLICK_BUST_THRESHOLD)) {
            bustNextClick = true;
        }
    }

    endTracking();
}

From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java

License:Apache License

/**
 * Touch move handler./*  ww  w .j a v a2  s.c o m*/
 *
 * @param e The touchmove event.
 */
@SuppressWarnings("unused")
private void onMove(final TouchEvent e) {
    if (!tracking || dragDelegate == null) {
        return;
    }

    // Prevent native scrolling.
    e.preventDefault();

    com.google.gwt.dom.client.Touch touch = getTouchFromEvent(e);
    Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY());

    double moveX = lastTouchPosition.x - touchCoordinate.x;
    double moveY = lastTouchPosition.y - touchCoordinate.y;
    totalMoveX += Math.abs(moveX);
    totalMoveY += Math.abs(moveY);
    lastTouchPosition.x = touchCoordinate.x;
    lastTouchPosition.y = touchCoordinate.y;

    // Handle case where they are getting close to leaving the window.
    // End events are unreliable when the touch is leaving the viewport area.
    // If they are close to the bottom or the right, and we don't get any other
    // touch events for another 100ms, assume they have left the screen. This
    // does not seem to be a problem for scrolling off the top or left of the
    // viewport area.
    if (scrollOffTimer != null) {
        scrollOffTimer.cancel();
    }
    if ((Window.getClientHeight() - touchCoordinate.y) < TOUCH_END_WORKAROUND_THRESHOLD
            || (Window.getClientWidth() - touchCoordinate.x) < TOUCH_END_WORKAROUND_THRESHOLD) {

        scrollOffTimer = new Timer() {
            @Override
            public void run() {
                e.setTimeStamp(Duration.currentTimeMillis());
                onEnd(e);
            }
        };
        scrollOffTimer.schedule(100);
    }

    boolean firstDrag = false;
    if (!dragging) {
        if (totalMoveY > MIN_TRACKING_FOR_DRAG || totalMoveX > MIN_TRACKING_FOR_DRAG) {
            dragging = true;
            firstDrag = true;
            dragDelegate.onDragStart(e);
        }
    }

    if (dragging) {
        dragDelegate.onDragMove(e);

        lastEvent = e;

        // This happens when they are dragging slowly. If they are dragging slowly
        // then we should reset the start time and position to where they are now.
        // This will be important during the drag end when we report to the
        // draggable delegate what kind of drag just happened.
        if (e.getTimeStamp() - recentTime > MAX_TRACKING_TIME) {
            recentTime = e.getTimeStamp();
            recentTouchPosition = touchCoordinate;
        }
    }
}

From source file:ca.wimsc.client.common.widgets.google.TouchHandler.java

License:Apache License

/**
 * Touch start handler./*from   w w w.j  a v a 2s  . c o  m*/
 *
 * @param e The touchstart event.
 * @private
 */
private void onStart(TouchEvent e) {
    // Ignore the touch if it is manufactured or if there is already a
    // touch happening.
    if (touching) {
        return;
    }

    touching = true;

    com.google.gwt.dom.client.Touch touch = getTouchFromEvent(e);
    Point touchCoordinate = new Point(touch.getPageX(), touch.getPageY());

    // Do not start tracking if...
    // - we already are tracking
    // - the touchable delegate refuses to accept the start event at this time
    // - there is no draggable delegate
    if ((dragDelegate == null) || ((touchDelegate != null) && !touchDelegate.onTouchStart(e))) {
        return;
    }

    startTouchPosition = touchCoordinate;
    recentTouchPosition = touchCoordinate;
    recentTime = e.getTimeStamp();
    lastEvent = e;
    lastTouchPosition = new Point(touchCoordinate);

    beginTracking();
}

From source file:com.appkit.ui.client.events.recognizer.longtap.LongTapRecognizer.java

License:Apache License

@Override
public void onTouchMove(TouchMoveEvent event) {
    switch (state) {
    case WAITING:
    case FINGERS_DOWN:
    case FINGERS_UP:
        // compare positions
        JsArray<Touch> currentTouches = event.getTouches();
        for (int i = 0; i < currentTouches.length(); i++) {
            Touch currentTouch = currentTouches.get(i);
            for (int j = 0; j < startPositions.length(); j++) {
                TouchCopy startTouch = startPositions.get(j);
                if (currentTouch.getIdentifier() == startTouch.getIdentifier()) {
                    if (Math.abs(currentTouch.getPageX() - startTouch.getPageX()) > distance
                            || Math.abs(currentTouch.getPageY() - startTouch.getPageY()) > distance) {
                        state = State.INVALID;
                        break;
                    }/*from   w w w  .j  a v  a 2 s .  c o m*/
                }
                if (state == State.INVALID) {
                    break;
                }
            }
        }

        break;

    default:
        state = State.INVALID;
        break;
    }
}

From source file:com.appkit.ui.client.events.recognizer.pinch.PinchRecognizer.java

License:Apache License

@Override
public void onTouchMove(TouchMoveEvent event) {
    switch (state) {
    case TWO_FINGER:

        Touch touch1 = event.getTouches().get(0);
        Touch touch2 = event.getTouches().get(1);

        int left = offsetProvider.getLeft();
        int top = offsetProvider.getTop();

        int x1 = touch1.getPageX() - left;
        int y1 = touch1.getPageY() - top;
        int x2 = touch2.getPageX() - left;
        int y2 = touch2.getPageY() - top;

        double newDistance = Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
        int x = (x1 + x2) / 2;
        int y = (y1 + y2) / 2;

        getEventPropagator().fireEvent(source, new PinchEvent(x, y, distance / newDistance));
        distance = newDistance;/*  ww  w.j  a  v  a2  s .co m*/

        break;

    default:
        state = State.INVALID;
        break;
    }
}

From source file:com.appkit.ui.client.events.recognizer.swipe.SwipeRecognizer.java

License:Apache License

@Override
public void onTouchMove(TouchMoveEvent event) {
    Touch touch = event.getTouches().get(0);

    switch (state) {
    case INVALID:

        break;//w  w  w.  ja v  a2  s  .  c o  m
    case READY:
        // WTF?
        state = State.INVALID;
        break;
    case FINDER_DOWN:

        // log(" X: " + touch.getPageX() + " old: " + touchStart.getPageX() + " test: " + x);

        if (Math.abs(touch.getPageX() - x) >= threshold) {
            state = State.FOUND_DIRECTION;

            direction = touch.getPageX() - x > 0 ? SwipeEvent.DIRECTION.LEFT_TO_RIGHT
                    : SwipeEvent.DIRECTION.RIGHT_TO_LEFT;

            SwipeStartEvent swipeStartEvent = new SwipeStartEvent(TouchCopy.copy(touch), touch.getPageX() - x,
                    direction);

            getEventPropagator().fireEvent(source, swipeStartEvent);

        } else {
            if (Math.abs(touch.getPageY() - y) >= threshold) {
                state = State.FOUND_DIRECTION;

                direction = touch.getPageY() - y > 0 ? SwipeEvent.DIRECTION.TOP_TO_BOTTOM
                        : SwipeEvent.DIRECTION.BOTTOM_TO_TOP;

                SwipeStartEvent swipeStartEvent = new SwipeStartEvent(TouchCopy.copy(touch),
                        touch.getPageY() - y, direction);

                getEventPropagator().fireEvent(source, swipeStartEvent);

            }

        }
        break;

    case FOUND_DIRECTION:

        switch (direction) {
        case TOP_TO_BOTTOM:
        case BOTTOM_TO_TOP:
            lastDistance = Math.abs(touch.getPageY() - y);
            getEventPropagator().fireEvent(source, new SwipeMoveEvent(TouchCopy.copy(touch),
                    lastDistance > minDistance, lastDistance, direction));
            break;

        case LEFT_TO_RIGHT:
        case RIGHT_TO_LEFT:
            lastDistance = Math.abs(touch.getPageX() - x);
            getEventPropagator().fireEvent(source, new SwipeMoveEvent(TouchCopy.copy(touch),
                    lastDistance > minDistance, lastDistance, direction));

            break;

        default:
            break;
        }

        break;

    default:
        break;
    }
}

From source file:com.appkit.ui.client.events.recognizer.TapRecognizer.java

License:Apache License

@Override
public void onTouchMove(TouchMoveEvent event) {
    Touch touch = event.getTouches().get(0);
    if (Math.abs(touch.getPageX() - start_x) > distance || Math.abs(touch.getPageY() - start_y) > distance) {
        hasMoved = true;/* w  w w.  j  ava2s.c o m*/
    }
}

From source file:com.appkit.ui.client.events.touch.TouchCopy.java

License:Apache License

public static TouchCopy copy(Touch touch) {
    return new TouchCopy(touch.getPageX(), touch.getPageY(), touch.getIdentifier());
}