本文整理匯總了Java中android.view.MotionEvent.getX方法的典型用法代碼示例。如果您正苦於以下問題:Java MotionEvent.getX方法的具體用法?Java MotionEvent.getX怎麽用?Java MotionEvent.getX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getX方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int x = (int) ev.getX();
int y = (int) ev.getY();
int action = ev.getAction();
if (action == MotionEvent.ACTION_DOWN) {
mLastX = x;
mLastY = y;
if (!mScroller.isFinished()) {
mScroller.abortAnimation();
return true;
}
return false;
} else {
return true;
}
}
示例2: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
x = event.getRawX();
y = event.getRawY();
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
touchX = event.getX();
touchY = event.getY();
break;
case MotionEvent.ACTION_MOVE:
if (dragEnabled) {
updateViewPostion();
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
touchX = touchY = 0;
dragEnabled = false;
break;
default:
break;
}
return super.onTouchEvent(event);
}
示例3: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
if (mClearDrawable != null && event.getAction() == MotionEvent.ACTION_UP) {
int x = (int) event.getX();
// 判斷觸摸點是否在水平範圍內
boolean isInnerWidth = (x > (getWidth() - getTotalPaddingRight()))
&& (x < (getWidth() - getPaddingRight()));
// 獲取刪除圖標的邊界,返回一個Rect對象
Rect rect = mClearDrawable.getBounds();
// 獲取刪除圖標的高度
int height = rect.height();
int y = (int) event.getY();
// 計算圖標底部到控件底部的距離
int distance = (getHeight() - height) / 2;
// 判斷觸摸點是否在豎直範圍內(可能會有點誤差)
// 觸摸點的縱坐標在distance到(distance+圖標自身的高度)之內,則視為點中刪除圖標
boolean isInnerHeight = (y > distance) && (y < (distance + height));
if (isInnerHeight && isInnerWidth) {
this.setText("");
}
}
return super.onTouchEvent(event);
}
示例4: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getX();
float y = event.getY();
switch (event.getAction()) {
case MotionEvent.ACTION_MOVE:
float dx = x - previousX;
float dy = y - previousY;
if (y > getHeight() / 2) {
dx = dx * -1;
}
if (x < getWidth() / 2) {
dy = dy * -1;
}
render.setAngle(render.getAngle() + (dx + dy) * TOUCH_SCALE_FACTOR);
requestRender();
}
previousX = x;
previousY = y;
return true;
}
示例5: onFling
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
float distanceX = e2.getX() - e1.getX();
float distanceY = e2.getY() - e1.getY();
if (Math.abs(distanceX) > Math.abs(distanceY) && Math.abs(distanceX) > SWIPE_DISTANCE_THRESHOLD
&& Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (distanceX > 0)
onSwipeRight();
else
onSwipeLeft();
return true;
}
else if (Math.abs(distanceY) > SWIPE_DISTANCE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
onSwipeTop();
}
return false;
}
示例6: updateDragging
import android.view.MotionEvent; //導入方法依賴的package包/類
private void updateDragging(MotionEvent ev) {
setHotspot(ev.getX(), ev.getY());
int x = (int) ev.getX();
Rect oldBounds = mThumb.getBounds();
int halfThumb = oldBounds.width() / 2;
int addedThumb = mAddedTouchBounds;
int newX = x - mDragOffset + halfThumb;
int left = getPaddingLeft() + halfThumb + addedThumb;
int right = getWidth() - (getPaddingRight() + halfThumb + addedThumb);
if (newX < left) {
newX = left;
} else if (newX > right) {
newX = right;
}
int available = right - left;
float scale = (float) (newX - left) / (float) available;
if (isRtl()) {
scale = 1f - scale;
}
int progress = Math.round((scale * (mMax - mMin)) + mMin);
setProgress(progress, true);
}
示例7: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
switch (action & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
final int pointerId = ev.getPointerId(pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = ev.getPointerId(newPointerIndex);
mLastTouchX = ev.getX(newPointerIndex);
mLastTouchY = ev.getY(newPointerIndex);
}
break;
}
mActivePointerIndex = ev.findPointerIndex(mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
return super.onTouchEvent(ev);
}
示例8: onTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onTouchEvent(MotionEvent event) {
PointF current = new PointF(event.getX(), event.getY());
String action = "";
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
action = "ACTION_DOWN";
//reset drawing state
mCurrentBox = new Box(current);
mBoxen.add(mCurrentBox);
break;
case MotionEvent.ACTION_MOVE:
action = "ACTION_MOVE";
if (null != mCurrentBox){
mCurrentBox.setCurrent(current);
invalidate();
}
break;
case MotionEvent.ACTION_UP:
action = "ACTION_UP";
mCurrentBox = null;
break;
case MotionEvent.ACTION_CANCEL:
action = "ACTION_CANCEL";
mCurrentBox = null;
break;
}
Log.i(TAG, action + "at x=" + current.x + ", y=" + current.y);
return true;
}
示例9: handleActionDown
import android.view.MotionEvent; //導入方法依賴的package包/類
private void handleActionDown(MotionEvent event) {
resetPattern();
final float x = event.getX();
final float y = event.getY();
final Cell hitCell = detectAndAddHit(x, y);
if (hitCell != null) {
mPatternInProgress = true;
mPatternDisplayMode = DisplayMode.Correct;
notifyPatternStarted();
} else if (mPatternInProgress) {
mPatternInProgress = false;
notifyPatternCleared();
}
if (hitCell != null) {
final float startX = getCenterXForColumn(hitCell.column);
final float startY = getCenterYForRow(hitCell.row);
final float widthOffset = mSquareWidth / 2f;
final float heightOffset = mSquareHeight / 2f;
invalidate((int) (startX - widthOffset),
(int) (startY - heightOffset),
(int) (startX + widthOffset), (int) (startY + heightOffset));
}
mInProgressX = x;
mInProgressY = y;
if (PROFILE_DRAWING) {
if (!mDrawingProfilingStarted) {
Debug.startMethodTracing("LockPatternDrawing");
mDrawingProfilingStarted = true;
}
}
}
示例10: onFling
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
} else {
if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeDown();
} else {
onSwipeUp();
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return false;
}
示例11: startDragging
import android.view.MotionEvent; //導入方法依賴的package包/類
private boolean startDragging(MotionEvent ev, boolean ignoreTrackIfInScrollContainer) {
final Rect bounds = mTempRect;
mThumb.copyBounds(bounds);
//Grow the current thumb rect for a bigger touch area
bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
mIsDragging = (bounds.contains((int) ev.getX(), (int) ev.getY()));
if (!mIsDragging && mAllowTrackClick && !ignoreTrackIfInScrollContainer) {
//If the user clicked outside the thumb, we compute the current position
//and force an immediate drag to it.
mIsDragging = true;
mDragOffset = (bounds.width() / 2) - mAddedTouchBounds;
updateDragging(ev);
//As the thumb may have moved, get the bounds again
mThumb.copyBounds(bounds);
bounds.inset(-mAddedTouchBounds, -mAddedTouchBounds);
}
if (mIsDragging) {
setPressed(true);
attemptClaimDrag();
setHotspot(ev.getX(), ev.getY());
mDragOffset = (int) (ev.getX() - bounds.left - mAddedTouchBounds);
if (mPublicChangeListener != null) {
mPublicChangeListener.onStartTrackingTouch(this);
}
}
return mIsDragging;
}
示例12: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
// 記錄手指按下的位置
startY = ev.getY();
startX = ev.getX();
// 初始化標記
mIsVpDragger = false;
break;
case MotionEvent.ACTION_MOVE:
// 如果viewpager正在拖拽中,那麽不攔截它的事件,直接return false;
if (mIsVpDragger) {
return false;
}
// 獲取當前手指位置
float endY = ev.getY();
float endX = ev.getX();
float distanceX = Math.abs(endX - startX);
float distanceY = Math.abs(endY - startY);
// 如果X軸位移大於Y軸位移,那麽將事件交給viewPager處理。
if (distanceX > mTouchSlop && distanceX > distanceY) {
mIsVpDragger = true;
return false;
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
// 初始化標記
mIsVpDragger = false;
break;
}
// 如果是Y軸位移大於X軸,事件交給swipeRefreshLayout處理。
return super.onInterceptTouchEvent(ev);
}
示例13: onTouchBeyondarView
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public void onTouchBeyondarView(MotionEvent event, ArBeyondarGLSurfaceView var2) {
float x = event.getX();
float y = event.getY();
ArrayList<BeyondarObject> geoObjects = new ArrayList<BeyondarObject>();
// This method call is better to don't do it in the UI thread!
// This method is also available in the BeyondarFragment
var2.getBeyondarObjectsOnScreenCoordinates(x, y, geoObjects);
String textEvent = "";
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
textEvent = "Event type ACTION_DOWN: ";
break;
case MotionEvent.ACTION_UP:
textEvent = "Event type ACTION_UP: ";
break;
case MotionEvent.ACTION_MOVE:
textEvent = "Event type ACTION_MOVE: ";
break;
default:
break;
}
Iterator<BeyondarObject> iterator = geoObjects.iterator();
while (iterator.hasNext()) {
BeyondarObject geoObject = iterator.next();
textEvent = textEvent + " " + geoObject.getName();
Log.d(TAG, "onTouchBeyondarView: ATTENTION !!! "+textEvent);
// ...
// Do something
// ...
}
}
示例14: onInterceptTouchEvent
import android.view.MotionEvent; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
if (!mSwipeEnabled) {
return false;
}
final float x = event.getX();
final float y = event.getY();
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mSwipeVertically = false;
mStartX = x;
mStartY = y;
} else if (!mSwipeVertically) {
final float dx = Math.abs(mStartX - x);
final float dy = Math.abs(mStartY - y);
mSwipeVertically = dy > mDragHelper.getTouchSlop() && dy > 1.5 * dx;
}
if (mSwipeVertically) {
return false;
} else {
try {
return mDragHelper.shouldInterceptTouchEvent(event);
} catch (Exception e) {
return false;
}
}
}
示例15: actionDown
import android.view.MotionEvent; //導入方法依賴的package包/類
private void actionDown(MotionEvent event) {
removeCallbacks(hideIndicator);
mLastScrollY = mScrollY;
mDownX = event.getX();
mDownY = event.getY();
if (mFlingAnimator != null) {
mFlingAnimator.cancel();
mFlingAnimator = null;
}
setUserTouch(true);
}