本文整理汇总了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);
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}