本文整理汇总了Java中android.support.v4.view.MotionEventCompat类的典型用法代码示例。如果您正苦于以下问题:Java MotionEventCompat类的具体用法?Java MotionEventCompat怎么用?Java MotionEventCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MotionEventCompat类属于android.support.v4.view包,在下文中一共展示了MotionEventCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (mReturningToStart && action == MotionEvent.ACTION_DOWN) {
mReturningToStart = false;
}
if (!isEnabled() || mReturningToStart
|| (!isChildScrollToTop() && !isChildScrollToBottom())) {
// 如果子View可以滑动,不拦截事件,交给子View处理
return false;
}
if (isChildScrollToBottom()) {
// 上拉加载更多
return handlerPushTouchEvent(ev, action);
} else {
// 下拉刷新
return handlerPullTouchEvent(ev, action);
}
}
示例2: onGenericMotionEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
public boolean onGenericMotionEvent(MotionEvent event) {
if (!(this.mLayout == null || this.mLayoutFrozen || (MotionEventCompat.getSource(event) & 2) == 0 || event.getAction() != 8)) {
float vScroll;
float hScroll;
if (this.mLayout.canScrollVertically()) {
vScroll = -MotionEventCompat.getAxisValue(event, 9);
} else {
vScroll = 0.0f;
}
if (this.mLayout.canScrollHorizontally()) {
hScroll = MotionEventCompat.getAxisValue(event, 10);
} else {
hScroll = 0.0f;
}
if (!(vScroll == 0.0f && hScroll == 0.0f)) {
float scrollFactor = getScrollFactor();
scrollByInternal((int) (hScroll * scrollFactor), (int) (vScroll * scrollFactor), event);
}
}
return false;
}
示例3: dispatchTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (mAutoScrollable) {
int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_DOWN) {
stopScroll();
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
resumeScroll();
}
this.getParent().requestDisallowInterceptTouchEvent(true);
}
return super.dispatchTouchEvent(ev);
}
示例4: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onTouchEvent(@NotNull MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case (MotionEvent.ACTION_DOWN):
case (MotionEvent.ACTION_MOVE):
case (MotionEvent.ACTION_UP):
int band = Math.max(0, Math.min(mSourcePathPoints.length - 1, (int)(mSourcePathPoints.length * event.getX() / getWidth())));
float value = 30 * (getHeight() - event.getY()) / getHeight();
if (listener != null)
listener.OnBandUpdated(band, value);
return true;
case (MotionEvent.ACTION_CANCEL):
return true;
case (MotionEvent.ACTION_OUTSIDE):
return true;
default :
return super.onTouchEvent(event);
}
}
示例5: bindDragHandle
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
/**
* this functions binds the view's touch listener to start the drag via the touch helper...
*
* @param holder the view holder
* @param holder the item
*/
public static void bindDragHandle(final RecyclerView.ViewHolder holder, final IExtendedDraggable item) {
// if necessary, init the drag handle, which will start the drag when touched
if (item.getTouchHelper() != null && item.getDragView(holder) != null) {
item.getDragView(holder).setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
if (item.isDraggable())
item.getTouchHelper().startDrag(holder);
}
return false;
}
});
}
}
示例6: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// Selection may be beginning. Sync the TextView with the buffer.
refreshTextFromBuffer();
}
// Mouse input is treated differently:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH &&
MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) {
if (onMouseEvent(event, terminalView.bridge)) {
return true;
}
terminalView.viewPager.setPagingEnabled(true);
} else {
if (terminalView.onTouchEvent(event)) {
return true;
}
}
return super.onTouchEvent(event);
}
示例7: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onTouchEvent(MotionEvent event) {
//Check pointer index to avoid -1 (error)
if (MotionEventCompat.findPointerIndex(event, 0) == -1) {
return super.onTouchEvent(event);
}
if (event.getPointerCount() >= 1) {
requestDisallowInterceptTouchEvent(true);
} else {
requestDisallowInterceptTouchEvent(false);
}
return super.onTouchEvent(event);
}
示例8: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
public boolean onTouchEvent(MotionEvent ev) {
int action = MotionEventCompat.getActionMasked(ev);
if (action == 0) {
this.mEatingTouch = false;
}
if (!this.mEatingTouch) {
boolean handled = super.onTouchEvent(ev);
if (action == 0 && !handled) {
this.mEatingTouch = true;
}
}
if (action == 1 || action == 3) {
this.mEatingTouch = false;
}
return true;
}
示例9: onInterceptTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// L.e("call: onInterceptTouchEvent([ev])-> " + ev.getAction());
int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
onTouchUp();
onTouchEnd();
if (Math.abs(mStartScrollY - getScrollY()) >
ViewConfiguration.get(getContext()).getScaledTouchSlop()) {
//ev.setAction(MotionEvent.ACTION_CANCEL);
return true;
}
}
return super.onInterceptTouchEvent(ev);
}
示例10: findSwipedView
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
private ViewHolder findSwipedView(MotionEvent motionEvent) {
final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager();
if (mActivePointerId == ACTIVE_POINTER_ID_NONE) {
return null;
}
final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, mActivePointerId);
final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - mInitialTouchX;
final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - mInitialTouchY;
final float absDx = Math.abs(dx);
final float absDy = Math.abs(dy);
if (absDx < mSlop && absDy < mSlop) {
return null;
}
if (absDx > absDy && lm.canScrollHorizontally()) {
return null;
} else if (absDy > absDx && lm.canScrollVertically()) {
return null;
}
View child = findChildView(motionEvent);
if (child == null) {
return null;
}
return mRecyclerView.getChildViewHolder(child);
}
示例11: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的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;
}
示例12: onTouch
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
public boolean onTouch(View v, MotionEvent event) {
boolean z = true;
if (!this.mEnabled) {
return false;
}
switch (MotionEventCompat.getActionMasked(event)) {
case 0:
this.mNeedsCancel = true;
this.mAlreadyDelayed = false;
break;
case 1:
case 3:
requestStop();
break;
case 2:
break;
}
this.mScroller.setTargetVelocity(computeTargetVelocity(0, event.getX(), (float) v.getWidth(), (float) this.mTarget.getWidth()), computeTargetVelocity(1, event.getY(), (float) v.getHeight(), (float) this.mTarget.getHeight()));
if (!this.mAnimating && shouldAnimate()) {
startAnimating();
}
if (!(this.mExclusive && this.mAnimating)) {
z = false;
}
return z;
}
示例13: onTouchEvent
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
@Override
public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) {
if (!child.isShown()) {
return false;
}
int action = MotionEventCompat.getActionMasked(event);
if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
return true;
}
mViewDragHelper.processTouchEvent(event);
if (action == MotionEvent.ACTION_DOWN) {
reset();
}
// The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it
// to capture the bottom sheet in case it is not captured and the touch slop is passed.
if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) {
if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) {
mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex()));
}
}
return !mIgnoreEvents;
}
示例14: determineDrag
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
private void determineDrag(MotionEvent ev) {
final int activePointerId = mActivePointerId;
final int pointerIndex = getPointerIndex(ev, activePointerId);
if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER)
return;
final float x = MotionEventCompat.getX(ev, pointerIndex);
final float dx = x - mLastMotionX;
final float xDiff = Math.abs(dx);
final float y = MotionEventCompat.getY(ev, pointerIndex);
final float dy = y - mLastMotionY;
final float yDiff = Math.abs(dy);
if (xDiff > (isMenuOpen()?mTouchSlop/2:mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) {
startDrag();
mLastMotionX = x;
mLastMotionY = y;
setScrollingCacheEnabled(true);
// TODO add back in touch slop check
} else if (xDiff > mTouchSlop) {
mIsUnableToDrag = true;
}
}
示例15: a
import android.support.v4.view.MotionEventCompat; //导入依赖的package包/类
private boolean a(char c) {
switch (c) {
case '\t':
case '\n':
case '\f':
case '\r':
case ' ':
case MotionEventCompat.AXIS_GENERIC_13 /*44*/:
case ':':
case '[':
case ']':
case '{':
case '}':
break;
case '#':
case MotionEventCompat.AXIS_GENERIC_16 /*47*/:
case ';':
case '=':
case '\\':
v();
break;
default:
return true;
}
return false;
}