当前位置: 首页>>代码示例>>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;未经允许,请勿转载。