Example usage for android.view MotionEvent setLocation

List of usage examples for android.view MotionEvent setLocation

Introduction

In this page you can find the example usage for android.view MotionEvent setLocation.

Prototype

public final void setLocation(float x, float y) 

Source Link

Document

Set this event's location.

Usage

From source file:android.support.test.testapp.VerticalViewPager.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    event.setLocation(event.getY() * getWidth() / getHeight(), event.getX() * getHeight() / getWidth());
    return super.onTouchEvent(event);
}

From source file:com.bjgas.common.DirectionalViewPager.java

/**
 * Swaps the X and Y coordinates of your touch event
 *///from  w  w  w  .  j  a  va  2s. co m
@Override
public boolean onTouchEvent(MotionEvent ev) {
    // swap the x and y coords of the touch event
    ev.setLocation(ev.getY(), ev.getX());

    return super.onTouchEvent(ev);
}

From source file:com.android.deskclock.VerticalViewPager.java

private boolean verticalDrag(MotionEvent ev) {
    final float x = ev.getX();
    final float y = ev.getY();
    ev.setLocation(y, x);
    return super.onTouchEvent(ev);
}

From source file:com.awen.codebase.ui.VerticalViewPager.java

private MotionEvent swapXY(MotionEvent ev) {
    float width = getWidth();
    float height = getHeight();

    float newX = (ev.getY() / height) * width;
    float newY = (ev.getX() / width) * height;

    ev.setLocation(newX, newY);

    return ev;/*from  www.jav a 2 s. c  om*/
}

From source file:com.android.wneng.widget.vertcalViewPager.VerticalViewPager.java

private MotionEvent swapTouchEvent(MotionEvent event) {
    float width = getWidth();
    float height = getHeight();

    float swappedX = (event.getY() / height) * width;
    float swappedY = (event.getX() / width) * height;

    event.setLocation(swappedX, swappedY);

    return event;
}

From source file:com.lixplor.fastcustomview.VerticalViewPager.java

/**
 * Swaps the X and Y coordinates of your touch event.
 *///w ww.  ja  va  2s . c  om
private MotionEvent swapXY(MotionEvent ev) {
    float width = getWidth();
    float height = getHeight();

    float newX = (ev.getY() / height) * width;
    float newY = (ev.getX() / width) * height;

    ev.setLocation(newX, newY);

    return ev;
}

From source file:com.androidinspain.deskclock.VerticalViewPager.java

private MotionEvent flipXY(MotionEvent ev) {
    final float width = getWidth();
    final float height = getHeight();

    final float x = (ev.getY() / height) * width;
    final float y = (ev.getX() / width) * height;

    ev.setLocation(x, y);

    return ev;/*from  w  w w  . ja v a2s .com*/
}

From source file:org.wikipedia.page.bottomcontent.BottomContentHandler.java

public BottomContentHandler(PageViewFragmentInternal parentFragment, CommunicationBridge bridge,
        ObservableWebView webview, LinkHandler linkHandler, ViewGroup hidingView, PageTitle pageTitle) {
    this.parentFragment = parentFragment;
    this.bridge = bridge;
    this.webView = webview;
    this.linkHandler = linkHandler;
    this.pageTitle = pageTitle;
    activity = parentFragment.getActivity();
    app = (WikipediaApp) activity.getApplicationContext();
    displayDensity = activity.getResources().getDisplayMetrics().density;

    bottomContentContainer = hidingView;
    webview.addOnScrollChangeListener(this);
    webview.addOnContentHeightChangedListener(this);

    pageLastUpdatedText = (TextView) bottomContentContainer.findViewById(R.id.page_last_updated_text);
    pageLicenseText = (TextView) bottomContentContainer.findViewById(R.id.page_license_text);
    readMoreContainer = bottomContentContainer.findViewById(R.id.read_more_container);
    readMoreList = (ListView) bottomContentContainer.findViewById(R.id.read_more_list);

    // set up pass-through scroll functionality for the ListView
    readMoreList.setOnTouchListener(new View.OnTouchListener() {
        private int touchSlop = ViewConfiguration.get(readMoreList.getContext()).getScaledTouchSlop();
        private boolean slopReached;
        private boolean doingSlopEvent;
        private boolean isPressed = false;
        private float startY;
        private float amountScrolled;

        @Override//  w  ww.j  a va 2s  . c  o  m
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getActionMasked() & MotionEvent.ACTION_MASK;
            switch (action) {
            case MotionEvent.ACTION_DOWN:
                isPressed = true;
                startY = event.getY();
                amountScrolled = 0;
                slopReached = false;
                break;
            case MotionEvent.ACTION_MOVE:
                if (isPressed && !doingSlopEvent) {
                    int contentHeight = (int) (webView.getContentHeight() * displayDensity);
                    int maxScroll = contentHeight - webView.getScrollY() - webView.getHeight();
                    int scrollAmount = Math.min((int) (startY - event.getY()), maxScroll);
                    // manually scroll the WebView that's underneath us...
                    webView.scrollBy(0, scrollAmount);
                    amountScrolled += scrollAmount;
                    if (Math.abs(amountScrolled) > touchSlop && !slopReached) {
                        slopReached = true;
                        // send an artificial Move event that scrolls it by an amount
                        // that's greater than the touch slop, so that the currently
                        // highlighted item is unselected.
                        MotionEvent moveEvent = MotionEvent.obtain(event);
                        moveEvent.setLocation(event.getX(), event.getY() + touchSlop * 2);
                        doingSlopEvent = true;
                        readMoreList.dispatchTouchEvent(moveEvent);
                        doingSlopEvent = false;
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL:
                isPressed = false;
                break;
            default:
                break;
            }
            return false;
        }
    });

    funnel = new SuggestedPagesFunnel(app, pageTitle.getSite());

    // preload the display density, since it will be used in a lot of places
    displayDensity = activity.getResources().getDisplayMetrics().density;
    // hide ourselves by default
    hide();
}

From source file:us.shandian.blacklight.ui.common.SwipeUpAndDownRefreshLayout.java

@Override
public boolean onTouchEvent(MotionEvent event) {
    boolean returningToStart = false;
    MotionEvent downEvent = null;
    try {//from www  .j  a v a2 s .c om
        returningToStart = Boolean.parseBoolean(mReturningToStart.get(this).toString());
        downEvent = (MotionEvent) mDownEvent.get(this);
    } catch (Exception e) {

    }

    boolean ret;

    if (event.getAction() == MotionEvent.ACTION_MOVE && downEvent != null && !returningToStart
            && !canChildScrollDown() && (mDownPriority || canChildScrollUp())) {
        downEvent.setLocation(downEvent.getX(), -downEvent.getY());
        event.setLocation(event.getX(), -event.getY());

        ret = super.onTouchEvent(event);

        downEvent.setLocation(downEvent.getX(), -downEvent.getY());
        event.setLocation(event.getX(), -event.getY());

        // Abandon the offset animation when swiping up
        try {
            mUpdateContentOffsetTop.invoke(this, -100);
        } catch (Exception e) {

        }

    } else {
        ret = super.onTouchEvent(event);
    }

    if (!canChildScrollDown()) {
        mIsDown = true;
    }

    if ((!mDownPriority || canChildScrollDown()) && !canChildScrollUp()) {
        mIsDown = false;
    }

    return ret;
}

From source file:com.github.crvv.wubinput.wubi.dictionary.suggestions.SuggestionStripView.java

@Override
public boolean onTouchEvent(final MotionEvent me) {
    // In the sliding input mode. {@link MotionEvent} should be forwarded to
    // {@link MoreSuggestionsView}.
    final int index = me.getActionIndex();
    final int x = mMoreSuggestionsView.translateX((int) me.getX(index));
    final int y = mMoreSuggestionsView.translateY((int) me.getY(index));
    me.setLocation(x, y);
    if (!mNeedsToTransformTouchEventToHoverEvent) {
        mMoreSuggestionsView.onTouchEvent(me);
        return true;
    }//  w  ww  . j a  v  a  2s  .  co  m
    // In sliding suggestion mode with accessibility mode on, a touch event should be
    // transformed to a hover event.
    final int width = mMoreSuggestionsView.getWidth();
    final int height = mMoreSuggestionsView.getHeight();
    final boolean onMoreSuggestions = (x >= 0 && x < width && y >= 0 && y < height);
    if (!onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Just drop this touch event because dispatching hover event isn't started yet and
        // the touch event isn't on {@link MoreSuggestionsView}.
        return true;
    }
    final int hoverAction;
    if (onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Transform this touch event to a hover enter event and start dispatching a hover
        // event to {@link MoreSuggestionsView}.
        mIsDispatchingHoverEventToMoreSuggestions = true;
        hoverAction = MotionEvent.ACTION_HOVER_ENTER;
    } else if (me.getActionMasked() == MotionEvent.ACTION_UP) {
        // Transform this touch event to a hover exit event and stop dispatching a hover event
        // after this.
        mIsDispatchingHoverEventToMoreSuggestions = false;
        mNeedsToTransformTouchEventToHoverEvent = false;
        hoverAction = MotionEvent.ACTION_HOVER_EXIT;
    } else {
        // Transform this touch event to a hover move event.
        hoverAction = MotionEvent.ACTION_HOVER_MOVE;
    }
    me.setAction(hoverAction);
    mMoreSuggestionsView.onHoverEvent(me);
    return true;
}