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


Java MotionEvent.getX方法代碼示例

本文整理匯總了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;
    }
}
 
開發者ID:DysaniazzZ,項目名稱:ArtOfAndroid,代碼行數:19,代碼來源:HorizontalScrollViewEx2.java

示例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);
}
 
開發者ID:treasure-lau,項目名稱:Linphone4Android,代碼行數:25,代碼來源:LinphoneOverlay.java

示例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);
}
 
開發者ID:lwd1815,項目名稱:Selector,代碼行數:25,代碼來源:OneKeyClearEditText.java

示例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;
}
 
開發者ID:FreeSunny,項目名稱:Amazing,代碼行數:25,代碼來源:MyGLSurfaceView.java

示例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;
}
 
開發者ID:JaeNuguid,項目名稱:Kids-Portal-Android,代碼行數:20,代碼來源:class_OnSwipeTouchListener_editText.java

示例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);
}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:24,代碼來源:DiscreteSeekBar.java

示例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);
}
 
開發者ID:liuke2016,項目名稱:filepicker,代碼行數:29,代碼來源:VersionedGestureDetector.java

示例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;
}
 
開發者ID:InnoFang,項目名稱:Android-Code-Demos,代碼行數:34,代碼來源:BoxDrawingView.java

示例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;
        }
    }
}
 
開發者ID:Dnet3,項目名稱:CustomAndroidOneSheeld,代碼行數:34,代碼來源:LockPatternViewEx.java

示例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;
}
 
開發者ID:micromasterandroid,項目名稱:androidadvanced,代碼行數:28,代碼來源:OnSwipeTouchListener.java

示例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;
}
 
開發者ID:dmllr,項目名稱:IdealMedia,代碼行數:28,代碼來源:DiscreteSeekBar.java

示例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);
}
 
開發者ID:crazysunj,項目名稱:CrazyDaily,代碼行數:38,代碼來源:VpSwipeRefreshLayout.java

示例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
        // ...
    }
}
 
開發者ID:KrishAmal,項目名稱:NavAR,代碼行數:39,代碼來源:PoiBrowserActivity.java

示例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;
    }
  }
}
 
開發者ID:seven332,項目名稱:conductor-attacher,代碼行數:30,代碼來源:SwipeBackLayout.java

示例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);
}
 
開發者ID:Zackratos,項目名稱:PureMusic,代碼行數:12,代碼來源:LyricView.java


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