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