当前位置: 首页>>代码示例>>Java>>正文


Java MotionEvent类代码示例

本文整理汇总了Java中android.view.MotionEvent的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent类的具体用法?Java MotionEvent怎么用?Java MotionEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


MotionEvent类属于android.view包,在下文中一共展示了MotionEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: move

import android.view.MotionEvent; //导入依赖的package包/类
private synchronized void move(MotionEvent event) {
    for (PinData item : pressedRects) {
        boolean pressed = false;
        for (int i = 0; i < (event.getPointerCount() > maxPointers ? maxPointers
                : event.getPointerCount()); i++) {
            if (item.rect
                    .contains((int) event.getX(i), (int) event.getY(i)))
                pressed = true;
        }
        if (!pressed) {
            if (item.key != null && item.key.eventListener != null)
                item.key.eventListener.onReleased(item.key);
            pressedRects.remove(item);
        }
    }
    for (int i = 0; i < (event.getPointerCount() > maxPointers ? maxPointers
            : event.getPointerCount()); i++) {
        down((int) event.getX(i), (int) event.getY(i));
    }
}
 
开发者ID:Dnet3,项目名称:CustomAndroidOneSheeld,代码行数:21,代码来源:MutitouchKeysContainer.java

示例2: beginFakeDrag

import android.view.MotionEvent; //导入依赖的package包/类
/**
 * Start a fake drag of the pager.
 *
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 *
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 *
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    mInitialMotionX = mLastMotionX = 0;
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    }
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}
 
开发者ID:benniaobuguai,项目名称:android-project-gallery,代码行数:37,代码来源:ViewPagerCompat.java

示例3: onScroll

import android.view.MotionEvent; //导入依赖的package包/类
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
		float distanceY) {
	MuPDFView pageView = (MuPDFView)getDisplayedView();
	switch (mMode) {
	case Viewing:
		if (!tapDisabled)
			onDocMotion();

		return super.onScroll(e1, e2, distanceX, distanceY);
	case Selecting:
		if (pageView != null)
			pageView.selectText(e1.getX(), e1.getY(), e2.getX(), e2.getY());
		return true;
	default:
		return true;
	}
}
 
开发者ID:ArtifexSoftware,项目名称:mupdf-android-viewer-old,代码行数:18,代码来源:MuPDFReaderView.java

示例4: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    int eventAction = event.getAction();
    int x = (int)event.getX();
    int y = (int)event.getY();
    switch (eventAction) {
        case MotionEvent.ACTION_DOWN:
            midpt.x = ((x*noOfTabs)/getWidth())*((getWidth()/noOfTabs)) + ((getWidth()/noOfTabs)/2);
            triangle.reset();
            break;
        case MotionEvent.ACTION_UP:
            break;
        case MotionEvent.ACTION_MOVE:
            break;
    }
    invalidate();
    return true;
}
 
开发者ID:Jhuku,项目名称:TriangularCustomView,代码行数:19,代码来源:IndicatorView.java

示例5: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {

    if(isDrawMode) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                touchMode = true;
                touchDown(event);
                if(onTouchListener != null) onTouchListener.onDown();
                break;
            case MotionEvent.ACTION_MOVE:
                touchMove(event);
                break;
            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_UP:
                touchMode = false;
                savePathList.add(new Path(mPath));
                paintList.add(new Paint(mPaint));
                if(onTouchListener != null) onTouchListener.onUp();
                if(onLineChangeListener != null) onLineChangeListener.onDrawLine(savePathList.size());
                break;
        }
        invalidate();
    }
    return isDrawMode;
}
 
开发者ID:Zhaoss,项目名称:WeiXinRecordedDemo,代码行数:27,代码来源:TuyaView.java

示例6: onDoubleTap

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onDoubleTap(MotionEvent ev) {
    if (photoViewAttacher == null)
        return false;

    try {
        float scale = photoViewAttacher.getScale();
        float x = ev.getX();
        float y = ev.getY();

        if (scale < photoViewAttacher.getMediumScale()) {
            photoViewAttacher.setScale(photoViewAttacher.getMediumScale(), x, y, true);
        } else if (scale >= photoViewAttacher.getMediumScale() && scale < photoViewAttacher.getMaximumScale()) {
            photoViewAttacher.setScale(photoViewAttacher.getMaximumScale(), x, y, true);
        } else {
            photoViewAttacher.setScale(photoViewAttacher.getMinimumScale(), x, y, true);
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        // Can sometimes happen when getX() and getY() is called
    }

    return true;
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:24,代码来源:DefaultOnDoubleTapListener.java

示例7: beginFakeDrag

import android.view.MotionEvent; //导入依赖的package包/类
/**
 * Start a fake drag of the pager.
 * <p/>
 * <p>A fake drag can be useful if you want to synchronize the motion of the ViewPager
 * with the touch scrolling of another view, while still letting the ViewPager
 * control the snapping motion and fling behavior. (e.g. parallax-scrolling tabs.)
 * Call {@link #fakeDragBy(float)} to simulate the actual drag motion. Call
 * {@link #endFakeDrag()} to complete the fake drag and fling as necessary.
 * <p/>
 * <p>During a fake drag the ViewPager will ignore all touch events. If a real drag
 * is already in progress, this method will return false.
 *
 * @return true if the fake drag began successfully, false if it could not be started.
 * @see #fakeDragBy(float)
 * @see #endFakeDrag()
 */
public boolean beginFakeDrag() {
    if (mIsBeingDragged) {
        return false;
    }
    mFakeDragging = true;
    setScrollState(SCROLL_STATE_DRAGGING);
    if (isHorizontalDirection()) {
        mInitialMotionX = mLastMotionX = 0;
    } else if (isVerticalDirection()) {
        mInitialMotionY = mLastMotionY = 0;
    }
    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    } else {
        mVelocityTracker.clear();
    }
    final long time = SystemClock.uptimeMillis();
    final MotionEvent ev = MotionEvent.obtain(time, time, MotionEvent.ACTION_DOWN, 0, 0, 0);
    mVelocityTracker.addMovement(ev);
    ev.recycle();
    mFakeDragBeginTime = time;
    return true;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:40,代码来源:BaseViewPager.java

示例8: dispatchTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    int action = ev.getAction();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mIsResumed = false;
        update();
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mIsResumed = true;
        update();
        break;
    }
    return super.dispatchTouchEvent(ev);
}
 
开发者ID:czy1121,项目名称:bannerview,代码行数:17,代码来源:BannerView.java

示例9: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);
    if (isBackToStart && action == MotionEvent.ACTION_DOWN) isBackToStart = false;
    switch (mType) {
        case BOTTOM:
            if (!isEnabled() || isBackToStart || canChildScrollDown() || isRefreshing) {
                return false;
            }
            break;
        case TOP:
        default:
            if (!isEnabled() || isBackToStart || canChildScrollUp() || isRefreshing) {
                return false;
            }
            break;
    }
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
            isReady = false;
            break;
        case MotionEvent.ACTION_MOVE:
            if (TouchActionMove(ev)) return false;
            break;
        case MotionEventCompat.ACTION_POINTER_DOWN:
            final int index = MotionEventCompat.getActionIndex(ev);
            mActivePointerId = MotionEventCompat.getPointerId(ev, index);
            break;
        case MotionEventCompat.ACTION_POINTER_UP:
            onSecondaryPointerUp(ev);
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL: {
            return TouchActionCancel(ev);
        }
    }
    return true;
}
 
开发者ID:shenhuanet,项目名称:AndroidOpen,代码行数:40,代码来源:SwipeToRefreshLayout.java

示例10: isInIgnoredView

import android.view.MotionEvent; //导入依赖的package包/类
private boolean isInIgnoredView(MotionEvent ev) {
	Rect rect = new Rect();
	for (View v : mIgnoredViews) {
		v.getHitRect(rect);
		if (rect.contains((int)ev.getX(), (int)ev.getY())) return true;
	}
	return false;
}
 
开发者ID:6ag,项目名称:LiuAGeAndroid,代码行数:9,代码来源:CustomViewAbove.java

示例11: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    // Detect when the user lifts their finger off the screen after a touch
    if (event.getAction() == MotionEvent.ACTION_UP) {
        // If not flinging then we are idle now. The user just finished a finger scroll.
        if (mFlingTracker == null || mFlingTracker.isFinished()) {
            setCurrentScrollState(OnScrollStateChangedListener.ScrollState.SCROLL_STATE_IDLE);
        }

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);

        releaseEdgeGlow();
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
        unpressTouchedChild();
        releaseEdgeGlow();

        // Allow the user to interact with parent views
        requestParentListViewToNotInterceptTouchEvents(false);
    }

    return super.onTouchEvent(event);
}
 
开发者ID:LanguidSheep,项目名称:sealtalk-android-master,代码行数:24,代码来源:HorizontalListView.java

示例12: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabled()) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            Log.d("Action down","Progress ="+progress);
        case MotionEvent.ACTION_MOVE:
            Log.d("Action move","Progress ="+progress);
        case MotionEvent.ACTION_UP:
            if(event.getY()<=getHeight() && event.getY()>=0) {
                progress = getMax() - (int) (getMax() * event.getY() / getHeight());
                Log.d("Action up", "Progress =" + progress);
                Log.d("GetMax Return", " " + getMax() + " getHeight " + getHeight() + " getY " + event.getY());
                this.setProgress(getMax() - (int) (getMax() * event.getY() / getHeight()));
            }
            onSizeChanged(getWidth(), getHeight(), 0, 0);
            break;

        case MotionEvent.ACTION_CANCEL:
            break;
    }
    return true;
}
 
开发者ID:mdnafiskhan,项目名称:Mp3Player,代码行数:27,代码来源:VerticalSeekBar.java

示例13: onInterceptTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    switch (ev.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mXDown = ev.getX();
        mYDown = ev.getY();
        mTouchDownTime = System.currentTimeMillis();
        break;
    case MotionEvent.ACTION_POINTER_UP:
    case MotionEvent.ACTION_UP:
        if (mTouchState == TOUCH_STATE_REST) {
            final CellLayout currentPage = (CellLayout) getChildAt(mCurrentPage);
            if (currentPage != null) {
                onWallpaperTap(ev);
            }
        }
    }
    return super.onInterceptTouchEvent(ev);
}
 
开发者ID:enricocid,项目名称:LaunchEnr,代码行数:20,代码来源:Workspace.java

示例14: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
	if(event.getAction() == MotionEvent.ACTION_DOWN)
	{
		down = true;
		return true;
	}
	if(event.getAction() == MotionEvent.ACTION_UP)
	{
		down = false;
		setSelectorPosition((int)event.getX() - getBackgroundOffset(), (int)event.getY() - getBackgroundOffset(), true);
		return true;
	}
	if(event.getAction() == MotionEvent.ACTION_MOVE && down)
	{
		setSelectorPosition((int)event.getX() - getBackgroundOffset(), (int)event.getY() - getBackgroundOffset(), false);
		return true;
	}
	return super.onTouchEvent(event);
}
 
开发者ID:pooyafaroka,项目名称:PlusGram,代码行数:21,代码来源:HsvColorValueView.java

示例15: onTouchEvent

import android.view.MotionEvent; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
    float x = event.getY();
    float y = event.getY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            onTouchDown(x, y);
            return true;
        case MotionEvent.ACTION_MOVE:
            onTouchMove(x, y);
            return true;
        case MotionEvent.ACTION_UP:
            onTouchUp(x, y);
            return true;
    }
    return super.onTouchEvent(event);
}
 
开发者ID:hyb1996,项目名称:Auto.js,代码行数:18,代码来源:PaintView.java


注:本文中的android.view.MotionEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。