Java Examples for android.support.v4.view.MotionEventCompat
The following java examples will help you to understand the usage of android.support.v4.view.MotionEventCompat. These source code samples are taken from different open source projects.
Example 1
| Project: AndroidFire-master File: IRecyclerView.java View source code |
/**
* 监�滑动手势
*
* @param e
* @return
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
final int action = android.support.v4.view.MotionEventCompat.getActionMasked(e);
final int actionIndex = android.support.v4.view.MotionEventCompat.getActionIndex(e);
switch(action) {
case MotionEvent.ACTION_DOWN:
{
mActivePointerId = android.support.v4.view.MotionEventCompat.getPointerId(e, 0);
mLastTouchX = (int) (android.support.v4.view.MotionEventCompat.getX(e, actionIndex) + 0.5f);
mLastTouchY = (int) (android.support.v4.view.MotionEventCompat.getY(e, actionIndex) + 0.5f);
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
{
mActivePointerId = android.support.v4.view.MotionEventCompat.getPointerId(e, actionIndex);
mLastTouchX = (int) (android.support.v4.view.MotionEventCompat.getX(e, actionIndex) + 0.5f);
mLastTouchY = (int) (android.support.v4.view.MotionEventCompat.getY(e, actionIndex) + 0.5f);
}
break;
case android.support.v4.view.MotionEventCompat.ACTION_POINTER_UP:
{
onPointerUp(e);
}
break;
}
return super.onInterceptTouchEvent(e);
}Example 2
| Project: FASTA-master File: DragDropUtil.java View source code |
/**
* 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;
}
});
}
}Example 3
| Project: FastAdapter-master File: DragDropUtil.java View source code |
/**
* 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;
}
});
}
}Example 4
| Project: palabre-extensions-master File: CategorySourceViewHolder.java View source code |
public void bindItem(Context context, String text, String image) {
textView.setText(text);
if (!TextUtils.isEmpty(image)) {
Picasso.with(context).load(image).into(// .centerCrop()
imageView);
}
if (dragView != null) {
dragView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
touchListener.startDrag(CategorySourceViewHolder.this);
}
return false;
}
});
}
}Example 5
| Project: wheelmap-android-master File: ScreenshotHelper.java View source code |
static Bitmap getBitmap(int x, int y, int width, int height, GL10 gl) throws OutOfMemoryError {
int[] bitmapBuffer = new int[(width * height)];
int[] bitmapSource = new int[(width * height)];
IntBuffer intBuffer = IntBuffer.wrap(bitmapBuffer);
intBuffer.position(0);
try {
gl.glReadPixels(x, y, width, height, 6408, 5121, intBuffer);
for (int i = 0; i < height; i++) {
int offset1 = i * width;
int offset2 = ((height - i) - 1) * width;
for (int j = 0; j < width; j++) {
int texturePixel = bitmapBuffer[offset1 + j];
bitmapSource[offset2 + j] = ((-16711936 & texturePixel) | ((texturePixel << 16) & 16711680)) | ((texturePixel >> 16) & MotionEventCompat.ACTION_MASK);
}
}
return Bitmap.createBitmap(bitmapSource, width, height, Config.ARGB_8888);
} catch (GLException e) {
Log.e(TAG, "Error generating Bitmap.", e);
return null;
}
}Example 6
| Project: AndroidSwipeableCardStack-master File: DragGestureDetector.java View source code |
public void onTouchEvent(MotionEvent event) {
mGestureDetector.onTouchEvent(event);
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case (MotionEvent.ACTION_UP):
Log.d(DEBUG_TAG, "Action was UP");
if (mStarted) {
mListener.onDragEnd(mOriginalEvent, event);
}
mStarted = false;
case (MotionEvent.ACTION_DOWN):
//need to set this, quick tap will not generate drap event, so the
//originalEvent may be null for case action_up
//which lead to null pointer
mOriginalEvent = event;
}
}Example 7
| Project: ikvStockChart-master File: PullListLayout.java View source code |
@Override
public boolean dispatchTouchEvent(MotionEvent e) {
// 解决 PullListLayout 垂直滑动(下拉刷新)与横�滑动冲�
if (gestureCompat.onTouchEvent(e, e.getRawX(), e.getRawY())) {
return dispatchTouchEventSupper(e);
}
// 解决�指缩放的冲�
if (MotionEventCompat.getActionMasked(e) == MotionEvent.ACTION_POINTER_DOWN) {
isRefresh = false;
}
if (isRefresh) {
return super.dispatchTouchEvent(e);
}
switch(e.getAction()) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
isRefresh = true;
return super.dispatchTouchEvent(e);
}
return dispatchTouchEventSupper(e);
}Example 8
| Project: material-motion-android-master File: TweenActivity.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case MotionEvent.ACTION_DOWN:
{
MaterialAnimator animator = MaterialAnimator.ofFloat(target, View.ALPHA, 0f);
animator.setDuration(1000);
animator.start(runtime);
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
{
MaterialAnimator animator = MaterialAnimator.ofFloat(target, View.ALPHA, 1f);
animator.setDuration(1000);
animator.start(runtime);
break;
}
}
return true;
}Example 9
| Project: MiMangaNu-master File: UnScrolledViewPagerVertical.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (getCurrentItem() == 0 || getCurrentItem() == getAdapter().getCount() - 1) {
final int action = ev.getAction();
float y = ev.getY();
switch(action & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
long mEndTime = ev.getEventTime();
if (Math.abs(y - mStartDragY) > MIN_DISTANCE && (mEndTime - mStartTime) < MAX_TIME) {
if (getCurrentItem() == 0 && y > mStartDragY) {
onSwipeOutAtStart();
return true;
}
if (getCurrentItem() == getAdapter().getCount() - 1 && y < mStartDragY) {
onSwipeOutAtEnd();
return true;
}
}
break;
}
} else {
mStartDragY = 0;
}
return super.onTouchEvent(ev);
}Example 10
| Project: MyDragLayout-master File: Utils.java View source code |
public static String getActionName(MotionEvent event) {
String action = "unknow";
switch(MotionEventCompat.getActionMasked(event)) {
case MotionEvent.ACTION_DOWN:
action = "ACTION_DOWN";
break;
case MotionEvent.ACTION_MOVE:
action = "ACTION_MOVE";
break;
case MotionEvent.ACTION_UP:
action = "ACTION_UP";
break;
case MotionEvent.ACTION_CANCEL:
action = "ACTION_CANCEL";
break;
case MotionEvent.ACTION_OUTSIDE:
action = "ACTION_SCROLL";
break;
default:
break;
}
return action;
}Example 11
| Project: Osmand-master File: SwitchableAction.java View source code |
@Override
public void onBindViewHolder(final Adapter.ItemHolder holder, final int position) {
final T item = itemsList.get(position);
holder.title.setText(getItemName(item));
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
onStartDragListener.onStartDrag(holder);
}
return false;
}
});
holder.closeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String oldTitle = getTitle(itemsList);
String defaultName = holder.handleView.getContext().getString(getNameRes());
deleteItem(holder.getAdapterPosition());
if (oldTitle.equals(title.getText().toString()) || title.getText().toString().equals(defaultName)) {
String newTitle = getTitle(itemsList);
title.setText(newTitle);
}
}
});
}Example 12
| Project: RxBinding-master File: RxSwipeRefreshLayoutTestActivity.java View source code |
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
swipeRefreshLayout = new SwipeRefreshLayout(this);
swipeRefreshLayout.setId(R.id.swipe_refresh_layout);
swipeRefreshLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_UP) {
handler.removeCallbacks(stopRefreshing);
handler.postDelayed(stopRefreshing, 300);
}
return false;
}
});
ScrollView scrollView = new ScrollView(this);
LayoutParams scrollParams = new LayoutParams(MATCH_PARENT, MATCH_PARENT);
swipeRefreshLayout.addView(scrollView, scrollParams);
FrameLayout emptyView = new FrameLayout(this);
LayoutParams emptyParams = new LayoutParams(MATCH_PARENT, 100000);
scrollView.addView(emptyView, emptyParams);
setContentView(swipeRefreshLayout);
}Example 13
| Project: shuttle-master File: TabsAdapter.java View source code |
@Override
protected void attachListeners(RecyclerView.ViewHolder viewHolder) {
super.attachListeners(viewHolder);
if (viewHolder instanceof TabView.ViewHolder) {
viewHolder.itemView.setOnClickListener( v -> {
if (mListener != null && viewHolder.getAdapterPosition() != -1) {
mListener.onItemClick(v, viewHolder.getAdapterPosition(), ((TabView) items.get(viewHolder.getAdapterPosition())).categoryItem);
}
});
if (((TabView.ViewHolder) viewHolder).dragHandle != null) {
((TabView.ViewHolder) viewHolder).dragHandle.setOnTouchListener(( v, event) -> {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mListener.onStartDrag(viewHolder);
}
return false;
});
}
}
}Example 14
| Project: trezor-android-master File: ScrollViewHelper.java View source code |
//
// CALLBACKS
//
public boolean onAnyTouchEvent(MotionEvent ev) {
if (!scrollingEnabled)
return false;
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
isRefusingOverscroll = false;
}
switch(action) {
case MotionEvent.ACTION_DOWN:
if (refuseOverscroll && host.isScrolledToTop()) {
isRefusingOverscroll = true;
mActivePointerId = ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK;
mInitMotionY = MotionEventCompat.getY(ev, mActivePointerId);
} else {
isRefusingOverscroll = false;
}
break;
case MotionEvent.ACTION_MOVE:
if (isRefusingOverscroll && mActivePointerId != INVALID_POINTER) {
final int pointerIndex = getPointerIndex(ev, mActivePointerId);
if (pointerIndex >= 0) {
final float y = MotionEventCompat.getY(ev, pointerIndex);
if (y > mInitMotionY) {
return false;
}
}
}
break;
}
return true;
}Example 15
| Project: trio-master File: MenuDescriptionPlaceholder.java View source code |
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
int diff;
switch(action) {
case MotionEvent.ACTION_DOWN:
mStartScroll = event.getY();
return true;
case MotionEvent.ACTION_MOVE:
diff = Math.round(event.getY() - mStartScroll);
mIsScrolling = Math.abs(diff) > SWIPE_MIN_DISTANCE;
if (Trio.LOCAL_LOGD)
Log.d("EVENT", "moving! " + diff);
if (mListener != null) {
mListener.onMoving(diff, mIsScrolling);
}
return true;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
diff = Math.round(event.getY() - mStartScroll);
if (mIsScrolling) {
if (mListener != null) {
if (diff > 0) {
if (Trio.LOCAL_LOGD)
Log.d("EVENT", "up!");
mListener.onUp(diff);
} else {
if (Trio.LOCAL_LOGD)
Log.d("EVENT", "down!");
mListener.onDown(diff);
}
}
} else {
if (mListener != null) {
mListener.onStoppedMoving(diff);
}
}
mIsScrolling = false;
return true;
default:
return super.onTouchEvent(event);
}
}Example 16
| Project: ZimDroid-master File: DraggableBottomCard.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
dragHelper.cancel();
return false;
} else if (dragHelper.shouldInterceptTouchEvent(ev)) {
return true;
}
return super.onInterceptTouchEvent(ev);
}Example 17
| Project: androGister-master File: CatalogProductListFragment.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
// Always handle the case of the touch gesture being complete.
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
// Release the scroll.
mIsScrolling = false;
// Do not intercept touch event, let the child
return false;
// handle it
}
switch(action) {
case MotionEvent.ACTION_MOVE:
{
if (mIsScrolling) {
// touch event!
return true;
}
// If the user has dragged her finger horizontally more than
// the touch slop, start the scroll
// left as an exercise for the reader
final boolean xDiff = calculateDistanceX(ev);
// constants.
if (xDiff) {
// Start scrolling!
mIsScrolling = true;
return true;
}
break;
}
}
return false;
}Example 18
| Project: androidbible-master File: VerseTextView.java View source code |
/**
* Detects link clicks more accurately using the following algorithm:
* 1. Get all the clickable spans.
* 2. For each of the clickable spans, try to approximate the bounds rects of the span by:
* a. If the span start and end are in the same line, the bounds rect is from span's start to end.
* b. Else, there are three bounds rects: the span start until the right side, span end until the left side, and the big
* multi-line bounds rect between the bottom of span start and top of span end. TODO: Support RTL.
* 3. Look for the entry that is nearest to the touch with max distance 24dp (so the touch diameter is 48dp) and perform click on the span.
* If there is no such entry, make our handling return false to let the touch handled by this view's parent.
*/
@Override
public boolean onTouchEvent(MotionEvent event) {
final int action = MotionEventCompat.getActionMasked(event);
if (action != MotionEvent.ACTION_UP && action != MotionEvent.ACTION_DOWN)
return false;
final CharSequence text = this.getText();
if (!(text instanceof Spanned))
return false;
final Layout layout = this.getLayout();
if (layout == null)
return false;
final Spanned buffer = (Spanned) text;
final int touchX = (int) (event.getX() + 0.5f) - this.getTotalPaddingLeft() + this.getScrollX();
final int touchY = (int) (event.getY() + 0.5f) - this.getTotalPaddingTop() + this.getScrollY();
final List<SpanEntry> spanEntries = spanEntriesBuffer.get();
// we don't clear the list to prevent deallocation and reallocation of SpanEntries.
int spanEntries_count = 0;
for (final ClickableSpan span : buffer.getSpans(0, buffer.length(), ClickableSpan.class)) {
final int spanStart = buffer.getSpanStart(span);
final int lineStart = layout.getLineForOffset(spanStart);
final int xStart = (int) (layout.getPrimaryHorizontal(spanStart) + 0.5f);
final int spanEnd = buffer.getSpanEnd(span);
final int lineEnd = layout.getLineForOffset(spanEnd);
final int xEnd = (int) (layout.getPrimaryHorizontal(spanEnd) + 0.5f);
if (lineStart == lineEnd) {
final int top = layout.getLineTop(lineStart);
final int bottom = layout.getLineBottom(lineStart);
spanEntries_count = addSpanEntry(spanEntries, spanEntries_count, span, xStart, top, xEnd, bottom);
} else {
final int topStart = layout.getLineTop(lineStart);
final int bottomStart = layout.getLineBottom(lineStart);
final int topEnd = layout.getLineTop(lineEnd);
final int bottomEnd = layout.getLineBottom(lineEnd);
// line where span start is contained
spanEntries_count = addSpanEntry(spanEntries, spanEntries_count, span, xStart, topStart, layout.getWidth(), bottomStart);
// line where span end is contained
spanEntries_count = addSpanEntry(spanEntries, spanEntries_count, span, 0, topEnd, xEnd, bottomEnd);
// add the in-between span only if line difference is > 1
if (lineEnd - lineStart > 1) {
spanEntries_count = addSpanEntry(spanEntries, spanEntries_count, span, 0, bottomStart, layout.getWidth(), topEnd);
}
}
}
if (BuildConfig.DEBUG) {
Log.d(TAG, "----------");
Log.d(TAG, "touchX=" + touchX);
Log.d(TAG, "touchY=" + touchY);
for (int i = 0; i < spanEntries_count; i++) {
final SpanEntry e = spanEntries.get(i);
Log.d(TAG, "SpanEntry " + i + " at " + e.rect.toString() + ": span " + e.span + " '" + buffer.subSequence(buffer.getSpanStart(e.span), buffer.getSpanEnd(e.span)) + "'");
}
}
if (spanEntries_count == 0)
return false;
final float density = getResources().getDisplayMetrics().density;
// radius 24dp
final int maxDistanceSquared = (int) (24 * 24 * density * density);
ClickableSpan bestSpan = null;
int bestDistanceSquared = Integer.MAX_VALUE;
for (int i = 0; i < spanEntries_count; i++) {
final SpanEntry spanEntry = spanEntries.get(i);
// is touch inside the span rect?
final Rect r = spanEntry.rect;
if (r.contains(touchX, touchY)) {
bestDistanceSquared = 0;
bestSpan = spanEntry.span;
// no possible better target
break;
} else {
final int distanceSquared;
if (touchY < r.top) {
if (touchX < r.left) {
distanceSquared = ds(touchX - r.left, touchY - r.top);
} else if (touchX >= r.right) {
distanceSquared = ds(touchX - r.right, touchY - r.top);
} else // on the top of bounds
{
distanceSquared = ds(0, touchY - r.top);
}
} else if (touchY >= r.bottom) {
if (touchX < r.left) {
distanceSquared = ds(touchX - r.left, touchY - r.bottom);
} else if (touchX >= r.right) {
distanceSquared = ds(touchX - r.right, touchY - r.bottom);
} else // on the bottom of bounds
{
distanceSquared = ds(0, touchY - r.bottom);
}
} else // on the left or right of bounds
{
if (touchX < r.left) {
distanceSquared = ds(touchX - r.left, 0);
} else {
distanceSquared = ds(touchX - r.right, 0);
}
}
if (distanceSquared <= maxDistanceSquared) {
if (distanceSquared < bestDistanceSquared) {
bestDistanceSquared = distanceSquared;
bestSpan = spanEntry.span;
}
}
}
}
for (int i = 0; i < spanEntries_count; i++) {
final SpanEntry spanEntry = spanEntries.get(i);
// don't keep any references to span!
spanEntry.clear();
}
if (BuildConfig.DEBUG) {
final double dist = Math.sqrt(bestDistanceSquared);
Log.d(TAG, "Best span is: " + bestSpan + " with distance " + dist + " (" + (dist / density) + "dp)");
}
if (bestSpan != null) {
if (action == MotionEvent.ACTION_UP) {
bestSpan.onClick(this);
}
return true;
}
return false;
}Example 19
| Project: AndroidStudioProjects-master File: MainActivity.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
int corx = (int) event.getX();
int cody = (int) event.getY();
switch(action) {
case (MotionEvent.ACTION_DOWN):
texto.setText("La pulsación ha sido DOWN en la posición: " + corx + ", " + cody);
return true;
case (MotionEvent.ACTION_MOVE):
texto.setText("La pulsación ha sido MOVE en la posición: " + corx + ", " + cody);
return true;
case (MotionEvent.ACTION_UP):
texto.setText("La pulsación ha sido UP en la posición: " + corx + ", " + cody);
return true;
case (MotionEvent.ACTION_CANCEL):
texto.setText("La pulsación ha sido ACTION_CANCEL en la posición: " + corx + ", " + cody);
return true;
case (MotionEvent.ACTION_OUTSIDE):
texto.setText("La pulsación ha sido ACTION_OUTSIDE en la posición: " + corx + ", " + cody);
return true;
default:
return true;
}
}Example 20
| Project: material-intro-screen-master File: SwipeableViewPager.java View source code |
@Override
public boolean onInterceptTouchEvent(final MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case (MotionEvent.ACTION_DOWN):
return super.onInterceptTouchEvent(event);
case (MotionEvent.ACTION_MOVE):
if (!swipingAllowed) {
return false;
}
return super.onInterceptTouchEvent(event);
case (MotionEvent.ACTION_UP):
if (!swipingAllowed) {
return false;
}
return super.onInterceptTouchEvent(event);
default:
return super.onInterceptTouchEvent(event);
}
}Example 21
| Project: meetup-client-master File: PhotoViewPager.java View source code |
public boolean onInterceptTouchEvent(MotionEvent motionevent) {
boolean flag;
boolean flag1;
boolean flag2 = false;
InterceptType intercepttype;
int i;
if (mListener != null)
intercepttype = mListener.onTouchIntercept(mActivatedX, mActivatedY);
else
intercepttype = InterceptType.NONE;
if (intercepttype == InterceptType.BOTH || intercepttype == InterceptType.LEFT)
flag = true;
else
flag = false;
if (intercepttype == InterceptType.BOTH || intercepttype == InterceptType.RIGHT)
flag1 = true;
else
flag1 = false;
i = 0xff & motionevent.getAction();
if (i == 3 || i == 1)
mActivePointerId = -1;
if (0 == i) {
mLastMotionX = motionevent.getX();
mActivatedX = motionevent.getRawX();
mActivatedY = motionevent.getRawY();
mActivePointerId = MotionEventCompat.getPointerId(motionevent, 0);
} else if (2 == i) {
if (!flag && !flag1)
return flag2;
int l = mActivePointerId;
if (l == -1)
return flag2;
float f = MotionEventCompat.getX(motionevent, MotionEventCompat.findPointerIndex(motionevent, l));
if (flag && flag1) {
mLastMotionX = f;
flag2 = false;
} else if (flag && f > mLastMotionX) {
mLastMotionX = f;
flag2 = false;
} else {
if (!flag1 || f >= mLastMotionX)
return flag2;
mLastMotionX = f;
flag2 = false;
}
} else if (6 == i) {
int j = MotionEventCompat.getActionIndex(motionevent);
if (MotionEventCompat.getPointerId(motionevent, j) == mActivePointerId) {
int k;
if (j == 0)
k = 1;
else
k = 0;
mLastMotionX = MotionEventCompat.getX(motionevent, k);
mActivePointerId = MotionEventCompat.getPointerId(motionevent, k);
}
flag2 = super.onInterceptTouchEvent(motionevent);
} else {
flag2 = super.onInterceptTouchEvent(motionevent);
}
return flag2;
}Example 22
| Project: MvpApp-master File: PullScrollView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch(MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_MOVE:
if (!mIsPullStatus) {
if (getScrollY() >= (getChildAt(0).getMeasuredHeight() - getHeight()) || getChildAt(0).getMeasuredHeight() < getHeight()) {
if (mPullListener != null && mPullListener.isDoPull()) {
mIsPullStatus = true;
mLastY = ev.getY();
}
}
} else if (mLastY < ev.getY()) {
mIsPullStatus = false;
_pullFootView(0);
} else {
float offsetY = mLastY - ev.getY();
_pullFootView(offsetY);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mIsPullStatus) {
if (mFootView.getHeight() > mPullCriticalDistance && mPullListener != null) {
if (!mPullListener.handlePull()) {
AnimateHelper.doClipViewHeight(mFootView, mFootView.getHeight(), 0, 200);
}
} else {
AnimateHelper.doClipViewHeight(mFootView, mFootView.getHeight(), 0, 200);
}
mIsPullStatus = false;
}
break;
}
return super.onTouchEvent(ev);
}Example 23
| Project: OAK-master File: EdgeyViewPager.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (getCurrentItem() == getAdapter().getCount() - 1) {
final int action = ev.getAction();
float x = ev.getX();
switch(action & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
mStartDragX = x;
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
if (x < mStartDragX) {
mListener.onSwipeOutAtEnd();
} else {
mStartDragX = 0;
}
break;
}
} else if (ev.getAction() != MotionEvent.ACTION_UP && ev.getX() < mEdgeSize) {
return false;
} else {
mStartDragX = 0;
}
return super.onTouchEvent(ev);
}Example 24
| Project: AisenWeiBo-master File: TimelineDetailScrollView.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (refreshView != null) {
boolean canChildScrollUp = ViewCompat.canScrollVertically(refreshView, -1);
// Logger.d(TAG, String.format("canChildScrollUp = %s", String.valueOf(canChildScrollUp)));
if (canChildScrollUp) {
return false;
}
}
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
final float initialMotionY = getMotionEventY(ev, mActivePointerId);
if (initialMotionY == -1) {
return false;
}
mInitialMotionY = initialMotionY;
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER) {
// Logger.e(TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
return false;
}
final float y = getMotionEventY(ev, mActivePointerId);
if (y == -1) {
return false;
}
final float yDiff = y - mInitialMotionY;
if (yDiff < 0) {
if (getChildAt(0).getHeight() <= getHeight() + getScrollY()) {
return false;
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mActivePointerId = INVALID_POINTER;
break;
}
return super.onInterceptTouchEvent(ev);
}Example 25
| Project: Android-ItemTouchHelper-Demo-master File: RecyclerListAdapter.java View source code |
@Override
public void onBindViewHolder(final ItemViewHolder holder, int position) {
holder.textView.setText(mItems.get(position));
// Start a drag whenever the handle view it touched
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragStartListener.onStartDrag(holder);
}
return false;
}
});
}Example 26
| Project: AndroidFine-master File: AutoLoopViewPager.java View source code |
/**
* <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 dispatchTouchEvent(MotionEvent ev) {
int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_DOWN) {
stopAutoScroll();
} else if (ev.getAction() == MotionEvent.ACTION_UP) {
startAutoScroll();
}
getParent().requestDisallowInterceptTouchEvent(true);
return super.dispatchTouchEvent(ev);
}Example 27
| Project: AndroidSamples-master File: ItemTouchHelperActivity.java View source code |
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.textView.setText(mItems.get(position));
holder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
itemTouchHelper.startDrag(holder);
}
return false;
}
});
}Example 28
| Project: androidui-master File: MyImageView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent e) {
final boolean canScrollVertically = true;
final MotionEvent vtev = MotionEvent.obtain(e);
final int action = MotionEventCompat.getActionMasked(e);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsets[0] = mNestedOffsets[1] = 0;
}
vtev.offsetLocation(mNestedOffsets[0], mNestedOffsets[1]);
switch(action) {
case MotionEvent.ACTION_DOWN:
{
mScrollPointerId = MotionEventCompat.getPointerId(e, 0);
mLastTouchY = (int) (e.getY() + 0.5f);
int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE;
if (canScrollVertically) {
nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL;
}
startNestedScroll(nestedScrollAxis);
}
break;
case MotionEvent.ACTION_MOVE:
{
final int index = MotionEventCompat.findPointerIndex(e, mScrollPointerId);
if (index < 0) {
return false;
}
final int y = (int) (MotionEventCompat.getY(e, index) + 0.5f);
int dx = 0;
int dy = mLastTouchY - y;
dispatchNestedPreScroll(dx, dy, mScrollConsumed, mScrollOffset);
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
stopNestedScroll();
break;
}
vtev.recycle();
return true;
}Example 29
| Project: awesome-blogs-android-master File: NestedWebView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean returnValue = false;
MotionEvent event = MotionEvent.obtain(ev);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsetY = 0;
}
int eventY = (int) event.getY();
event.offsetLocation(0, mNestedOffsetY);
switch(action) {
case MotionEvent.ACTION_MOVE:
int deltaY = mLastY - eventY;
// NestedPreScroll
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
mLastY = eventY - mScrollOffset[1];
event.offsetLocation(0, -mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
}
returnValue = super.onTouchEvent(event);
// NestedScroll
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
event.offsetLocation(0, mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
mLastY -= mScrollOffset[1];
}
break;
case MotionEvent.ACTION_DOWN:
returnValue = super.onTouchEvent(event);
mLastY = eventY;
// start NestedScroll
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
returnValue = super.onTouchEvent(event);
// end NestedScroll
stopNestedScroll();
break;
}
return returnValue;
}Example 30
| Project: code-reader-master File: NestedScrollWebView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean result = false;
MotionEvent trackedEvent = MotionEvent.obtain(event);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedYOffset = 0;
}
int y = (int) event.getY();
event.offsetLocation(0, mNestedYOffset);
switch(action) {
case MotionEvent.ACTION_DOWN:
mLastMotionY = y;
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
result = super.onTouchEvent(event);
break;
case MotionEvent.ACTION_MOVE:
int deltaY = mLastMotionY - y;
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
int oldY = getScrollY();
mLastMotionY = y - mScrollOffset[1];
if (deltaY < 0) {
int newScrollY = Math.max(0, oldY + deltaY);
deltaY -= newScrollY - oldY;
if (dispatchNestedScroll(0, newScrollY - deltaY, 0, deltaY, mScrollOffset)) {
mLastMotionY -= mScrollOffset[1];
trackedEvent.offsetLocation(0, mScrollOffset[1]);
mNestedYOffset += mScrollOffset[1];
}
}
trackedEvent.recycle();
result = super.onTouchEvent(trackedEvent);
break;
case MotionEvent.ACTION_POINTER_DOWN:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
stopNestedScroll();
result = super.onTouchEvent(event);
break;
}
return result;
}Example 31
| Project: FancyProgress-master File: FancyProgress4.java View source code |
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(MotionEventCompat.getActionMasked(event)) {
case MotionEvent.ACTION_DOWN:
mStartX = event.getRawX();
break;
case MotionEvent.ACTION_MOVE:
float distance = event.getRawX() - mStartX;
long playTime = (long) ((distance * 20) % (mOneShotDuration * 4));
mAnim.setCurrentPlayTime(playTime);
break;
case MotionEvent.ACTION_UP:
break;
default:
break;
}
return true;
}Example 32
| Project: FastHub-master File: NestedWebView.java View source code |
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent ev) {
boolean returnValue;
MotionEvent event = MotionEvent.obtain(ev);
final int action = MotionEventCompat.getActionMasked(event);
if (action == MotionEvent.ACTION_DOWN) {
mNestedOffsetY = 0;
}
int eventY = (int) event.getY();
event.offsetLocation(0, mNestedOffsetY);
switch(action) {
case MotionEvent.ACTION_MOVE:
int deltaY = mLastY - eventY;
// NestedPreScroll
if (dispatchNestedPreScroll(0, deltaY, mScrollConsumed, mScrollOffset)) {
deltaY -= mScrollConsumed[1];
mLastY = eventY - mScrollOffset[1];
event.offsetLocation(0, -mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
}
returnValue = super.onTouchEvent(event);
// NestedScroll
if (dispatchNestedScroll(0, mScrollOffset[1], 0, deltaY, mScrollOffset)) {
event.offsetLocation(0, mScrollOffset[1]);
mNestedOffsetY += mScrollOffset[1];
mLastY -= mScrollOffset[1];
}
break;
case MotionEvent.ACTION_DOWN:
returnValue = super.onTouchEvent(event);
if (firstScroll) {
mLastY = eventY - 5;
firstScroll = false;
} else {
mLastY = eventY;
}
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
default:
returnValue = super.onTouchEvent(event);
// end NestedScroll
stopNestedScroll();
break;
}
return returnValue;
}Example 33
| Project: GithubTrends-master File: CustomLanguageAdapter.java View source code |
@Override
public void onBindViewHolder(final ViewHolder viewHolder, int position) {
final Language language = mItems.get(position);
viewHolder.text.setText(language.name);
// Start a drag whenever the handle view it touched
viewHolder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragStartListener.onStartDrag(viewHolder);
}
return false;
}
});
viewHolder.removeView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int index = mItems.indexOf(language);
if (index >= 0) {
if (mItems.size() > 1) {
mItems.remove(index);
notifyItemRemoved(index);
} else {
ConfirmDialog confirmDialog = ConfirmDialog.newInstance("Invalid Operation", "You should keep at least one language.", 0, -1);
confirmDialog.show(((AppCompatActivity) context).getSupportFragmentManager(), "confirm");
}
}
}
});
switch(mode) {
case Constants.MODE_DRAGGABLE:
viewHolder.handleView.setVisibility(View.VISIBLE);
viewHolder.removeView.setVisibility(View.GONE);
break;
case Constants.MODE_REMOVE:
viewHolder.handleView.setVisibility(View.GONE);
viewHolder.removeView.setVisibility(View.VISIBLE);
break;
}
}Example 34
| Project: kasahorow-Keyboard-For-Android-master File: AskV8GestureDetector.java View source code |
@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
int singleFingerEventPointerId = mSingleFingerEventPointerId;
//I want to keep track on the first finger (https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300)
switch(MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_DOWN:
if (ev.getPointerCount() == 1) {
mSingleFingerEventPointerId = ev.getPointerId(0);
singleFingerEventPointerId = mSingleFingerEventPointerId;
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (ev.getPointerCount() == 1)
mSingleFingerEventPointerId = NOT_A_POINTER_ID;
}
try {
//https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/26
mScaleGestureDetector.onTouchEvent(ev);
} catch (IllegalArgumentException e) {
} catch (ArrayIndexOutOfBoundsException e) {
}
//https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/300
if (ev.getPointerCount() == 1 && ev.getPointerId(0) == singleFingerEventPointerId)
return super.onTouchEvent(ev);
else
return false;
}Example 35
| Project: MaterialDesignExample-master File: RefreshLayout.java View source code |
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (!isEnabled() || canChildScrollDown()) {
// Fail fast if we're not in a state where a swipe is possible
return super.dispatchTouchEvent(ev);
}
switch(action) {
case MotionEvent.ACTION_DOWN:
mIsBeingDragged = false;
mInitialDownY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
{
final float y = ev.getY();
final float overscrollTop = (mInitialDownY - y) * DRAG_RATE;
if (overscrollTop > mTouchSlop) {
mIsBeingDragged = true;
if (!isLoading) {
isLoading = true;
setProgressViewOffset(true, getBottom() - mCircleView.getHeight(), (int) (getBottom() - mCircleView.getHeight() - mTotalDragDistance));
}
moveSpinner(overscrollTop);
return true;
}
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
{
if (mIsBeingDragged) {
final float y = ev.getY();
final float overscrollTop = (mInitialDownY - y) * DRAG_RATE;
mIsBeingDragged = false;
finishSpinner(overscrollTop);
return true;
}
}
}
return super.dispatchTouchEvent(ev);
}Example 36
| Project: platform_frameworks_support-master File: AbsActionBarView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
// ActionBarViews always eat touch events, but should still respect the touch event dispatch
// contract. If the normal View implementation doesn't want the events, we'll just silently
// eat the rest of the gesture without reporting the events to the default implementation
// since that's what it expects.
final int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_DOWN) {
mEatingTouch = false;
}
if (!mEatingTouch) {
final boolean handled = super.onTouchEvent(ev);
if (action == MotionEvent.ACTION_DOWN && !handled) {
mEatingTouch = true;
}
}
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
mEatingTouch = false;
}
return true;
}Example 37
| Project: react-native-navigation-master File: CollapsingTopBarReactHeader.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
switch(action) {
case MotionEvent.ACTION_CANCEL:
releaseScroll(ev);
break;
case MotionEvent.ACTION_UP:
releaseScroll(ev);
break;
case MotionEvent.ACTION_DOWN:
onTouchDown(ev);
break;
case MotionEvent.ACTION_MOVE:
{
if (mIsScrolling) {
return true;
}
if (calculateDistanceY(ev) > mTouchSlop) {
mIsScrolling = true;
return true;
}
break;
}
default:
break;
}
return false;
}Example 38
| Project: ScrollableSlidingUpPaneLayout-master File: ScrollableSlidingUpPaneLayoutHelper.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
final int action = MotionEventCompat.getActionMasked(event);
if (mTargetView instanceof SlideableScrollView && ((SlideableScrollView) mTargetView).isReadyForPull(mTargetView, event.getX(), event.getY()) && !mIsReadyToPullChecked) {
// ScrollView will skip Action_down event, this is to fix this problem
mInitialY = ((SlideableScrollView) mTargetView).mInitialY;
}
switch(action) {
case MotionEvent.ACTION_DOWN:
if (mViewDelegate.isReadyForPull(v, event.getX(), event.getY())) {
mInitialY = (int) event.getY();
}
break;
case MotionEvent.ACTION_MOVE:
if (mInitialY > 0) {
int yDiff = mInitialY - (int) event.getY();
if (yDiff < mTouchSlop) {
enableSlidingPane();
resetTouch();
}
}
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
resetTouch();
}
return false;
}Example 39
| Project: sdk-support-master File: SwipeToDismissActivity.java View source code |
@Override
public ItemTouchViewHolder onCreateViewHolder(ViewGroup parent) {
final ItemTouchViewHolder vh = super.onCreateViewHolder(parent);
vh.actionButton.setText(R.string.swipe);
vh.actionButton.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mItemTouchHelper.startSwipe(vh);
}
return false;
}
});
return vh;
}Example 40
| Project: SyncthingAndroid-master File: DragSwipeAdapterWrapper.java View source code |
@Override
public void onBindViewHolder(final VH viewHolder, int i) {
wrappedAdapter.onBindViewHolder(viewHolder, i);
// Start a drag whenever the handle view it touched
if (viewHolder instanceof DragSwipeViewHolder) {
DragSwipeViewHolder vh = (DragSwipeViewHolder) viewHolder;
vh.getDragHandle().setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
itemTouchHelper.startDrag(viewHolder);
}
return false;
}
});
}
}Example 41
| Project: AdvancedRecyclerView-master File: RecyclerViewTouchActionGuardManager.java View source code |
/*package*/
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (!mEnabled) {
return false;
}
final int action = MotionEventCompat.getActionMasked(e);
if (LOCAL_LOGV) {
Log.v(TAG, "onInterceptTouchEvent() action = " + action);
}
switch(action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
handleActionUpOrCancel();
break;
case MotionEvent.ACTION_DOWN:
handleActionDown(e);
break;
case MotionEvent.ACTION_MOVE:
if (handleActionMove(rv, e)) {
return true;
}
break;
}
return false;
}Example 42
| Project: AisenWeiBo-master-master File: ProfileScrollView.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (refreshView != null) {
boolean canChildScrollUp = ViewCompat.canScrollVertically(refreshView, -1);
Logger.d(TAG, String.format("canChildScrollUp = %s", String.valueOf(canChildScrollUp)));
if (canChildScrollUp) {
return false;
}
}
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
final float initialMotionY = getMotionEventY(ev, mActivePointerId);
if (initialMotionY == -1) {
return false;
}
mInitialMotionY = initialMotionY;
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER) {
Logger.e(TAG, "Got ACTION_MOVE event but don't have an active pointer id.");
return false;
}
final float y = getMotionEventY(ev, mActivePointerId);
if (y == -1) {
return false;
}
final float yDiff = y - mInitialMotionY;
if (yDiff < 0) {
if (getChildAt(0).getMeasuredHeight() <= getHeight() + getScrollY()) {
return false;
}
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
mActivePointerId = INVALID_POINTER;
break;
}
return super.onInterceptTouchEvent(ev);
}Example 43
| Project: AiStore-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
return super.onTouchEvent(ev);
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 44
| Project: android-advancedrecyclerview-master File: RecyclerViewTouchActionGuardManager.java View source code |
/*package*/
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (!mEnabled) {
return false;
}
final int action = MotionEventCompat.getActionMasked(e);
if (LOCAL_LOGV) {
Log.v(TAG, "onInterceptTouchEvent() action = " + action);
}
switch(action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
handleActionUpOrCancel();
break;
case MotionEvent.ACTION_DOWN:
handleActionDown(e);
break;
case MotionEvent.ACTION_MOVE:
if (handleActionMove(rv, e)) {
return true;
}
break;
}
return false;
}Example 45
| Project: Android-Next-master File: MotionTrackListView.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = MotionEventCompat.getActionMasked(ev);
switch(action) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_MOVE:
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
break;
default:
break;
}
return super.onInterceptTouchEvent(ev);
}Example 46
| Project: Android-Studio-Project-master File: YoutubeLayout.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
final float x = ev.getX();
final float y = ev.getY();
boolean interceptTap = false;
switch(action) {
case MotionEvent.ACTION_DOWN:
mInitialMotionX = x;
mInitialMotionY = y;
interceptTap = mDragHelper.isViewUnder(mHeaderView, (int) x, (int) y);
break;
case MotionEvent.ACTION_MOVE:
final float adx = Math.abs(x - mInitialMotionX);
final float ady = Math.abs(y - mInitialMotionY);
//滑动的最��离
final int slop = mDragHelper.getTouchSlop();
if (ady > slop && adx > ady) {
mDragHelper.cancel();
return false;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mDragHelper.cancel();
return false;
}
return mDragHelper.shouldInterceptTouchEvent(ev) || interceptTap;
}Example 47
| Project: android2048-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
// return super.onTouchEvent(ev);
// try to cancel the touch event
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
onTouchEvent(cancelEvent);
return true;
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 48
| Project: AndroidMSamples-master File: SampleAdapter.java View source code |
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.mTextView.setText(mValues.get(position));
// Start a drag whenever the handle view it touched
holder.mHandleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragStartListener.onStartDrag(holder);
}
return false;
}
});
Glide.with(holder.mImageView.getContext()).load(mDrawables.get(position)).into(holder.mImageView);
}Example 49
| Project: Android_RssReader-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
// return super.onTouchEvent(ev);
// try to cancel the touch event
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
onTouchEvent(cancelEvent);
return true;
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchView.getMenuView(), mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null && mTouchView != null) {
mOnSwipeListener.onSwipeEnd(mTouchView.getMenuView(), mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 50
| Project: Bingo-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
return super.onTouchEvent(ev);
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 51
| Project: bosi-android-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
return super.onTouchEvent(ev);
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 52
| Project: ChromeLikeSwipeLayout-master File: TouchManager.java View source code |
private void onSecondaryPointerUp(MotionEvent ev) {
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
// This was our active pointer going up. Choose a new
// active pointer and adjust accordingly.
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
setActivePointerId(ev, newPointerIndex);
}
}Example 53
| Project: Dribble-master File: SwipeHoverLayout.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int actionMasked = MotionEventCompat.getActionMasked(ev);
boolean flag = false;
switch(actionMasked) {
case MotionEvent.ACTION_DOWN:
mDownX = (int) ev.getX();
mGestureDetector.onTouchEvent(ev);
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(ev.getX() - mDownX) > mTouchSlop)
flag = true;
break;
}
return flag;
}Example 54
| Project: epub3reader-master File: BookView.java View source code |
// Change page
protected void swipePage(View v, MotionEvent event, int book) {
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case (MotionEvent.ACTION_DOWN):
swipeOriginX = event.getX();
swipeOriginY = event.getY();
break;
case (MotionEvent.ACTION_UP):
int quarterWidth = (int) (screenWidth * 0.25);
float diffX = swipeOriginX - event.getX();
float diffY = swipeOriginY - event.getY();
float absDiffX = Math.abs(diffX);
float absDiffY = Math.abs(diffY);
if ((diffX > quarterWidth) && (absDiffX > absDiffY)) {
try {
navigator.goToNextChapter(index);
} catch (Exception e) {
errorMessage(getString(R.string.error_cannotTurnPage));
}
} else if ((diffX < -quarterWidth) && (absDiffX > absDiffY)) {
try {
navigator.goToPrevChapter(index);
} catch (Exception e) {
errorMessage(getString(R.string.error_cannotTurnPage));
}
}
break;
}
}Example 55
| Project: ExSample-master File: ScaleDragDetector.java View source code |
private void onTouchActivePointer(int action, MotionEvent ev) {
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
}
break;
}
mActivePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}Example 56
| Project: itemtouchhelper-extension-master File: MainRecyclerAdapter.java View source code |
public void bind(TestModel testModel) {
mTextTitle.setText(testModel.title);
mTextIndex.setText("#" + testModel.position);
itemView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mItemTouchHelperExtension.startDrag(ItemBaseViewHolder.this);
}
return true;
}
});
}Example 57
| Project: jzgs-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
return super.onTouchEvent(ev);
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 58
| Project: MusicDNA-master File: PlaylistTrackAdapter.java View source code |
@Override
public void onBindViewHolder(final PlaylistTrackAdapter.MyViewHolder holder, int position) {
UnifiedTrack ut = songList.get(position);
if (ut.getType()) {
LocalTrack lt = ut.getLocalTrack();
imgLoader.DisplayImage(lt.getPath(), holder.art);
holder.title.setText(lt.getTitle());
holder.artist.setText(lt.getArtist());
} else {
Track t = ut.getStreamTrack();
Picasso.with(ctx).load(t.getArtworkURL()).resize(100, 100).error(R.drawable.ic_default).placeholder(R.drawable.ic_default).into(holder.art);
holder.title.setText(t.getTitle());
holder.artist.setText("");
}
holder.holderImg.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragStartListener.onDragStarted(holder);
}
return false;
}
});
}Example 59
| Project: nices-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
return super.onTouchEvent(ev);
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 60
| Project: OpenCVTour-master File: RecyclerViewTouchActionGuardManager.java View source code |
/*package*/
boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
if (!mEnabled) {
return false;
}
final int action = MotionEventCompat.getActionMasked(e);
if (LOCAL_LOGV) {
Log.v(TAG, "onInterceptTouchEvent() action = " + action);
}
switch(action) {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
handleActionUpOrCancel();
break;
case MotionEvent.ACTION_DOWN:
handleActionDown(e);
break;
case MotionEvent.ACTION_MOVE:
if (handleActionMove(rv, e)) {
return true;
}
break;
}
return false;
}Example 61
| Project: Ouroboros-master File: NavigationBoardListAdapter.java View source code |
@Override
public void onBindViewHolderCursor(final RecyclerView.ViewHolder holder, Cursor cursor) {
final NavigationBoardListViewHolder navigationBoardListViewHolder = (NavigationBoardListViewHolder) holder;
navigationBoardListViewHolder.handleView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
dragStartListener.onStartDrag(navigationBoardListViewHolder);
}
return false;
}
});
navigationBoardListViewHolder.boardObject.boardName = cursor.getString(cursor.getColumnIndex(DbContract.BoardEntry.COLUMN_BOARDS));
navigationBoardListViewHolder.boardObject.boardOrder = cursor.getInt(cursor.getColumnIndex(DbContract.BoardEntry.BOARD_ORDER));
navigationBoardListViewHolder.boardNameBtn.setText("/" + navigationBoardListViewHolder.boardObject.boardName + "/");
}Example 62
| Project: PandaEye-master File: AutoScrollViewPager.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch(MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_DOWN:
getParent().requestDisallowInterceptTouchEvent(true);
stopAutoScroll();
break;
case MotionEvent.ACTION_UP:
getParent().requestDisallowInterceptTouchEvent(false);
startAutoScroll();
break;
}
return super.onTouchEvent(ev);
}Example 63
| Project: PhotoDraweeView-master File: ScaleDragDetector.java View source code |
private void onTouchActivePointer(int action, MotionEvent ev) {
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
}
break;
}
mActivePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}Example 64
| Project: Qmusic-master File: BSwipeView2.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
int action = MotionEventCompat.getActionMasked(ev);
final float x = ev.getX();
final float y = ev.getY();
if (isEnabled() && swipeMode != SWIPE_MODE_NONE) {
switch(action) {
case MotionEvent.ACTION_MOVE:
// Log.d(TAG, "onInterceptTouchEvent:move");
swiping = checkInMoving(x, y);
if (swiping) {
touchState = TOUCH_STATE_SCROLLING_X;
return true;
} else {
return false;
}
case MotionEvent.ACTION_DOWN:
Log.d(TAG, "onInterceptTouchEvent:down");
if (backView == null || frontView == null) {
backView = this.getChildAt(0);
frontView = this.getChildAt(1);
}
touchState = TOUCH_STATE_REST;
lastMotionX = x;
lastMotionY = y;
return false;
case MotionEvent.ACTION_CANCEL:
Log.d(TAG, "onInterceptTouchEvent:cancel");
touchState = TOUCH_STATE_REST;
break;
case MotionEvent.ACTION_UP:
Log.d(TAG, "onInterceptTouchEvent:up");
return touchState == TOUCH_STATE_SCROLLING_X;
default:
// Log.d(TAG, "onInterceptTouchEvent:default");
break;
}
}
return super.onInterceptTouchEvent(ev);
}Example 65
| Project: RecyclerViewUndoSwipe-master File: ItemAdapter.java View source code |
@Override
public void onBindViewHolder(final ItemViewHolder itemViewHolder, final int position) {
final Item item = itemList.get(position);
itemViewHolder.tvItemName.setText(item.getItemName());
itemViewHolder.relativeReorder.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
dragStartListener.onStartDrag(itemViewHolder);
}
return false;
}
});
}Example 66
| Project: selendroid-master File: TouchGesturesActivity.java View source code |
@Override
public boolean onTouchEvent(MotionEvent event) {
clearExtraInformationTextViews();
scaleDetector.onTouchEvent(event);
// Check if multitouch action or single touch based on pointer count.
if (event.getPointerCount() > 1) {
clearExtraInformationTextViews();
gestureTypeTV.setText("MULTI TOUCH EVENT");
textView3.setText("Num Pointers: " + event.getPointerCount());
int action = MotionEventCompat.getActionMasked(event);
textView4.setText(actionToString(action));
int index = MotionEventCompat.getActionIndex(event);
textView5.setText("Pointer index: " + index);
} else
gestureDetect.onTouchEvent(event);
return true;
}Example 67
| Project: SprintNBA-master File: ScaleDragDetector.java View source code |
private void onTouchActivePointer(int action, MotionEvent ev) {
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
}
break;
}
mActivePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}Example 68
| Project: SwipeMenuListView-master-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
mTouchView.smoothCloseMenu();
mTouchView = null;
// return super.onTouchEvent(ev);
// try to cancel the touch event
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
onTouchEvent(cancelEvent);
return true;
}
if (view instanceof SwipeMenuLayout) {
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
getSelector().setState(new int[] { 0 });
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 69
| Project: syng-client-master File: ProfileDrawerAdapter.java View source code |
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder instanceof SimpleViewHolder) {
// -1 because of the header
final Profile profile = mDataSet.get(position - 1);
final SimpleViewHolder myHolder = (SimpleViewHolder) holder;
myHolder.setting.setVisibility(mEditModeEnabled ? View.VISIBLE : View.GONE);
myHolder.reorder.setVisibility(mEditModeEnabled ? View.VISIBLE : View.GONE);
Glide.with(mContext).load(R.drawable.profile).into(myHolder.profileIcon);
myHolder.nameTextView.setText(profile.getName());
myHolder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mEditModeEnabled) {
if (mProfileClickListener != null) {
mProfileClickListener.onProfileClick(profile);
}
} else {
setEditModeEnabled(false);
}
}
});
myHolder.view.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
mEditModeEnabled = !mEditModeEnabled;
notifyDataSetChanged();
return true;
}
});
myHolder.setting.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mProfileClickListener != null) {
mProfileClickListener.onProfileEdit(profile);
}
}
});
myHolder.reorder.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
mDragListener.onStartDrag(myHolder);
}
return false;
}
});
}
if (holder instanceof HeaderViewHolder) {
HeaderViewHolder myHolder = (HeaderViewHolder) holder;
myHolder.view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mProfileClickListener != null) {
mProfileClickListener.onProfileAdd();
}
}
});
}
}Example 70
| Project: TarMediaPlayer-as-master File: PlaylistSongCursorAdapter.java View source code |
@Override
public boolean onTouch(View v, @NonNull MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
startDragListener.onStartDrag(holder);
isMove = true;
playlistId = songCursor.getInt(songCursor.getColumnIndexOrThrow(MediaStore.Audio.Playlists.Members.PLAYLIST_ID));
}
return false;
}Example 71
| Project: TLint-master File: ScaleDragDetector.java View source code |
private void onTouchActivePointer(int action, MotionEvent ev) {
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = ev.getPointerId(0);
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
mActivePointerId = INVALID_POINTER_ID;
break;
case MotionEvent.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = (pointerIndex == 0) ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
mLastTouchX = MotionEventCompat.getX(ev, newPointerIndex);
mLastTouchY = MotionEventCompat.getY(ev, newPointerIndex);
}
break;
}
mActivePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId != INVALID_POINTER_ID ? mActivePointerId : 0);
}Example 72
| Project: UltimateRecyclerView-master File: SimpleAdapter.java View source code |
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (position < getItemCount() && (customHeaderView != null ? position <= stringList.size() : position < stringList.size()) && (customHeaderView != null ? position > 0 : true)) {
((ViewHolder) holder).textViewSample.setText(stringList.get(customHeaderView != null ? position - 1 : position));
// ((ViewHolder) holder).itemView.setActivated(selectedItems.get(position, false));
if (mDragStartListener != null) {
// ((ViewHolder) holder).imageViewSample.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View v, MotionEvent event) {
// if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
// mDragStartListener.onStartDrag(holder);
// }
// return false;
// }
// });
((ViewHolder) holder).item_view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
}
}
}Example 73
| Project: AFBaseLibrary-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 74
| Project: android-betterpickers-master File: UnderlinePageIndicatorPicker.java View source code |
public boolean onTouchEvent(MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false;
}
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mLastMotionX = ev.getX();
break;
case MotionEvent.ACTION_MOVE:
{
final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = x - mLastMotionX;
if (!mIsDragging) {
if (Math.abs(deltaX) > mTouchSlop) {
mIsDragging = true;
}
}
if (mIsDragging) {
mLastMotionX = x;
if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
mViewPager.fakeDragBy(deltaX);
}
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsDragging) {
final int count = mViewPager.getAdapter().getCount();
final int width = getWidth();
final float halfWidth = width / 2f;
final float sixthWidth = width / 6f;
if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage - 1);
}
return true;
} else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage + 1);
}
return true;
}
}
mIsDragging = false;
mActivePointerId = INVALID_POINTER;
if (mViewPager.isFakeDragging()) {
mViewPager.endFakeDrag();
}
break;
case MotionEventCompat.ACTION_POINTER_DOWN:
{
final int index = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, index);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
break;
}
return true;
}Example 75
| Project: android-sdk-sources-for-api-level-23-master File: PhotoViewPager.java View source code |
/**
* {@inheritDoc}
* <p>
* We intercept touch event intercepts so we can prevent switching views when the
* current view is internally scrollable.
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY) : InterceptType.NONE;
final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);
// Only check ability to page if we can't scroll in one / both directions
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
mActivePointerId = INVALID_POINTER;
}
switch(action) {
case MotionEvent.ACTION_MOVE:
{
if (ignoreScrollLeft || ignoreScrollRight) {
final int activePointerId = mActivePointerId;
if (activePointerId == INVALID_POINTER) {
// If we don't have a valid id, the touch down wasn't on content.
break;
}
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
final float x = MotionEventCompat.getX(ev, pointerIndex);
if (ignoreScrollLeft && ignoreScrollRight) {
mLastMotionX = x;
return false;
} else if (ignoreScrollLeft && (x > mLastMotionX)) {
mLastMotionX = x;
return false;
} else if (ignoreScrollRight && (x < mLastMotionX)) {
mLastMotionX = x;
return false;
}
}
break;
}
case MotionEvent.ACTION_DOWN:
{
mLastMotionX = ev.getX();
// Use the raw x/y as the children can be located anywhere and there isn't a
// single offset that would be meaningful
mActivatedX = ev.getRawX();
mActivatedY = ev.getRawY();
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
{
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
// Our active pointer going up; select a new active pointer
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
break;
}
}
return super.onInterceptTouchEvent(ev);
}Example 76
| Project: android-smarterwifi-master File: UnderlinePageIndicatorPicker.java View source code |
public boolean onTouchEvent(MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false;
}
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mLastMotionX = ev.getX();
break;
case MotionEvent.ACTION_MOVE:
{
final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = x - mLastMotionX;
if (!mIsDragging) {
if (Math.abs(deltaX) > mTouchSlop) {
mIsDragging = true;
}
}
if (mIsDragging) {
mLastMotionX = x;
if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
mViewPager.fakeDragBy(deltaX);
}
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsDragging) {
final int count = mViewPager.getAdapter().getCount();
final int width = getWidth();
final float halfWidth = width / 2f;
final float sixthWidth = width / 6f;
if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage - 1);
}
return true;
} else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage + 1);
}
return true;
}
}
mIsDragging = false;
mActivePointerId = INVALID_POINTER;
if (mViewPager.isFakeDragging()) {
mViewPager.endFakeDrag();
}
break;
case MotionEventCompat.ACTION_POINTER_DOWN:
{
final int index = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, index);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
break;
}
return true;
}Example 77
| Project: BaseMoudle-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 78
| Project: BaseRecyclerViewAdapterHelper-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 79
| Project: betterpickers-master File: UnderlinePageIndicatorPicker.java View source code |
public boolean onTouchEvent(MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false;
}
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mLastMotionX = ev.getX();
break;
case MotionEvent.ACTION_MOVE:
{
final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = x - mLastMotionX;
if (!mIsDragging) {
if (Math.abs(deltaX) > mTouchSlop) {
mIsDragging = true;
}
}
if (mIsDragging) {
mLastMotionX = x;
if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
mViewPager.fakeDragBy(deltaX);
}
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsDragging) {
final int count = mViewPager.getAdapter().getCount();
final int width = getWidth();
final float halfWidth = width / 2f;
final float sixthWidth = width / 6f;
if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage - 1);
}
return true;
} else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage + 1);
}
return true;
}
}
mIsDragging = false;
mActivePointerId = INVALID_POINTER;
if (mViewPager.isFakeDragging()) {
mViewPager.endFakeDrag();
}
break;
case MotionEventCompat.ACTION_POINTER_DOWN:
{
final int index = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, index);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
break;
}
return true;
}Example 80
| Project: boardgamegeek4android-master File: NestedScrollWebView.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = ev.getAction();
if ((action == MotionEvent.ACTION_MOVE) && (isBeingDragged)) {
return true;
}
switch(action & MotionEventCompat.ACTION_MASK) {
case MotionEvent.ACTION_MOVE:
{
final int activePointerId = this.activePointerId;
if (activePointerId == INVALID_POINTER) {
break;
}
final int pointerIndex = ev.findPointerIndex(activePointerId);
if (pointerIndex == -1) {
Log.e(TAG, "Invalid pointerId=" + activePointerId + " in onInterceptTouchEvent");
break;
}
final int y = (int) ev.getY(pointerIndex);
final int yDiff = Math.abs(y - lastMotionY);
if (yDiff > touchSlop && (getNestedScrollAxes() & ViewCompat.SCROLL_AXIS_VERTICAL) == 0) {
isBeingDragged = true;
lastMotionY = y;
initVelocityTrackerIfNotExists();
velocityTracker.addMovement(ev);
nestedYOffset = 0;
final ViewParent parent = getParent();
if (parent != null) {
parent.requestDisallowInterceptTouchEvent(true);
}
}
break;
}
case MotionEvent.ACTION_DOWN:
{
lastMotionY = (int) ev.getY();
activePointerId = ev.getPointerId(0);
initOrResetVelocityTracker();
velocityTracker.addMovement(ev);
scroller.computeScrollOffset();
isBeingDragged = !scroller.isFinished();
startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
isBeingDragged = false;
activePointerId = INVALID_POINTER;
recycleVelocityTracker();
if (scroller.springBack(getScrollX(), getScrollY(), 0, 0, 0, getScrollRange())) {
ViewCompat.postInvalidateOnAnimation(this);
}
stopNestedScroll();
break;
case MotionEventCompat.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
}
return isBeingDragged;
}Example 81
| Project: demos-master File: HeaderBehavior.java View source code |
@Override
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent ev) {
if (mTouchSlop < 0) {
mTouchSlop = ViewConfiguration.get(parent.getContext()).getScaledTouchSlop();
}
final int action = ev.getAction();
// Shortcut since we're being dragged
if (action == MotionEvent.ACTION_MOVE && mIsBeingDragged) {
return true;
}
switch(MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_DOWN:
{
mIsBeingDragged = false;
final int x = (int) ev.getX();
final int y = (int) ev.getY();
if (canDragView(child) && parent.isPointInChildBounds(child, x, y)) {
mLastMotionY = y;
mActivePointerId = ev.getPointerId(0);
ensureVelocityTracker();
}
break;
}
case MotionEvent.ACTION_MOVE:
{
final int activePointerId = mActivePointerId;
if (activePointerId == INVALID_POINTER) {
// If we don't have a valid id, the touch down wasn't on content.
break;
}
final int pointerIndex = ev.findPointerIndex(activePointerId);
if (pointerIndex == -1) {
break;
}
final int y = (int) ev.getY(pointerIndex);
final int yDiff = Math.abs(y - mLastMotionY);
if (yDiff > mTouchSlop) {
mIsBeingDragged = true;
mLastMotionY = y;
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
{
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
if (mVelocityTracker != null) {
mVelocityTracker.recycle();
mVelocityTracker = null;
}
break;
}
}
if (mVelocityTracker != null) {
mVelocityTracker.addMovement(ev);
}
return mIsBeingDragged;
}Example 82
| Project: droidfish-master File: FrameLayoutWithHole.java View source code |
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
//first check if the location button should handle the touch event
dumpEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
if (mViewHole != null) {
int[] pos = new int[2];
mViewHole.getLocationOnScreen(pos);
Log.d("tourguide", "[dispatchTouchEvent] mViewHole.getHeight(): " + mViewHole.getHeight());
Log.d("tourguide", "[dispatchTouchEvent] mViewHole.getWidth(): " + mViewHole.getWidth());
Log.d("tourguide", "[dispatchTouchEvent] Touch X(): " + ev.getRawX());
Log.d("tourguide", "[dispatchTouchEvent] Touch Y(): " + ev.getRawY());
// Log.d("tourguide", "[dispatchTouchEvent] X of image: "+pos[0]);
// Log.d("tourguide", "[dispatchTouchEvent] Y of image: "+pos[1]);
Log.d("tourguide", "[dispatchTouchEvent] X lower bound: " + pos[0]);
Log.d("tourguide", "[dispatchTouchEvent] X higher bound: " + (pos[0] + mViewHole.getWidth()));
Log.d("tourguide", "[dispatchTouchEvent] Y lower bound: " + pos[1]);
Log.d("tourguide", "[dispatchTouchEvent] Y higher bound: " + (pos[1] + mViewHole.getHeight()));
if (ev.getRawY() >= pos[1] && ev.getRawY() <= (pos[1] + mViewHole.getHeight()) && ev.getRawX() >= pos[0] && ev.getRawX() <= (pos[0] + mViewHole.getWidth())) {
//location button event
Log.d("tourguide", "to the BOTTOM!");
Log.d("tourguide", "" + ev.getAction());
return false;
}
}
return super.dispatchTouchEvent(ev);
}Example 83
| Project: ExpandablePager-master File: SlidingContainer.java View source code |
private boolean translate(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
int stepSize = stopValues.size();
switch(action) {
case MotionEvent.ACTION_DOWN:
{
startYCoordinate = ev.getRawY();
translated = 0;
break;
}
case MotionEvent.ACTION_MOVE:
{
touchDelta = (startYCoordinate - ev.getRawY());
if (Math.abs(touchDelta) > slideThreshold) {
float startingPointY, nextPointY, maxDiff, tempDelta, auxDelta = 0;
tempDelta = touchDelta + (touchDelta < 0 ? 1 : -1) * slideThreshold;
startingPointY = stopValues.get(stopValueIndex);
if (!isUpwardGesture() && stopValueIndex >= 1) {
nextPointY = stopValues.get(stopValueIndex - 1);
maxDiff = nextPointY - stopValues.get(stopValueIndex);
auxDelta = Math.min(-tempDelta, maxDiff);
} else if (isUpwardGesture() && stopValueIndex < stepSize - 1) {
nextPointY = stopValues.get(stopValueIndex + 1);
maxDiff = nextPointY - stopValues.get(stopValueIndex);
auxDelta = Math.max(-tempDelta, maxDiff);
}
float preTranslated = translated;
translated = startingPointY + auxDelta;
setTranslationY(translated);
if (preTranslated != translated)
notifySlideEvent(translated);
return false;
}
return true;
}
case MotionEvent.ACTION_UP:
{
if (Math.abs(touchDelta) > slideThreshold) {
if (!isUpwardGesture() && stopValueIndex > 0)
stopValueIndex--;
else if (isUpwardGesture() && stopValueIndex < stepSize - 1)
stopValueIndex++;
if (!stopValues.contains(translated)) {
animate(stopValues.get(stopValueIndex));
} else
onSettled(stopValueIndex);
startYCoordinate = -1;
touchDelta = 0;
}
break;
}
case MotionEvent.ACTION_CANCEL:
{
break;
}
case MotionEvent.ACTION_POINTER_UP:
{
break;
}
}
return true;
}Example 84
| Project: fosdem-companion-android-master File: UnderlinePageIndicator.java View source code |
@Override
public boolean onTouchEvent(@NonNull MotionEvent ev) {
if (super.onTouchEvent(ev)) {
return true;
}
if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
return false;
}
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mLastMotionX = ev.getX();
break;
case MotionEvent.ACTION_MOVE:
{
final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
final float x = MotionEventCompat.getX(ev, activePointerIndex);
final float deltaX = x - mLastMotionX;
if (!mIsDragging) {
if (Math.abs(deltaX) > mTouchSlop) {
mIsDragging = true;
}
}
if (mIsDragging) {
mLastMotionX = x;
if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
mViewPager.fakeDragBy(deltaX);
}
}
break;
}
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
if (!mIsDragging) {
final int count = mViewPager.getAdapter().getCount();
final int width = getWidth();
final float halfWidth = width / 2f;
final float sixthWidth = width / 6f;
if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage - 1);
}
return true;
} else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
if (action != MotionEvent.ACTION_CANCEL) {
mViewPager.setCurrentItem(mCurrentPage + 1);
}
return true;
}
}
mIsDragging = false;
mActivePointerId = INVALID_POINTER;
if (mViewPager.isFakeDragging())
mViewPager.endFakeDrag();
break;
case MotionEventCompat.ACTION_POINTER_DOWN:
{
final int index = MotionEventCompat.getActionIndex(ev);
mLastMotionX = MotionEventCompat.getX(ev, index);
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
break;
}
return true;
}Example 85
| Project: GlassTunes-master File: BounceBackViewPager.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
try {
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
switch(action) {
case MotionEvent.ACTION_DOWN:
{
mLastMotionX = ev.getX();
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
break;
}
case MotionEventCompat.ACTION_POINTER_DOWN:
{
final int index = MotionEventCompat.getActionIndex(ev);
final float x = MotionEventCompat.getX(ev, index);
mLastMotionX = x;
mActivePointerId = MotionEventCompat.getPointerId(ev, index);
break;
}
}
return super.onInterceptTouchEvent(ev);
} catch (IllegalArgumentException e) {
e.printStackTrace();
return false;
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
return false;
}
}Example 86
| Project: InfiniteIndicator-master File: InfiniteIndicator.java View source code |
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (configuration == null) {
return super.dispatchTouchEvent(ev);
}
int action = MotionEventCompat.getActionMasked(ev);
if (configuration.isStopWhenTouch()) {
if ((action == MotionEvent.ACTION_DOWN) && isScrolling) {
isStopByTouch = true;
stop();
} else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
start();
}
}
return super.dispatchTouchEvent(ev);
}Example 87
| Project: InstagramGallery-master File: ZoomImageView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent event) {
if (detector != null)
detector.onTouchEvent(event);
// get the type of action associated with the event and switch on it
final int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case MotionEvent.ACTION_DOWN:
{
final int pointerIndex = MotionEventCompat.getActionIndex(event);
final float x = MotionEventCompat.getX(event, pointerIndex);
final float y = MotionEventCompat.getY(event, pointerIndex);
// save our last position and the pointer id
lastX = x;
lastY = y;
activePointerID = MotionEventCompat.getPointerId(event, pointerIndex);
break;
}
case MotionEvent.ACTION_MOVE:
{
// fetch the active pointer index
final int pointerIndex = MotionEventCompat.findPointerIndex(event, activePointerID);
final float x = MotionEventCompat.getX(event, pointerIndex);
final float y = MotionEventCompat.getY(event, pointerIndex);
// only move if not scaling?
if (detector != null && !detector.isInProgress()) {
final float dx = x - lastX;
final float dy = y - lastY;
// adjust canvas offset
offsetX += dx;
offsetY += dy;
// remember these new coordinates
lastX = x;
lastY = y;
invalidate();
}
break;
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
{
activePointerID = -1;
break;
}
case MotionEvent.ACTION_POINTER_UP:
{
// get pointer information
final int pointerIndex = MotionEventCompat.getActionIndex(event);
final int pointerID = MotionEventCompat.getPointerId(event, pointerIndex);
// if the pointer we were tracking was lifted, choose a new pointer
if (pointerID == activePointerID) {
final int newPointerIndex = (pointerIndex == 0 ? 1 : 0);
lastX = MotionEventCompat.getX(event, newPointerIndex);
lastY = MotionEventCompat.getY(event, newPointerIndex);
activePointerID = MotionEventCompat.getPointerId(event, newPointerIndex);
}
break;
}
}
fitToScreen();
return true;
}Example 88
| Project: JD-Test-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 89
| Project: likequanmintv-master File: AutoScrollViewPager.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
switch(MotionEventCompat.getActionMasked(ev)) {
case MotionEvent.ACTION_DOWN:
if (getCurrentItemOfWrapper() + 1 == getCountOfWrapper()) {
setCurrentItem(0, false);
} else if (getCurrentItemOfWrapper() == 0) {
setCurrentItem(getCount() - 1, false);
}
handler.removeMessages(MSG_AUTO_SCROLL);
mInitialMotionX = ev.getX();
mInitialMotionY = ev.getY();
break;
case MotionEvent.ACTION_MOVE:
mLastMotionX = ev.getX();
mLastMotionY = ev.getY();
if ((int) Math.abs(mLastMotionX - mInitialMotionX) > touchSlop || (int) Math.abs(mLastMotionY - mInitialMotionY) > touchSlop) {
mInitialMotionX = 0.0f;
mInitialMotionY = 0.0f;
}
break;
case MotionEvent.ACTION_UP:
if (autoScroll) {
startAutoScroll();
}
// Manually swipe not affected by scroll factor.
if (scroller != null) {
final double lastFactor = scroller.getFactor();
scroller.setFactor(1);
post(new Runnable() {
@Override
public void run() {
scroller.setFactor(lastFactor);
}
});
}
mLastMotionX = ev.getX();
mLastMotionY = ev.getY();
if ((int) mInitialMotionX != 0 && (int) mInitialMotionY != 0) {
if ((int) Math.abs(mLastMotionX - mInitialMotionX) < touchSlop && (int) Math.abs(mLastMotionY - mInitialMotionY) < touchSlop) {
mInitialMotionX = 0.0f;
mInitialMotionY = 0.0f;
mLastMotionX = 0.0f;
mLastMotionY = 0.0f;
if (onPageClickListener != null) {
onPageClickListener.onPageClick(this, getCurrentItem());
}
}
}
break;
}
return super.onTouchEvent(ev);
}Example 90
| Project: LuaViewSDK-master File: AutoScrollViewPager.java View source code |
/**
* <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>
*
* bugfix: å¢žåŠ ev.getAction() == MotionEvent.ACTION_CANCELæ?¡ä»¶åˆ¤æ–,Action Cancel事件å?‘生的时候也è¦?é‡?新开始自动滚动
*
*/
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
if (!canAutoScroll) {
return super.dispatchTouchEvent(ev);
}
int action = MotionEventCompat.getActionMasked(ev);
if (stopScrollWhenTouch) {
if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) {
isStopByTouch = true;
stopAutoScroll();
} else if ((ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) && isStopByTouch) {
startAutoScroll();
}
}
return super.dispatchTouchEvent(ev);
}Example 91
| Project: MVP-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 92
| Project: NIM_Android_Demo-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 93
| Project: NIM_Android_UIKit-master File: BaseItemDraggableAdapter.java View source code |
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN && !mDragOnLongPress) {
if (mItemTouchHelper != null && itemDragEnabled) {
mItemTouchHelper.startDrag((RecyclerView.ViewHolder) v.getTag(R.id.BaseQuickAdapter_viewholder_support));
}
return true;
} else {
return false;
}
}Example 94
| Project: osm-contributor-master File: PoiTypeTagAdapter.java View source code |
@Override
public void onBindViewHolder(final PoiTypeTagViewHolder holder, int position) {
holder.onBind(poiTypeTags.get(position));
holder.handle.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
startDragListener.onStartDrag(holder);
}
return false;
}
});
}Example 95
| Project: PowerAdapter-master File: SingleAdapter.java View source code |
protected void setTouchDragListener(final View view, final RecyclerView.ViewHolder viewHolder) {
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) {
if (mDragStartListener != null)
mDragStartListener.onStartDrag(viewHolder);
}
return false;
}
});
}Example 96
| Project: property-db-master File: PhotoViewPager.java View source code |
/**
* {@inheritDoc}
* <p>
* We intercept touch event intercepts so we can prevent switching views when the
* current view is internally scrollable.
*/
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final InterceptType intercept = (mListener != null) ? mListener.onTouchIntercept(mActivatedX, mActivatedY) : InterceptType.NONE;
final boolean ignoreScrollLeft = (intercept == InterceptType.BOTH || intercept == InterceptType.LEFT);
final boolean ignoreScrollRight = (intercept == InterceptType.BOTH || intercept == InterceptType.RIGHT);
// Only check ability to page if we can't scroll in one / both directions
final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
mActivePointerId = INVALID_POINTER;
}
switch(action) {
case MotionEvent.ACTION_MOVE:
{
if (ignoreScrollLeft || ignoreScrollRight) {
final int activePointerId = mActivePointerId;
if (activePointerId == INVALID_POINTER) {
// If we don't have a valid id, the touch down wasn't on content.
break;
}
final int pointerIndex = MotionEventCompat.findPointerIndex(ev, activePointerId);
final float x = MotionEventCompat.getX(ev, pointerIndex);
if (ignoreScrollLeft && ignoreScrollRight) {
mLastMotionX = x;
return false;
} else if (ignoreScrollLeft && (x > mLastMotionX)) {
mLastMotionX = x;
return false;
} else if (ignoreScrollRight && (x < mLastMotionX)) {
mLastMotionX = x;
return false;
}
}
break;
}
case MotionEvent.ACTION_DOWN:
{
mLastMotionX = ev.getX();
// Use the raw x/y as the children can be located anywhere and there isn't a
// single offset that would be meaningful
mActivatedX = ev.getRawX();
mActivatedY = ev.getRawY();
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
break;
}
case MotionEventCompat.ACTION_POINTER_UP:
{
final int pointerIndex = MotionEventCompat.getActionIndex(ev);
final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
if (pointerId == mActivePointerId) {
// Our active pointer going up; select a new active pointer
final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex);
mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
}
break;
}
}
return super.onInterceptTouchEvent(ev);
}Example 97
| Project: pulltorefreshView-master File: SwipeMenuListView.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
if (ev.getAction() != MotionEvent.ACTION_DOWN && mTouchView == null)
return super.onTouchEvent(ev);
int action = MotionEventCompat.getActionMasked(ev);
action = ev.getAction();
switch(action) {
case MotionEvent.ACTION_DOWN:
int oldPos = mTouchPosition;
mDownX = ev.getX();
mDownY = ev.getY();
mTouchState = TOUCH_STATE_NONE;
mTouchPosition = pointToPosition((int) ev.getX(), (int) ev.getY());
if (mTouchPosition == oldPos && mTouchView != null && mTouchView.isOpen()) {
//这次点击的item和上次点击的是å?Œä¸€ä¸ª(点击时上一个item还未关é—)
mTouchState = TOUCH_STATE_X;
mTouchView.onSwipe(ev);
return true;
}
View view = getChildAt(mTouchPosition - getFirstVisiblePosition());
if (mTouchView != null && mTouchView.isOpen()) {
//这次点击的item和上次点击的ä¸?是å?Œä¸€ä¸ª,并且上次点击的view还未关é—
//å…³é—上次点击的view
mTouchView.smoothCloseMenu();
mTouchView = null;
// return super.onTouchEvent(ev);
// try to cancel the touch event
MotionEvent cancelEvent = MotionEvent.obtain(ev);
cancelEvent.setAction(MotionEvent.ACTION_CANCEL);
onTouchEvent(cancelEvent);
return true;
}
if (view instanceof SwipeMenuLayout) {
//第一次点击或者点击过但上一个itemå·²ç»?å…³é—
mTouchView = (SwipeMenuLayout) view;
}
if (mTouchView != null) {
mTouchView.onSwipe(ev);
}
break;
case MotionEvent.ACTION_MOVE:
float dy = Math.abs((ev.getY() - mDownY));
float dx = Math.abs((ev.getX() - mDownX));
if (mTouchState == TOUCH_STATE_X) {
//这次点击的item和上次点击的是å?Œä¸€ä¸ª(点击时上一个item还未关é—)
if (mTouchView != null) {
//å·¦å?³æ»‘动过程ä¸ï¼Œç¦?æ¢ä¸Šä¸‹æ‹‰
if (getParent().getParent() instanceof PullToRefreshSwipeListView) {
getParent().getParent().requestDisallowInterceptTouchEvent(true);
}
mTouchView.onSwipe(ev);
}
//listView显示selector䏿²¡æœ‰çжæ€?的背景
getSelector().setState(new int[] { 0 });
//å?–消事件,当å‰?çš„æ‰‹åŠ¿è¢«ä¸æ–,ä¸?会å†?接收到关于它的记录
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
} else if (mTouchState == TOUCH_STATE_NONE) {
if (Math.abs(dy) > MAX_Y) {
mTouchState = TOUCH_STATE_Y;
} else if (dx > MAX_X) {
mTouchState = TOUCH_STATE_X;
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeStart(mTouchPosition);
}
}
}
break;
case MotionEvent.ACTION_UP:
if (mTouchState == TOUCH_STATE_X) {
if (mTouchView != null) {
mTouchView.onSwipe(ev);
if (!mTouchView.isOpen()) {
mTouchPosition = -1;
mTouchView = null;
}
}
if (mOnSwipeListener != null) {
mOnSwipeListener.onSwipeEnd(mTouchPosition);
}
ev.setAction(MotionEvent.ACTION_CANCEL);
super.onTouchEvent(ev);
return true;
}
break;
}
return super.onTouchEvent(ev);
}Example 98
| Project: PullToZoomInListView-master File: PullToZoomListView.java View source code |
private void onSecondaryPointerUp(MotionEvent ev) {
int pointerIndex = (ev.getAction() & MotionEventCompat.ACTION_POINTER_INDEX_MASK) >> 8;
if (ev.getPointerId(pointerIndex) == mActivePointerId) {
int newPointerIndex = pointerIndex == 0 ? 1 : 0;
mLastMotionY = ev.getY(newPointerIndex);
mActivePointerId = ev.getPointerId(newPointerIndex);
}
}Example 99
| Project: sbt-android-master File: BottomSheet.java View source code |
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) {
viewDragHelper.cancel();
return false;
}
return isDraggableViewUnder((int) ev.getX(), (int) ev.getY()) && (viewDragHelper.shouldInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev));
}Example 100
| Project: scrumdailytimer-master File: ChronoFragment.java View source code |
private void start() {
mVibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);
new Thread() {
public void run() {
mAlarmPlayer = mProvider.getAlarmPlayer(getActivity());
}
}.start();
new Thread() {
public void run() {
mTickPlayer = mProvider.getTickPlayer(getActivity());
}
}.start();
mScrumTimer.configure(this);
mSeekBarController.configure(mSeekBar, this);
mNumberOfParticipants = 1;
mNumberOfTimeouts = 0;
mStatus = ChronoStatus.STARTED;
mWholeLayout.setBackgroundResource(R.drawable.background_gradient);
mTapForNextTextView.setText(R.string.tap_for_first_participant);
mScrumTimer.startTimer();
mWholeLayout.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mStatus == ChronoStatus.STARTED) {
return false;
}
mWholeLayout.setBackgroundResource(R.drawable.pause_background_gradient);
mScrumTimer.pauseCountDown();
// If tick is playing, then we are in timeout.
if (mTickPlayer.isPlaying()) {
mPausedInTimeout = true;
mTickPlayer.pause();
}
return false;
}
});
mWholeLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case MotionEvent.ACTION_UP:
return endPause();
default:
break;
}
return false;
}
});
mWholeLayout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mScrumTimer.isCountDownPaused()) {
return;
}
vibrate();
isBackPressReset = true;
switch(mStatus) {
case STARTED:
// Set time and store
storeSlotTime();
mScrumTimer.setTimeSlotLength(mSeekBar.getProgress());
mWholeLayout.setBackgroundResource(R.drawable.meeting_background_gradient);
mSeekBar.setVisibility(View.GONE);
mStatus = ChronoStatus.COUNTDOWN;
mWarmUpTime = mScrumTimer.getPrettyTime();
mParticipantTextView.setVisibility(View.VISIBLE);
repaintParticipants();
mTapForNextTextView.setText(R.string.tap_for_next);
mScrumTimer.resetCountDown();
mCountDownTextView.setText(mScrumTimer.getPrettyCountDown());
break;
case COUNTDOWN:
if (mTickPlayer.isPlaying()) {
mTickPlayer.pause();
}
mNumberOfParticipants++;
repaintParticipants();
mScrumTimer.resetCountDown();
mCountDownTextView.setText(mScrumTimer.getPrettyCountDown());
resetBackground();
break;
default:
}
}
});
}Example 101
| Project: Sidebar-master File: SideBar.java View source code |
@Override
public boolean onTouchEvent(MotionEvent ev) {
final int action = MotionEventCompat.getActionMasked(ev);
switch(action) {
case MotionEvent.ACTION_DOWN:
mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
mIsBeingDragged = false;
final float initialDownY = getMotionEventY(ev, mActivePointerId);
if (initialDownY == -1) {
return false;
}
if (!mIsDownRect.contains(ev.getX(), ev.getY())) {
return false;
}
mInitialDownY = initialDownY;
break;
case MotionEvent.ACTION_MOVE:
if (mActivePointerId == INVALID_POINTER) {
return false;
}
final float y = getMotionEventY(ev, mActivePointerId);
if (y == -1) {
return false;
}
final float yDiff = Math.abs(y - mInitialDownY);
if (yDiff > mTouchSlop && !mIsBeingDragged) {
mIsBeingDragged = true;
}
if (mIsBeingDragged) {
mY = y;
final float moveY = y - getPaddingTop() - mLetterHeight / 1.64f;
final int characterIndex = (int) (moveY / mHalfHeight * mLetters.length);
if (mChoose != characterIndex) {
if (characterIndex >= 0 && characterIndex < mLetters.length) {
mChoose = characterIndex;
Log.d(TAG, "mChoose " + mChoose + " mLetterHeight " + mLetterHeight);
// mOnTouchingLetterChangedListener.onTouchingLetterChanged(mLetters[characterIndex]);
}
}
invalidate();
}
break;
case MotionEventCompat.ACTION_POINTER_UP:
onSecondaryPointerUp(ev);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (mOnTouchingLetterChangedListener != null) {
if (mIsBeingDragged) {
mOnTouchingLetterChangedListener.onTouchingLetterChanged(mLetters[mChoose]);
} else {
float downY = ev.getY() - getPaddingTop();
final int characterIndex = (int) (downY / mHalfHeight * mLetters.length);
if (characterIndex >= 0 && characterIndex < mLetters.length) {
mOnTouchingLetterChangedListener.onTouchingLetterChanged(mLetters[characterIndex]);
}
}
}
mStartEndAnim = mIsBeingDragged;
mIsBeingDragged = false;
mActivePointerId = INVALID_POINTER;
mChoose = -1;
mAnimStep = 0f;
invalidate();
return false;
}
return true;
}