本文整理汇总了Java中android.view.MotionEvent.ACTION_DOWN属性的典型用法代码示例。如果您正苦于以下问题:Java MotionEvent.ACTION_DOWN属性的具体用法?Java MotionEvent.ACTION_DOWN怎么用?Java MotionEvent.ACTION_DOWN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.view.MotionEvent
的用法示例。
在下文中一共展示了MotionEvent.ACTION_DOWN属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dispatchOnItemTouchIntercept
private boolean dispatchOnItemTouchIntercept(MotionEvent e) {
final int action = e.getAction();
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_DOWN) {
mActiveOnItemTouchListener = null;
}
final int listenerCount = mOnItemTouchListeners.size();
for (int i = 0; i < listenerCount; i++) {
final OnItemTouchListener listener = mOnItemTouchListeners.get(i);
if (listener.onInterceptTouchEvent(this, e) && action != MotionEvent.ACTION_CANCEL) {
mActiveOnItemTouchListener = listener;
return true;
}
}
return false;
}
示例2: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if (mCanClick) {
mCanClick = false;
if (mStatus == STATUS_NORMAL) {
mStatus = STATUS_PRESS;
startPressStatusAnimation();
} else {
resetStatus();
}
}
break;
case MotionEvent.ACTION_UP:
if (mStatus == STATUS_PRESS) {
mStatus = STATUS_PRESS_RELEASE;
startPressReleaseStatusAnimation();
}
break;
}
return true;
}
示例3: analyzeTouchToMaximizeIfNeeded
private void analyzeTouchToMaximizeIfNeeded(MotionEvent ev, boolean isDragViewHit) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
lastTouchActionDownXPosition = ev.getX();
break;
case MotionEvent.ACTION_UP:
float clickOffset = ev.getX() - lastTouchActionDownXPosition;
if (shouldMaximizeOnClick(ev, clickOffset, isDragViewHit)) {
if (isMinimized() && isClickToMaximizeEnabled()) {
maximize();
} else if (isMaximized() && isClickToMinimizeEnabled()) {
minimize();
}
}
break;
default:
break;
}
}
示例4: dispatchTouchEvent
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mIsLoadDataComplete) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
mStartY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(mStartY - ev.getY()) > 15) {
mTvTime.removeCallbacks(mHideAnimTask);
if (mTvTime.getVisibility() == View.GONE || mHideTimeAnim.isRunning()) {
mHideTimeAnim.cancel();
mShowTimeAnim.start();
}
setTvTimeText();
}
break;
}
}
return super.dispatchTouchEvent(ev);
}
示例5: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
lastY = (int) e.getRawY();
break;
case MotionEvent.ACTION_MOVE:
int y = (int) (e.getRawY());
int dy = y - lastY;
lastY = y;
if (startNestedScroll(ViewCompat.SCROLL_AXIS_HORIZONTAL) //如果找到了支持嵌套滚动的父类
&& dispatchNestedPreScroll(0, dy, consumed, offset)) {//父类进行了一部分滚动
int remain = dy - consumed[1];//获取滚动的剩余距离
if (remain != 0) {
scrollBy(0, -remain);
}
} else {
scrollBy(0, -dy);
}
}
return true;
}
示例6: dispatchTouchEvent
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
if (isTouchView(filterViewByIds(), ev)) return super.dispatchTouchEvent(ev);
if (hideSoftByEditViewIds() == null || hideSoftByEditViewIds().length == 0)
return super.dispatchTouchEvent(ev);
View v = getCurrentFocus();
if (isFocusEditText(v, hideSoftByEditViewIds())) {
if (isTouchView(hideSoftByEditViewIds(), ev))
return super.dispatchTouchEvent(ev);
//隐藏键盘
KeyBoardUtils.hideInputForce(this);
clearViewFocus(v, hideSoftByEditViewIds());
}
}
return super.dispatchTouchEvent(ev);
}
示例7: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
xDistance = yDistance = 0f;
lastX = ev.getX();
lastY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
final float curX = ev.getX();
final float curY = ev.getY();
xDistance += Math.abs(curX - lastX);
yDistance += Math.abs(curY - lastY);
lastX = curX;
lastY = curY;
if(xDistance > yDistance)
return false;
}
return super.onInterceptTouchEvent(ev);
}
示例8: onTouch
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouch(View view, MotionEvent event) {
boolean isTouchEventConsumed = false;
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
mIsTouchEventsBeingProcessed = true;
isTouchEventConsumed |= true;
view.setPressed(true);
showAppMenu(view, true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mIsTouchEventsBeingProcessed = false;
isTouchEventConsumed |= true;
view.setPressed(false);
break;
default:
}
// If user starts to drag on this menu button, ACTION_DOWN and all the subsequent touch
// events are received here. We need to forward this event to the app menu to handle
// dragging correctly.
AppMenuDragHelper dragHelper = mMenuHandler.getAppMenuDragHelper();
if (dragHelper != null) {
isTouchEventConsumed |= dragHelper.handleDragging(event, view);
}
return isTouchEventConsumed;
}
示例9: onTouchEvent
public boolean onTouchEvent(MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
// If down event occurs inside index bar region, start indexing
if (mState != STATE_HIDDEN && contains(ev.getX(), ev.getY())) {
setState(STATE_SHOWN);
// It demonstrates that the motion event started from index bar
mIsIndexing = true;
// Determine which section the point is in, and move the list to that section
mCurrentSection = getSectionByPoint(ev.getY());
mListView.setSelection(mIndexer.getPositionForSection(mCurrentSection));
return true;
}
break;
case MotionEvent.ACTION_MOVE:
if (mIsIndexing) {
// If this event moves inside index bar
if (contains(ev.getX(), ev.getY())) {
// Determine which section the point is in, and move the list to that section
mCurrentSection = getSectionByPoint(ev.getY());
mListView.setSelection(mIndexer.getPositionForSection(mCurrentSection));
}
return true;
}
break;
case MotionEvent.ACTION_UP:
if (mIsIndexing) {
mIsIndexing = false;
mCurrentSection = -1;
}
if (mState == STATE_SHOWN)
setState(STATE_HIDING);
break;
}
return false;
}
示例10: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
//用户按下到下一个链接加载之前,置为true
mTouchByUser = true;
break;
}
return super.onTouchEvent(event);
}
示例11: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
mScroller.forceFinished(true);
int type = MotionEventCompat.getActionMasked(ev);
float currentX = MotionEventCompat.getX(ev, 0);
float currentY = MotionEventCompat.getY(ev, 0);
switch (type) {
case MotionEvent.ACTION_DOWN:
downX = currentX;
downY = currentY;
float x = firstView.getX() + firstView.getMeasuredWidth() / 2.0f;
float y = firstView.getY() + firstView.getMeasuredHeight() / 2.0f;
lastAngle = (float) getRelativeAngle(x, y);
break;
case MotionEvent.ACTION_MOVE:
float distance = getDistance(downX, downY, currentX, currentY);
if (distance > ViewConfiguration.getTouchSlop()) {
return true;
}
break;
case MotionEvent.ACTION_UP:
break;
}
return false;
}
示例12: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = ev.getAction();
float x = ev.getRawX();
float y = ev.getRawY();
switch (action) {
case MotionEvent.ACTION_DOWN:
xDown = x;
yDown = y;
break;
case MotionEvent.ACTION_MOVE:
int xDistance = (int) (x - xDown);
int yDistance = (int) (y - yDown);
if (Math.abs(xDistance) > touchSlop && Math.abs(xDistance) > Math.abs(yDistance)) {
if (!recyclerView.canScrollHorizontally(-1) && xDistance > 0
|| (!recyclerView.canScrollHorizontally(1) && xDistance < 0)) {
enableOverScrollPull = true;
return true;
} else {
enableOverScrollPull = false;
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (enableOverScrollPull) {
return true;
}
break;
default:
break;
}
return false;
}
示例13: onInterceptTouchEvent
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, TextView child, MotionEvent ev) {
switch (ev.getAction()) {
case MotionEvent.ACTION_DOWN:
downReach = false;
upReach = false;
break;
}
return super.onInterceptTouchEvent(parent, child, ev);
}
示例14: onTouchEvent
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
downX = event.getX();
break;
case MotionEvent.ACTION_MOVE:
moveX = event.getX();
//if is not scrolling
if (Math.abs(downX - moveX) >= touchSlop) {
isScrolling = true;
int alterMove = (int) (downX - moveX);
if (getScrollX() + alterMove <= leftBorder) {
scrollTo((int) leftBorder, 0);
} else {
scrollTo(getScrollX() + alterMove, 0);
}
}
break;
case MotionEvent.ACTION_UP:
if (isScrolling == true) {
scroller.startScroll(getScrollX(), 0, getScrollX() + (int) (moveX - downX), 0, 2000);
invalidate();
}
break;
}
return true;
}
示例15: onTouchEvent
/**
* <ul>
* if stopScrollWhenTouch is true
* <li>if event is down, stop auto scroll.</li>
* <li>if event is up, start auto scroll again.</li>
* </ul>
*/
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (stopScrollWhenTouch) {
if (ev.getAction() == MotionEvent.ACTION_DOWN && isAutoScroll) {
isStopByTouch = true;
stopAutoScroll();
} else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
startAutoScroll();
}
}
if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
touchX = ev.getX();
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
downX = touchX;
}
int currentItem = getCurrentItem();
PagerAdapter adapter = getAdapter();
int pageCount = adapter == null ? 0 : adapter.getCount();
/**
* current index is first one and slide to right or current index is last one and slide to left.<br/>
* if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br/>
* else scroll to last one when current item is first one, scroll to first one when current item is last
* one.
*/
if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) {
if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
getParent().requestDisallowInterceptTouchEvent(false);
} else {
if (pageCount > 1) {
setCurrentItem(pageCount - currentItem - 1, isBorderAnimation);
}
getParent().requestDisallowInterceptTouchEvent(true);
}
return super.onTouchEvent(ev);
}
}
getParent().requestDisallowInterceptTouchEvent(true);
return super.onTouchEvent(ev);
}