本文整理匯總了Java中android.view.MotionEvent.offsetLocation方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.offsetLocation方法的具體用法?Java MotionEvent.offsetLocation怎麽用?Java MotionEvent.offsetLocation使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.offsetLocation方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: transformMotionEventToGlobal
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* Recursive helper method that applies transformations in pre-order.
*
* @param ev the on-screen motion event
*/
private static void transformMotionEventToGlobal(@NonNull View view, @NonNull MotionEvent ev) {
Matrix matrix = view.getMatrix();
if (matrix != null) {
ev.transform(matrix);
}
ev.offsetLocation(view.getLeft(), view.getTop());
final ViewParent parent = view.getParent();
if (parent instanceof View) {
final View vp = (View) parent;
ev.offsetLocation(-vp.getScrollX(), -vp.getScrollY());
transformMotionEventToGlobal(vp, ev);
} // TODO: Use reflections to access ViewRootImpl
// else if (parent instanceof ViewRootImpl) {
// final ViewRootImpl vr = (ViewRootImpl) parent;
// ev.offsetLocation(0, -vr.mCurScrollY);
// }
}
示例2: canLoadmore
import android.view.MotionEvent; //導入方法依賴的package包/類
public static boolean canLoadmore(View targetView, MotionEvent event) {
if (!canScrollDown(targetView) && canScrollUp(targetView) && targetView.getVisibility() == View.VISIBLE) {
return true;
}
if (targetView instanceof ViewGroup && event != null) {
ViewGroup viewGroup = (ViewGroup) targetView;
final int childCount = viewGroup.getChildCount();
PointF point = new PointF();
for (int i = 0; i < childCount; i++) {
View child = viewGroup.getChildAt(i);
if (isTransformedTouchPointInView(viewGroup, child, event.getX(), event.getY(), point)) {
event = MotionEvent.obtain(event);
event.offsetLocation(point.x, point.y);
return canLoadmore(child, event);
}
}
}
return false;
}
示例3: findScrollableViewByEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
protected View findScrollableViewByEvent(View content, MotionEvent event, View orgScrollableView) {
if (content instanceof ViewGroup && event != null) {
ViewGroup viewGroup = (ViewGroup) content;
final int childCount = viewGroup.getChildCount();
PointF point = new PointF();
for (int i = childCount; i > 0; i--) {
View child = viewGroup.getChildAt(i - 1);
if (isTransformedTouchPointInView(viewGroup, child, event.getX(), event.getY(), point)) {
if (!(child instanceof ViewPager) && isScrollableView(child)) {
return child;
} else {
event = MotionEvent.obtain(event);
event.offsetLocation(point.x, point.y);
return findScrollableViewByEvent(child, event, orgScrollableView);
}
}
}
}
return orgScrollableView;
}
示例4: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
if(redirectTouchesToStickyView){
ev.offsetLocation(0, ((getScrollY() + stickyViewTopOffset) - getTopForViewRelativeOnlyChild(currentlyStickingView)));
}
if(ev.getAction()==MotionEvent.ACTION_DOWN){
hasNotDoneActionDown = false;
}
if(hasNotDoneActionDown){
MotionEvent down = MotionEvent.obtain(ev);
down.setAction(MotionEvent.ACTION_DOWN);
super.onTouchEvent(down);
hasNotDoneActionDown = false;
}
if(ev.getAction()==MotionEvent.ACTION_UP || ev.getAction()==MotionEvent.ACTION_CANCEL){
hasNotDoneActionDown = true;
}
return super.onTouchEvent(ev);
}
示例5: onTouch
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
final int actionMasked = motionEvent.getActionMasked();
if (actionMasked == MotionEvent.ACTION_DOWN) {
if (view instanceof ViewGroup) {
mInitialTouchTarget = findNearestChild((ViewGroup) view,
(int) motionEvent.getX(), (int) motionEvent.getY());
} else {
mInitialTouchTarget = null;
}
}
final View child = mInitialTouchTarget;
if (child == null) {
return false;
}
final float offsetX = view.getScrollX() - child.getLeft();
final float offsetY = view.getScrollY() - child.getTop();
motionEvent.offsetLocation(offsetX, offsetY);
final boolean handled = child.dispatchTouchEvent(motionEvent);
motionEvent.offsetLocation(-offsetX, -offsetY);
if (actionMasked == MotionEvent.ACTION_UP
|| actionMasked == MotionEvent.ACTION_CANCEL) {
mInitialTouchTarget = null;
}
return handled;
}
示例6: canScrollUp
import android.view.MotionEvent; //導入方法依賴的package包/類
private static boolean canScrollUp(View targetView, MotionEvent event) {
if (canScrollUp(targetView)) {
return true;
}
if (targetView instanceof ViewGroup && event != null) {
ViewGroup viewGroup = (ViewGroup) targetView;
final int childCount = viewGroup.getChildCount();
PointF point = new PointF();
for (int i = 0; i < childCount; i++) {
View child = viewGroup.getChildAt(i);
if (isTransformedTouchPointInView(viewGroup,child, event.getX(), event.getY() , point)) {
event = MotionEvent.obtain(event);
event.offsetLocation(point.x, point.y);
return canScrollUp(child, event);
}
}
}
return false;
}
示例7: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(final MotionEvent event)
{
if (getX() != 0)
event.offsetLocation(-getX(), -getY());
DifferentTouchInput.touchInput.process(event);
if( DemoRenderer.mRatelimitTouchEvents )
{
limitEventRate(event);
}
return true;
}
示例8: onTouchEventInternal
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEventInternal(MotionEvent e) {
if (mActiveDelegate != null) {
if (mActiveDelegate.autoOffsetEvents()) {
e.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
}
return mActiveDelegate.onTouchEventInternal(e);
}
return false;
}
示例9: 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;
}
示例10: dispatchTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mStickyRect.contains(ev.getX(), ev.getY())) {
ev.offsetLocation(-mStickyRect.left, -mStickyRect.top);
return mStickyContainer.dispatchTouchEvent(ev);
} else {
return super.dispatchTouchEvent(ev);
}
}
示例11: toGlobalMotionEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
boolean toGlobalMotionEvent(@NonNull View view, @NonNull MotionEvent ev) {
final int[] windowPosition = getWindowPosition(view);
if (windowPosition == null) {
return false;
}
transformMotionEventToGlobal(view, ev);
ev.offsetLocation(windowPosition[0], windowPosition[1]);
return true;
}
示例12: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
/**
* @see android.view.ViewGroup#onInterceptTouchEvent(android.view.MotionEvent)
* @param event The {@link MotionEvent} that started the gesture to be evaluated.
* @param isKeyboardShowing Whether the keyboard is currently showing.
* @return Whether the filter is going to intercept events.
*/
public final boolean onInterceptTouchEvent(MotionEvent event, boolean isKeyboardShowing) {
MotionEvent sentEvent = event;
if (mAutoOffset && (mCurrentTouchOffsetX != 0 || mCurrentTouchOffsetY != 0)) {
sentEvent = MotionEvent.obtain(event);
sentEvent.offsetLocation(mCurrentTouchOffsetX, mCurrentTouchOffsetY);
}
boolean consumed = onInterceptTouchEventInternal(sentEvent, isKeyboardShowing);
if (sentEvent != event) sentEvent.recycle();
return consumed;
}
示例13: toLocalMotionEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
private boolean toLocalMotionEvent(View view, MotionEvent event) {
int[] loc = this.mTmpLocation;
view.getLocationOnScreen(loc);
event.offsetLocation((float) (-loc[0]), (float) (-loc[1]));
return true;
}
示例14: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean eventHandled = false;
final MotionEvent event = MotionEvent.obtain(ev);
final int action = event.getActionMasked();
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsetY = 0;
}
final int eventY = (int) event.getY();
event.offsetLocation(0, mNestedOffsetY);
switch (action) {
case MotionEvent.ACTION_MOVE:
int deltaY = mLastY - eventY;
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
mLastY = eventY - mScrollOffset[1];
event.offsetLocation(0, -mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
}
eventHandled = super.onTouchEvent(event);
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
event.offsetLocation(0, mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
mLastY -= mScrollOffset[1];
}
break;
case MotionEvent.ACTION_DOWN:
eventHandled = super.onTouchEvent(event);
mLastY = eventY;
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
eventHandled = super.onTouchEvent(event);
stopNestedScroll();
break;
default:
// We don't care about other touch events
}
return eventHandled;
}
示例15: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean returnValue = false;
MotionEvent event = MotionEvent.obtain(ev);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsetY = 0;
}
int eventY = (int) event.getY();
event.offsetLocation(0, mNestedOffsetY);
switch (action) {
case MotionEvent.ACTION_MOVE:
int deltaY = mLastY - eventY;
// NestedPreScroll
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
mLastY = eventY - mScrollOffset[1];
event.offsetLocation(0, -mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
}
returnValue = super.onTouchEvent(event);
// NestedScroll
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
event.offsetLocation(0, mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
mLastY -= mScrollOffset[1];
}
break;
case MotionEvent.ACTION_DOWN:
returnValue = super.onTouchEvent(event);
mLastY = eventY;
// start NestedScroll
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
returnValue = super.onTouchEvent(event);
// end NestedScroll
stopNestedScroll();
break;
}
return returnValue;
}