List of usage examples for android.view MotionEvent ACTION_MASK
int ACTION_MASK
To view the source code for android.view MotionEvent ACTION_MASK.
Click Source Link
From source file:com.gdestiny.resume.view.touchgallery.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }/* w w w .j a v a 2 s . c om*/ float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onInterceptTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.heinrichreimersoftware.materialintro.view.SwipeBlockableViewPager.java
private boolean handleTouchEvent(MotionEvent event) { boolean allowTouch = false; final int action = event.getAction(); switch (action & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: { lastTouchX = event.getX();//from w w w . ja v a 2 s . c om // Save the ID of this pointer activePointerId = event.getPointerId(0); break; } case MotionEvent.ACTION_MOVE: { // Find the index of the active pointer and fetch its position final int pointerIndex = event.findPointerIndex(activePointerId); final float x = event.getX(pointerIndex); final float dx = x - lastTouchX; if (dx > 0) { // Swiped right if (!swipeRightEnabled && Math.abs(dx) > SWIPE_LOCK_THRESHOLD) { lockedRight = true; } if (!lockedRight) { allowTouch = true; if (Math.abs(dx) > SWIPE_UNLOCK_THRESHOLD) { lockedLeft = false; } } } else if (dx < 0) { // Swiped left if (!swipeLeftEnabled && Math.abs(dx) > SWIPE_LOCK_THRESHOLD) { lockedLeft = true; } if (!lockedLeft) { allowTouch = true; if (Math.abs(dx) > SWIPE_UNLOCK_THRESHOLD) { lockedRight = false; } } } lastTouchX = x; invalidate(); break; } case MotionEvent.ACTION_UP: { activePointerId = INVALID_POINTER_ID; lockedLeft = false; lockedRight = false; break; } case MotionEvent.ACTION_CANCEL: { activePointerId = INVALID_POINTER_ID; lockedLeft = false; lockedRight = false; break; } case MotionEvent.ACTION_POINTER_UP: { // Extract the index of the pointer that left the touch sensor final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT; final int pointerId = event.getPointerId(pointerIndex); if (pointerId == activePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; lastTouchX = event.getX(newPointerIndex); activePointerId = event.getPointerId(newPointerIndex); } break; } } return (!lockedLeft && !lockedRight) || allowTouch; }
From source file:com.gongpingjia.carplay.view.gallery.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }//from www . j a v a 2 s . c o m float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { try { return super.onInterceptTouchEvent(event); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.shenma.yueba.view.imageshow.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }//from w w w. j a va 2 s .c om float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onInterceptTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move // right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move // left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.windnow.StationPicActivity.java
@SuppressLint("NewApi") @Override//from www . j a v a 2 s . c o m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_station_pic); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { getActionBar().setDisplayHomeAsUpEnabled(true); } TextView tv = (TextView) findViewById(R.id.textViewPicName); tv.setText(getIntent().getExtras().getString("name")); imageDetail = (ImageView) findViewById(R.id.imageView1); String filename = "pic" + getIntent().getExtras().getString("txt").hashCode(); Bitmap pic = null; try { FileInputStream is = this.openFileInput(filename); pic = BitmapFactory.decodeStream(is); is.close(); } catch (IOException e) { LoadSaveOps.printErrorToLog(e); } imageDetail.setImageBitmap(pic); imageDetail.setOnTouchListener(new View.OnTouchListener() { @SuppressLint("ClickableViewAccessibility") @Override public boolean onTouch(View v, MotionEvent event) { ImageView view = (ImageView) v; switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_DOWN: savedMatrix.set(matrix); startPoint.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(midPoint, event); mode = ZOOM; } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: mode = NONE; break; case MotionEvent.ACTION_MOVE: if (mode == DRAG) { matrix.set(savedMatrix); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; matrix.postScale(scale, scale, midPoint.x, midPoint.y); matrix.postTranslate(event.getX() - startPoint.x, event.getY() - startPoint.y); //new } } break; } view.setImageMatrix(matrix); return true; } @SuppressLint("FloatMath") private float spacing(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return FloatMath.sqrt(x * x + y * y); } private void midPoint(PointF point, MotionEvent event) { float x = event.getX(0) + event.getX(1); float y = event.getY(0) + event.getY(1); point.set(x / 2, y / 2); } }); }
From source file:com.overtake.view.touchgallery.GalleryWidget.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }//from w ww. java2 s . c o m float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { //catch exception to prevent crash try { return super.onInterceptTouchEvent(event); } catch (Exception e) { e.printStackTrace(); } } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.manyi.mall.widget.GalleryWidget.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }/*from w ww.j a v a2s. com*/ float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { Log.e("LOG", "gallery"); } } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.gokuai.yunkuandroidsdk.gallery.touchwedgit.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }//from w ww.j a v a 2 s.c om float[] difference = handleMotionEvent(event); try { if (mCurrentView.pagerCanScroll()) { return super.onInterceptTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) // move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) // move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } } catch (IllegalArgumentException e) { // TODO: handle exception } return false; }
From source file:com.android.audiorecorder.gallery.widget.GalleryViewPager.java
@Override public boolean onInterceptTouchEvent(MotionEvent event) { if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { super.onInterceptTouchEvent(event); }/*w ww.j a v a2 s . c om*/ float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { try { return super.onInterceptTouchEvent(event); } catch (Exception e) { } } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onInterceptTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onInterceptTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onInterceptTouchEvent(event); } } return false; }
From source file:com.liangxun.yuejiula.galleryweidget.GalleryViewPager.java
@Override public boolean onTouchEvent(MotionEvent event) { try {//from w ww . j av a 2 s .c o m if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) { //super.onInterceptTouchEvent(event); float endX = event.getX(); float endY = event.getY(); if (isAClick(startX, endX, startY, endY)) { if (mOnItemClickListener != null) { mOnItemClickListener.onItemClicked(mCurrentView, getCurrentItem()); } } else { super.onTouchEvent(event); } } if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { startX = event.getX(); startY = event.getY(); } float[] difference = handleMotionEvent(event); if (mCurrentView.pagerCanScroll()) { return super.onTouchEvent(event); } else { if (difference != null && mCurrentView.onRightSide && difference[0] < 0) //move right { return super.onTouchEvent(event); } if (difference != null && mCurrentView.onLeftSide && difference[0] > 0) //move left { return super.onTouchEvent(event); } if (difference == null && (mCurrentView.onLeftSide || mCurrentView.onRightSide)) { return super.onTouchEvent(event); } } } catch (Exception e) { e.printStackTrace(); } return false; }