本文整理汇总了Java中android.view.MotionEvent.getDownTime方法的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.getDownTime方法的具体用法?Java MotionEvent.getDownTime怎么用?Java MotionEvent.getDownTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.getDownTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onInterceptTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final long downTime = ev.getDownTime();
if (downTime != mLastTouchDownTime) {
mLastTouchDownTime = downTime;
if (interceptsTouchEvent(ev.getX(), ev.getY())) {
return true;
}
}
if (mOnInterceptTouchEventListener != null &&
mOnInterceptTouchEventListener.onInterceptTouchEvent(this, ev)) {
return true;
}
// We intercept the touch event if the children are not supposed to receive it.
if (mPointerEvents == PointerEvents.NONE || mPointerEvents == PointerEvents.BOX_ONLY) {
return true;
}
return super.onInterceptTouchEvent(ev);
}
示例2: sendMouseEventCode
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* Send a single mouse event code to the terminal.
*/
void sendMouseEventCode(MotionEvent e, int button, boolean pressed) {
int x = (int) (e.getX() / mRenderer.mFontWidth) + 1;
int y = (int) ((e.getY() - mRenderer.mFontLineSpacingAndAscent) / mRenderer.mFontLineSpacing) + 1;
if (pressed && (button == TerminalEmulator.MOUSE_WHEELDOWN_BUTTON || button == TerminalEmulator.MOUSE_WHEELUP_BUTTON)) {
if (mMouseStartDownTime == e.getDownTime()) {
x = mMouseScrollStartX;
y = mMouseScrollStartY;
} else {
mMouseStartDownTime = e.getDownTime();
mMouseScrollStartX = x;
mMouseScrollStartY = y;
}
}
mEmulator.sendMouseEvent(button, x, y, pressed);
}
示例3: isClickEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
private boolean isClickEvent(float startX, float startY, MotionEvent event) {
float duration = event.getEventTime() - event.getDownTime();
if (duration > MAX_CLICK_DURATION) {
return false;
}
float differenceX = Math.abs(startX - event.getX());
float differenceY = Math.abs(startY - event.getY());
return !(differenceX > MAX_CLICK_DISTANCE || differenceY > MAX_CLICK_DISTANCE);
}
示例4: onTouchMove
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public void onTouchMove(MotionEvent event) {
if (!hold && event.getEventTime() - event.getDownTime() >= holdDelay) {
hold = true;
onVibrate(100);
}
}
示例5: onTouchMoveMouseMove
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onTouchMoveMouseMove(MotionEvent event) {
if (holdPossible) {
if (getDistanceFromDown(event) > immobileDistance) {
holdPossible = false;
} else if (event.getEventTime() - event.getDownTime() > this.holdDelay) {
onMouseClick(MouseClickAction.STATE_DOWN, MouseClickAction.BUTTON_LEFT);
holdPossible = false;
setHold(true);
onVibrate(100);
}
}
float moveRawX = event.getRawX() - movePreviousX;
float moveRawY = event.getRawY() - movePreviousY;
moveRawX *= moveSensitivity;
moveRawY *= moveSensitivity;
moveRawX = (float) ((Math.pow(Math.abs(moveRawX), moveAcceleration) * Math.signum(moveRawX)));
moveRawY = (float) ((Math.pow(Math.abs(moveRawY), moveAcceleration) * Math.signum(moveRawY)));
moveRawX += moveResultX;
moveRawY += moveResultY;
int moveXFinal = Math.round(moveRawX);
int moveYFinal = Math.round(moveRawY);
if (moveXFinal != 0 || moveYFinal != 0) {
mouseMove(moveXFinal, moveYFinal);
}
moveResultX = moveRawX - moveXFinal;
moveResultY = moveRawY - moveYFinal;
movePreviousX = event.getRawX();
movePreviousY = event.getRawY();
}
示例6: handleDebugLayout
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* 多点按下, 是否处理
*/
protected boolean handleDebugLayout(MotionEvent ev) {
int actionMasked = ev.getActionMasked();
long downTime = ev.getDownTime();
if (actionMasked == MotionEvent.ACTION_DOWN) {
firstDownTime = downTime;
}
if (L.LOG_DEBUG &&
showDebugLayout &&
actionMasked == MotionEvent.ACTION_POINTER_DOWN &&
ev.getPointerCount() == 6) {
if (ev.getEventTime() - firstDownTime < 500) {
//快速三指按下才受理操作
//debug模式下, 三指按下
if (isInDebugLayout) {
closeDebugLayout();
} else {
startDebugLayout();
}
return true;
}
}
return false;
}
示例7: onDown
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onDown(MotionEvent e) {
if(DBG) Log.d(TAG, "onDown: stopScrollingAnim");
if (mAnimHandler.isSpeedScrollingAnimating()) {
mAnimHandler.stopScrollingAnimation();
// Remember down time stopping scrolling so that it is not used for onClick file opening
mThisOnDownMustNotOpen = e.getDownTime();
}
return true;
}
示例8: onSingleTapConfirmed
import android.view.MotionEvent; //导入方法依赖的package包/类
public boolean onSingleTapConfirmed(MotionEvent e) {
final int x=(int)e.getX();
final int y=(int)e.getY();
Log.d(TAG,"onSingleTapConfirmed " + x + " " + y);
// If the down event has been used to stop scrolling, it must not open the file
if (e.getDownTime() == mThisOnDownMustNotOpen) {
Log.d(TAG, "onSingleTapConfirmed: don't open item because view was scrolling!");
return true; // has been consumed to stop the scrolling
}
// Ask the 3D world coordinates to the GL thread.
// Will reply using the RendererListener
/* 2010-10-26 STOP with this crappy 3D picking for now...
queueEvent(new Runnable(){
public void run() {
mRenderer.click(x,y);
}});
*/ // Use a more basic hard-coded 2D operation instead:
// Ask the layout for a basic 2D pseudo-picking
Integer tappedCoverId = mLayout.getCoverIndexAtPosition(x, y);
if (tappedCoverId==null) {
if(DBG) Log.d(TAG,"Found no cover at the click point!");
return false;
}
// If the clicked cover is the front one, we open the browser
if (tappedCoverId.intValue() == mLayout.getFrontCoverIndex()) {
// Animations intent will be launched at the end of the click animation
mAnimHandler.startItemClickAnimation(tappedCoverId, getOpenAction(tappedCoverId), 0);
mAnimHandler.startBackgroundCoversFadeOutAnimation();
}
// If the clicked cover is not the front one, put it to front position
else {
float targetScroll = mLayout.getScrollingPositionToCenterThisCover(tappedCoverId);
mAnimHandler.startScrollingAnimPosition(targetScroll, AnimHandler.SPEED_FAST);
}
return true;
}
示例9: dispatchTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
int actionMasked = MotionEventCompat.getActionMasked(ev);
if (actionMasked == MotionEvent.ACTION_DOWN) {
isFling = false;
fastDownX = ev.getX();
fastDownY = ev.getY();
fastDownTime = ev.getDownTime();
if (enableScroll && isEnabled()) {
stopAutoScroll();
}
} else if (actionMasked == MotionEvent.ACTION_UP ||
actionMasked == MotionEvent.ACTION_CANCEL) {
if (actionMasked == MotionEvent.ACTION_UP &&
mOnFastTouchListener != null) {
long eventTime = ev.getEventTime();
int dv = 10;
if (eventTime - fastDownTime <= OnFastTouchListener.FAST_TIME) {
float x = ev.getX();
float y = ev.getY();
if (Math.abs(x - fastDownX) <= dv && Math.abs(y - fastDownY) <= dv) {
mOnFastTouchListener.onFastClick();
}
}
}
if (enableScroll && isEnabled()) {
startAutoScroll();
}
}
return super.dispatchTouchEvent(ev);
}
示例10: onActionUp
import android.view.MotionEvent; //导入方法依赖的package包/类
private void onActionUp(MotionEvent event)
{
long duration = event.getEventTime() - event.getDownTime();
if (duration < mClickTimeout
&& mTouchHelper.getDeltaXFrom(FTouchHelper.EVENT_DOWN) < mTouchSlop
&& mTouchHelper.getDeltaYFrom(FTouchHelper.EVENT_DOWN) < mTouchSlop)
{
toggleChecked(mAttrModel.isNeedToggleAnim(), true);
} else
{
if (mTouchHelper.isNeedCosume())
{
final int left = mViewThumb.getLeft();
final boolean checked = left >= ((getLeftNormal() + getLeftChecked()) / 2);
boolean updatePosition = false;
if (checked)
{
if (left != getLeftChecked())
{
updatePosition = true;
}
} else
{
if (left != getLeftNormal())
{
updatePosition = true;
}
}
if (setChecked(checked, true, true))
{
// 更新状态成功,内部会更新view的位置
} else
{
if (updatePosition)
{
updateViewByState(true);
}
}
}
}
}
示例11: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled() || !isClickable() || !isFocusable()) {
return false;
}
int action = event.getAction();
float deltaX = event.getX() - mStartX;
float deltaY = event.getY() - mStartY;
// status the view going to change to when finger released
boolean nextStatus;
switch (action) {
case MotionEvent.ACTION_DOWN:
catchView();
mStartX = event.getX();
mStartY = event.getY();
mLastX = mStartX;
setPressed(true);
break;
case MotionEvent.ACTION_MOVE:
float x = event.getX();
setProcess(getProcess() + (x - mLastX) / mSafeRectF.width());
mLastX = x;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
setPressed(false);
nextStatus = getStatusBasedOnPos();
float time = event.getEventTime() - event.getDownTime();
if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) {
performClick();
} else {
if (nextStatus != isChecked()) {
playSoundEffect(SoundEffectConstants.CLICK);
setChecked(nextStatus);
} else {
animateToState(nextStatus);
}
}
break;
default:
break;
}
return true;
}
示例12: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (getParent() != null) {
getParent().requestDisallowInterceptTouchEvent(true);
}
if (isOnAnimator) {
return false;
}
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
onTouchMove = true;
if (mScroller.computeScrollOffset()) {
mScroller.abortAnimation();
invalidate();
requestLayout();
}
touchBegan(event);
touchViewItem = getTopView();
isOnTopView = inRangeOfView(touchViewItem, event);
downX = event.getX();
downY = event.getY();
if (isOnTopView) {
sendLongClickAction();
}
return true;
case MotionEvent.ACTION_MOVE:
touchMoved(event);
if (Math.abs(downX - event.getX()) >= 10
|| Math.abs(downY - event.getY()) >= 10) { //10像素以外,不属于点击事件
removeLongClickAction();
touchViewItem = null;
isOnTopView = false;
}
return true;
case MotionEvent.ACTION_UP:
removeLongClickAction();
if (isOnTopView && touchViewItem == getTopView()
&& inRangeOfView(touchViewItem, event)) {
if (mTopViewClickLister != null) {
mTopViewClickLister.onClick(getTopViewPosition(), getTopView());
}
}
touchViewItem = null;
isOnTopView = false;
touchEnded(event);
//不是点击top view。并且启用点击切换。并且点击了
if (!isOnTopView && clickSwitchEnable
&& Math.abs(downX - event.getX()) < 10
&& Math.abs(downY - event.getY()) < 10
&& event.getEventTime() - event.getDownTime() < 500) {
if (atLeftOfView(getTopView(), event)) {
gotoPrevious();
} else if (atRightOfView(getTopView(), event)) {
gotoForward();
}
}
return true;
}
return false;
}
示例13: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
/**
* 触摸触发事件
* @param event 触摸事件
* @return 是否已处理
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
float x = event.getX();
float y = event.getY();
float deltaX = Math.abs(x - mFirstDownX);
float deltaY = Math.abs(y - mFirstDownY);
switch (action) {
case MotionEvent.ACTION_DOWN:
attemptClaimDrag();
mFirstDownX = x;
mFirstDownY = y;
mCurBtnPic = mBtnPressed;
mBtnInitPos = mChecked ? mBtnOnPos : mBtnOffPos;
break;
case MotionEvent.ACTION_MOVE:
mBtnPos = mBtnInitPos + event.getX() - mFirstDownX;
if (mBtnPos >= mBtnOffPos) {
mBtnPos = mBtnOffPos;
}
if (mBtnPos <= mBtnOnPos) {
mBtnPos = mBtnOnPos;
}
mTurningOn = mBtnPos > (mBtnOffPos - mBtnOnPos) / 2 + mBtnOnPos;
mRealPos = getRealPos(mBtnPos);
break;
case MotionEvent.ACTION_UP:
mCurBtnPic = mBtnNormal;
float time = event.getEventTime() - event.getDownTime();
if (deltaY < mTouchSlop && deltaX < mTouchSlop && time < mClickTimeout) {
if (mPerformClick == null) {
mPerformClick = new PerformClick();
}
if (!post(mPerformClick)) {
performClick();
}
} else {
startAnimation(!mTurningOn);
}
break;
}
invalidate();
return isEnabled();
}
示例14: onTouch
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();
}
mVelocityTracker.addMovement(event);
int velocityX = 0;
int velocityY = 0;
if (event.getAction() == MotionEvent.ACTION_DOWN) {
updateTargetViewLocation();
mShieldView.setVisibility(mShieldEnabled ? View.VISIBLE : View.GONE);
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (event.getEventTime() - event.getDownTime() >= 150) {
float accX = 0;
float accY = 0;
if (mVelocityTracker != null) {
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
velocityX = (int) mVelocityTracker.getXVelocity();
velocityY = (int) mVelocityTracker.getYVelocity();
accX = velocityX / (mMaxVelocity);
accY = velocityY / (mMaxVelocity);
}
dragView(event.getRawX() - mTargetWidth / 2,
event.getRawY() - mTargetHeight / 2 - mContentTopInWindow,
velocityX, velocityY, accX, accY);
mChildren.get(mChildCount - 1).setClickable(false);
return true;
}
} else if (event.getAction() == MotionEvent.ACTION_UP) {
mChildren.get(mChildCount - 1).setClickable(true);
if (event.getEventTime() - event.getDownTime() < 150) {
mShieldView.setVisibility(View.GONE);
return false;
} else {
releaseView();
return true;
}
}
return false;
}
示例15: onTouchEvent
import android.view.MotionEvent; //导入方法依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!isEnabled() || !isClickable()) {
return false;
}
int action = event.getAction();
float deltaX = event.getX() - mStartX;
float deltaY = event.getY() - mStartY;
// status the view going to change to when finger released
boolean nextStatus;
switch (action) {
case MotionEvent.ACTION_DOWN:
catchView();
mStartX = event.getX();
mStartY = event.getY();
mLastX = mStartX;
setPressed(true);
break;
case MotionEvent.ACTION_MOVE:
float x = event.getX();
setProcess(getProcess() + (x - mLastX) / mSafeRectF.width());
mLastX = x;
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
setPressed(false);
nextStatus = getStatusBasedOnPos();
float time = event.getEventTime() - event.getDownTime();
if (deltaX < mTouchSlop && deltaY < mTouchSlop && time < mClickTimeout) {
performClick();
} else {
if (nextStatus != isChecked()) {
playSoundEffect(SoundEffectConstants.CLICK);
setChecked(nextStatus);
} else {
animateToState(nextStatus);
}
}
break;
default:
break;
}
return true;
}