List of usage examples for android.view MotionEvent getY
public final float getY()
From source file:com.android.andryyu.lifehelper.widget.RippleView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { animateRipple(event);/*w ww . ja va 2 s. co m*/ sendClickEvent(false); rippleStatus = RIPPLE_SINGLE; } if (rippleStatus == RIPPLE_LONG_PRESS) { if (event.getAction() == MotionEvent.ACTION_UP) { rippleStatus = RIPPLE_ACTION_UP; } else if (Math.abs(event.getX() - lastLongPressX) >= touchSlop || Math.abs(event.getY() - lastLongPressY) >= touchSlop) { rippleStatus = RIPPLE_ACTION_MOVE; } } return super.onTouchEvent(event); }
From source file:com.andview.refreshview.swipe.SwipeMenuLayout.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (mVelocityTracker == null) mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(ev);/*from w w w. j a v a 2s .c o m*/ int dx; int dy; int action = ev.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: mLastX = (int) ev.getX(); mLastY = (int) ev.getY(); break; case MotionEvent.ACTION_MOVE: if (!isSwipeEnable()) break; int disX = (int) (mLastX - ev.getX()); int disY = (int) (mLastY - ev.getY()); if (!mDragging && Math.abs(disX) > mScaledTouchSlop && Math.abs(disX) > Math.abs(disY)) { mDragging = true; } if (mDragging) { if (mSwipeCurrentHorizontal == null || shouldResetSwipe) { if (disX < 0) { if (mSwipeLeftHorizontal != null) mSwipeCurrentHorizontal = mSwipeLeftHorizontal; else mSwipeCurrentHorizontal = mSwipeRightHorizontal; } else { if (mSwipeRightHorizontal != null) mSwipeCurrentHorizontal = mSwipeRightHorizontal; else mSwipeCurrentHorizontal = mSwipeLeftHorizontal; } } scrollBy(disX, 0); mLastX = (int) ev.getX(); mLastY = (int) ev.getY(); shouldResetSwipe = false; } break; case MotionEvent.ACTION_UP: dx = (int) (mDownX - ev.getX()); dy = (int) (mDownY - ev.getY()); mDragging = false; mVelocityTracker.computeCurrentVelocity(1000, mScaledMaximumFlingVelocity); int velocityX = (int) mVelocityTracker.getXVelocity(); int velocity = Math.abs(velocityX); if (velocity > mScaledMinimumFlingVelocity) { if (mSwipeCurrentHorizontal != null) { int duration = getSwipeDuration(ev, velocity); if (mSwipeCurrentHorizontal instanceof SwipeRightHorizontal) { if (velocityX < 0) { smoothOpenMenu(duration); } else { smoothCloseMenu(duration); } } else { if (velocityX > 0) { smoothOpenMenu(duration); } else { smoothCloseMenu(duration); } } ViewCompat.postInvalidateOnAnimation(this); } } else { judgeOpenClose(dx, dy); } mVelocityTracker.clear(); mVelocityTracker.recycle(); mVelocityTracker = null; if (Math.abs(mDownX - ev.getX()) > mScaledTouchSlop || Math.abs(mDownY - ev.getY()) > mScaledTouchSlop || isMenuOpen()) { ev.setAction(MotionEvent.ACTION_CANCEL); super.onTouchEvent(ev); return true; } break; case MotionEvent.ACTION_CANCEL: mDragging = false; if (!mScroller.isFinished()) { mScroller.abortAnimation(); } else { dx = (int) (mDownX - ev.getX()); dy = (int) (mDownY - ev.getY()); judgeOpenClose(dx, dy); } break; } return super.onTouchEvent(ev); }
From source file:com.appsimobile.appsii.SidebarHotspot.java
@Override public boolean onTouchEvent(MotionEvent e) { switch (e.getAction()) { case MotionEvent.ACTION_DOWN: { mVelocityTracker = VelocityTracker.obtain(); mVelocityTracker.addMovement(e); // remove the background to make sure it does not overlap // the sidebar mIsDragOpening = true;/*from w ww. j a v a 2 s.com*/ setBackgroundResource(0); float x = e.getX(); float y = e.getY(); if (mCallback != null) { mSwipeListener = mCallback.open(this, Gesture.TO_CENTER, (int) x, (int) y); mSwipeInProgress = mSwipeListener != null; mState = STATE_AWAITING_RELEASE; if (mVibrate) { vibrate(); } return true; } return false; } case MotionEvent.ACTION_MOVE: mVelocityTracker.addMovement(e); float x = e.getX(); float y = e.getY(); return detectSwipe(x, y, e); case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: cancelMotionHandling(e, false); return false; } return super.onTouchEvent(e); }
From source file:com.test.hwautotest.emmagee.service.EmmageeService.java
/** * create a floating window to show real-time data. */// w w w. j a v a2s. c o m private void createFloatingWindow() { SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = shared.edit(); editor.putInt("float", 1); editor.commit(); windowManager = (WindowManager) getApplicationContext().getSystemService("window"); wmParams = ((MyApplication) getApplication()).getMywmParams(); wmParams.type = 2002; wmParams.flags |= 8; wmParams.gravity = Gravity.LEFT | Gravity.TOP; wmParams.x = 0; wmParams.y = 0; wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.format = 1; windowManager.addView(viFloatingWindow, wmParams); viFloatingWindow.setOnTouchListener(new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { x = event.getRawX(); y = event.getRawY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // state = MotionEvent.ACTION_DOWN; startX = x; startY = y; mTouchStartX = event.getX(); mTouchStartY = event.getY(); Log.d("startP", "startX" + mTouchStartX + "====startY" + mTouchStartY); break; case MotionEvent.ACTION_MOVE: // state = MotionEvent.ACTION_MOVE; updateViewPosition(); break; case MotionEvent.ACTION_UP: // state = MotionEvent.ACTION_UP; updateViewPosition(); // showImg();//? mTouchStartX = mTouchStartY = 0; break; } return true; } }); // btnWifi.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // try { // btnWifi = (Button) viFloatingWindow.findViewById(R.id.wifi); // String buttonText = (String) btnWifi.getText(); // String wifiText = getResources().getString( // R.string.openwifi); // if (buttonText.equals(wifiText)) { // wifiManager.setWifiEnabled(true); // btnWifi.setText(R.string.closewifi); // } else { // wifiManager.setWifiEnabled(false); // btnWifi.setText(R.string.openwifi); // } // } catch (Exception e) { // Toast.makeText(viFloatingWindow.getContext(), "?wifi", // Toast.LENGTH_LONG).show(); // Log.e(LOG_TAG, e.toString()); // } // } // }); //? imgClose.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { // TODO Auto-generated method stub showMemi(); } }); }
From source file:com.cloverstudio.spika.CameraCropActivity.java
@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);//from w ww . j a v a 2s.c o m start.set(event.getX(), event.getY()); mode = DRAG; break; case MotionEvent.ACTION_POINTER_DOWN: oldDist = spacing(event); if (oldDist > 10f) { savedMatrix.set(matrix); midPoint(mid, 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() - start.x, event.getY() - start.y); start_x = event.getX() - start.x; start_y = event.getY() - start.y; } else if (mode == ZOOM) { float newDist = spacing(event); if (newDist > 10f) { matrix.set(savedMatrix); float scale = newDist / oldDist; mAspect = scale; matrix.postScale(scale, scale, mid.x, mid.y); } } break; } view.setImageMatrix(matrix); view.invalidate(); return true; }
From source file:com.borax12.materialdaterangepicker.date.MonthView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: final int day = getDayFromLocation(event.getX(), event.getY()); if (day >= 0) { onDayClick(day);/*w w w . j a v a 2 s .c o m*/ } break; } return true; }
From source file:org.artoolkit.ar.samples.ARMovie.ARMovieActivity.java
private void focusOnTouch(MotionEvent event) { Log.i("TAG", "Touched !"); if (camSurface.getCamera() != null) { Camera.Parameters parameters = camSurface.getCamera().getParameters(); if (parameters.getMaxNumMeteringAreas() > 0) { Log.i("TAG", "fancy !"); Rect rect = calculateFocusArea(event.getX(), event.getY()); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); List<Camera.Area> meteringAreas = new ArrayList<Camera.Area>(); meteringAreas.add(new Camera.Area(rect, 800)); parameters.setFocusAreas(meteringAreas); camSurface.getCamera().setParameters(parameters); camSurface.getCamera().autoFocus(mAutoFocusTakePictureCallback); } else {/* ww w. j a va2s . c o m*/ camSurface.getCamera().autoFocus(mAutoFocusTakePictureCallback); } } }
From source file:com.appunite.list.FastScroller.java
boolean onInterceptTouchEvent(MotionEvent ev) { switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: if (mState > STATE_NONE && isPointInside(ev.getX(), ev.getY())) { if (!mList.isInScrollingContainerUnhide()) { beginDrag();// w ww . ja v a2s .c o m return true; } mInitialTouchY = ev.getY(); startPendingDrag(); } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: cancelPendingDrag(); break; } return false; }
From source file:de.tlabs.ssr.g1.client.SourcesView.java
@Override public boolean onDown(MotionEvent event) { scrolling = false;/*from www.ja v a 2 s .c o m*/ synchronized (GlobalData.audioScene) { // determine transformed coordinate of touch point touchPoint[0] = event.getX(); touchPoint[1] = event.getY(); inverseViewportTransformation.mapPoints(touchPoint); GlobalData.audioScene.inverseMapPoint(touchPoint); // try to find nearest sound source lastTouchSoundSource = GlobalData.audioScene.getNearestSoundSource(touchPoint); if (lastTouchSoundSource != null) { // get distance (touch point to source) in pixels selectionOffset[0] = lastTouchSoundSource.getX(); selectionOffset[1] = lastTouchSoundSource.getY(); GlobalData.audioScene.mapPoint(selectionOffset); viewportTransformation.mapPoints(selectionOffset); selectionOffset[0] -= event.getX(); selectionOffset[1] -= event.getY(); float distance = FloatMath .sqrt(selectionOffset[0] * selectionOffset[0] + selectionOffset[1] * selectionOffset[1]); // select source? if (distance > SOURCE_SELECT_RADIUS) { lastTouchSoundSource = null; } } } return true; }
From source file:com.android.yijiang.kzx.widget.betterpickers.radialtimepicker.RadialPickerLayout.java
@Override public boolean onTouch(View v, MotionEvent event) { final float eventX = event.getX(); final float eventY = event.getY(); int degrees;/*from w w w . j a v a 2s. c o m*/ int value; final Boolean[] isInnerCircle = new Boolean[1]; isInnerCircle[0] = false; long millis = SystemClock.uptimeMillis(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mInputEnabled) { return true; } mDownX = eventX; mDownY = eventY; mLastValueSelected = -1; mDoingMove = false; mDoingTouch = true; // If we're showing the AM/PM, check to see if the user is touching it. if (!mHideAmPm) { mIsTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); } else { mIsTouchingAmOrPm = -1; } if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { // If the touch is on AM or PM, set it as "touched" after the tapTimeout // in case the user moves their finger quickly. tryVibrate(); mDownDegrees = -1; mHandler.postDelayed(new Runnable() { @Override public void run() { mAmPmCirclesView.setAmOrPmPressed(mIsTouchingAmOrPm); mAmPmCirclesView.invalidate(); } }, tapTimeout); } else { // If we're in accessibility mode, force the touch to be legal. Otherwise, // it will only register within the given touch target zone. boolean forceLegal = AccessibilityManagerCompat.isTouchExplorationEnabled(mAccessibilityManager); // Calculate the degrees that is currently being touched. mDownDegrees = getDegreesFromCoords(eventX, eventY, forceLegal, isInnerCircle); if (mDownDegrees != -1) { // If it's a legal touch, set that number as "selected" after the // tapTimeout in case the user moves their finger quickly. tryVibrate(); mHandler.postDelayed(new Runnable() { @Override public void run() { mDoingMove = true; int value = reselectSelector(mDownDegrees, isInnerCircle[0], false, true); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } }, tapTimeout); } } return true; case MotionEvent.ACTION_MOVE: if (!mInputEnabled) { // We shouldn't be in this state, because input is disabled. Log.e(TAG, "Input was disabled, but received ACTION_MOVE."); return true; } float dY = Math.abs(eventY - mDownY); float dX = Math.abs(eventX - mDownX); if (!mDoingMove && dX <= touchSlop && dY <= touchSlop) { // Hasn't registered down yet, just slight, accidental movement of finger. break; } // If we're in the middle of touching down on AM or PM, check if we still are. // If so, no-op. If not, remove its pressed state. Either way, no need to check // for touches on the other circle. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { mHandler.removeCallbacksAndMessages(null); int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); if (isTouchingAmOrPm != mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); mIsTouchingAmOrPm = -1; } break; } if (mDownDegrees == -1) { // Original down was illegal, so no movement will register. break; } // We're doing a move along the circle, so move the selection as appropriate. mDoingMove = true; mHandler.removeCallbacksAndMessages(null); degrees = getDegreesFromCoords(eventX, eventY, true, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], false, true); if (value != mLastValueSelected) { tryVibrate(); mLastValueSelected = value; mListener.onValueSelected(getCurrentItemShowing(), value, false); } } return true; case MotionEvent.ACTION_UP: if (!mInputEnabled) { // If our touch input was disabled, tell the listener to re-enable us. Log.d(TAG, "Input was disabled, but received ACTION_UP."); mListener.onValueSelected(ENABLE_PICKER_INDEX, 1, false); return true; } mHandler.removeCallbacksAndMessages(null); mDoingTouch = false; // If we're touching AM or PM, set it as selected, and tell the listener. if (mIsTouchingAmOrPm == AM || mIsTouchingAmOrPm == PM) { int isTouchingAmOrPm = mAmPmCirclesView.getIsTouchingAmOrPm(eventX, eventY); mAmPmCirclesView.setAmOrPmPressed(-1); mAmPmCirclesView.invalidate(); if (isTouchingAmOrPm == mIsTouchingAmOrPm) { mAmPmCirclesView.setAmOrPm(isTouchingAmOrPm); if (getIsCurrentlyAmOrPm() != isTouchingAmOrPm) { mListener.onValueSelected(AMPM_INDEX, mIsTouchingAmOrPm, false); setValueForItem(AMPM_INDEX, isTouchingAmOrPm); } } mIsTouchingAmOrPm = -1; break; } // If we have a legal degrees selected, set the value and tell the listener. if (mDownDegrees != -1) { degrees = getDegreesFromCoords(eventX, eventY, mDoingMove, isInnerCircle); if (degrees != -1) { value = reselectSelector(degrees, isInnerCircle[0], !mDoingMove, false); if (getCurrentItemShowing() == HOUR_INDEX && !mIs24HourMode) { int amOrPm = getIsCurrentlyAmOrPm(); if (amOrPm == AM && value == 12) { value = 0; } else if (amOrPm == PM && value != 12) { value += 12; } } setValueForItem(getCurrentItemShowing(), value); mListener.onValueSelected(getCurrentItemShowing(), value, true); } } mDoingMove = false; return true; default: break; } return false; }