當前位置: 首頁>>代碼示例>>Java>>正文


Java MotionEvent.setLocation方法代碼示例

本文整理匯總了Java中android.view.MotionEvent.setLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.setLocation方法的具體用法?Java MotionEvent.setLocation怎麽用?Java MotionEvent.setLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.view.MotionEvent的用法示例。


在下文中一共展示了MotionEvent.setLocation方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mTargets == null) return true;

    View selectedTarget = null;
    float selectedDistance = 0;
    // newX and newY are in the coordinates of the selectedTarget.
    float newX = 0;
    float newY = 0;
    for (View target : mTargets) {
        if (!target.isShown()) continue;

        mCachedTargetBounds.set(0, 0, target.getWidth(), target.getHeight());
        offsetDescendantRectToMyCoords(target, mCachedTargetBounds);
        float x = event.getX();
        float y = event.getY();
        float dx = distanceToRange(
                mCachedTargetBounds.left, mCachedTargetBounds.right, x);
        float dy = distanceToRange(
                mCachedTargetBounds.top, mCachedTargetBounds.bottom, y);
        float distance = Math.abs(dx) + Math.abs(dy);
        if (selectedTarget == null || distance < selectedDistance) {
            selectedTarget = target;
            selectedDistance = distance;
            newX = x + dx;
            newY = y + dy;
        }
    }

    if (selectedTarget == null) return false;

    event.setLocation(newX, newY);
    return selectedTarget.onTouchEvent(event);
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:35,代碼來源:LocationBarTablet.java

示例2: swapTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:UltraViewPagerView.java

示例3: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
/**
 * Will forward touch events to the delegate view if the event is within the bounds
 * specified in the constructor.
 *
 * @param event The touch event to forward
 * @return True if the event was forwarded to the delegate, false otherwise.
 */
public boolean onTouchEvent(MotionEvent event) {
    boolean sendToDelegate = false;
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mDelegateTargeted = mTouchCheckBounds.contains(event.getX(), event.getY());
            if (mDelegateTargeted) {
                mWasTouchOutsideBounds = !mBounds.contains(event.getX(), event.getY());
                sendToDelegate = true;
            }
            break;
        case MotionEvent.ACTION_MOVE:
            sendToDelegate = mDelegateTargeted;
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            sendToDelegate = mDelegateTargeted;
            mDelegateTargeted = false;
            break;
    }
    boolean handled = false;
    if (sendToDelegate) {
        float x = event.getX();
        float y = event.getY();
        if (mWasTouchOutsideBounds) {
            event.setLocation(mBounds.centerX(), mBounds.centerY());
        } else {
            event.offsetLocation(-mBounds.left, -mBounds.top);
        }
        handled = mDelegateView.dispatchTouchEvent(event);
        event.setLocation(x, y);
    }
    return handled;
}
 
開發者ID:enricocid,項目名稱:LaunchEnr,代碼行數:41,代碼來源:TransformingTouchDelegate.java

示例4: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    viewTouchPoint[0] = event.getX();
    viewTouchPoint[1] = event.getY();
    rotateMatrix.mapPoints(childTouchPoint, viewTouchPoint);
    event.setLocation(childTouchPoint[0], childTouchPoint[1]);
    boolean result = super.dispatchTouchEvent(event);
    event.setLocation(viewTouchPoint[0], viewTouchPoint[1]);
    return result;
}
 
開發者ID:suragch,項目名稱:mongol-library,代碼行數:11,代碼來源:RotatedViewGroup.java

示例5: swapTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
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;
}
 
開發者ID:smallsilver,項目名稱:VerticalWebView,代碼行數:11,代碼來源:VerticalViewPager.java

示例6: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
public boolean onTouchEvent(final int x, final int y, final MotionEvent me) {
    mReceiverView.getGlobalVisibleRect(mEventReceivingRect);
    // Translate global coordinates to <code>ReceiverView</code> local coordinates.
    me.setLocation(translateX(x), translateY(y));
    mReceiverView.dispatchTouchEvent(me);
    onForwardingEvent(me);
    return true;
}
 
開發者ID:rkkr,項目名稱:simple-keyboard,代碼行數:9,代碼來源:InputView.java

示例7: swapXY

import android.view.MotionEvent; //導入方法依賴的package包/類
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;
}
 
開發者ID:willowtreeapps,項目名稱:spruce-android,代碼行數:12,代碼來源:VerticalViewPager.java

示例8: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    mViewTouchPoint[0] = event.getX();
    mViewTouchPoint[1] = event.getY();

    mEventTransformMatrix.mapPoints(mChildTouchPoint, mViewTouchPoint);
    event.setLocation(mChildTouchPoint[0], mChildTouchPoint[1]);
    boolean result = super.dispatchTouchEvent(event);
    event.setLocation(mViewTouchPoint[0], mViewTouchPoint[1]);

    return result;
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:13,代碼來源:RotatedViewGroup.java

示例9: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
    updateSourcePartial();

    // The logic below is mostly copied from the parent class, since we
    // can't update private mBounds variable.

    // http://android.git.kernel.org/?p=platform/frameworks/base.git;a=blob;
    // f=core/java/android/view/TouchDelegate.java;hb=eclair#l98

    final Rect sourcePartial = mSourcePartial;
    final View target = mTarget;

    int x = (int)event.getX();
    int y = (int)event.getY();

    boolean sendToDelegate = false;
    boolean hit = true;
    boolean handled = false;

    switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
        if (sourcePartial.contains(x, y)) {
            mDelegateTargeted = true;
            sendToDelegate = true;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_MOVE:
        sendToDelegate = mDelegateTargeted;
        if (sendToDelegate) {
            if (!sourcePartial.contains(x, y)) {
                hit = false;
            }
        }
        break;
    case MotionEvent.ACTION_CANCEL:
        sendToDelegate = mDelegateTargeted;
        mDelegateTargeted = false;
        break;
    }

    if (sendToDelegate) {
        if (hit) {
            event.setLocation(target.getWidth() / 2, target.getHeight() / 2);
        } else {
            event.setLocation(-1, -1);
        }
        handled = target.dispatchTouchEvent(event);
    }
    return handled;
}
 
開發者ID:dreaminglion,項目名稱:iosched-reader,代碼行數:53,代碼來源:FractionalTouchDelegate.java

示例10: dispatchTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
  // Modify the touch events so that children receive scaled touch events
  ev.setLocation(ev.getX() * (1f / mScale), ev.getY() * (1f / mScale));
  super.dispatchTouchEvent(ev);
  return true;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:8,代碼來源:ScaledFrameLayout.java

示例11: swapXY

import android.view.MotionEvent; //導入方法依賴的package包/類
private MotionEvent swapXY(MotionEvent ev) {
        switch(ev.getAction())
        {
            case MotionEvent.ACTION_DOWN:
                x1 = ev.getX();
                y1=ev.getY();
                break;
            case MotionEvent.ACTION_UP:
                x2 = ev.getX();
                y2=ev.getY();

                float deltaX = x2 - x1;
                float deltaY = y2 - y1;

                if (Math.abs(deltaX) > MIN_DISTANCE)
                {
                    setPageTransformer(false, new VerticalPageTransformer());
                    flag=true;
                }

                if (Math.abs(deltaY) > MIN_DISTANCE)
                {
                    setPageTransformer(true, new VerticalPageTransformer());
                    flag=false;
                }
                break;
        }
//        return super.onTouchEvent(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;
    }
 
開發者ID:goutham-kalikrishna,項目名稱:ShotsNewsApp,代碼行數:41,代碼來源:VerticalViewPager.java

示例12: onTouchEvent

import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(final MotionEvent me) {
    if (!mMoreSuggestionsView.isShowingInParent()) {
        // Ignore any touch event while more suggestions panel hasn't been shown.
        // Detecting sliding up is done at {@link #onInterceptTouchEvent}.
        return true;
    }
    // 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;
    }
    // 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;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:48,代碼來源:SuggestionStripView.java


注:本文中的android.view.MotionEvent.setLocation方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。