List of usage examples for android.view MotionEvent getY
public final float getY(int pointerIndex)
From source file:ch.jeda.platform.android.CanvasFragment.java
@Override public boolean onTouch(final View view, final MotionEvent event) { int index;//from w w w . j av a 2 s .c o m switch (event.getActionMasked()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_DOWN, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: index = event.getActionIndex(); this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_UP, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); break; case MotionEvent.ACTION_MOVE: for (index = 0; index < event.getPointerCount(); ++index) { this.postEvent(new PointerEvent(mapDevice(event), EventType.POINTER_MOVED, event.getPointerId(index), (int) event.getX(index), (int) event.getY(index))); } break; } return true; }
From source file:com.apptentive.android.sdk.util.image.PreviewImageView.java
@Override public boolean onTouch(View v, MotionEvent event) { gestureDetector.onTouchEvent(event); scaleGestureDetector.onTouchEvent(event); float x = 0, y = 0; // Get multiple touch points final int pointerCount = event.getPointerCount(); // Calculate average x and y for (int i = 0; i < pointerCount; i++) { x += event.getX(i);//w w w .ja v a2s . c om y += event.getY(i); } x = x / pointerCount; y = y / pointerCount; /** * Reset lastX and lastY */ if (pointerCount != lastPointerCount) { isCanDrag = false; lastX = x; lastY = y; } lastPointerCount = pointerCount; switch (event.getAction()) { case MotionEvent.ACTION_MOVE: float dx = x - lastX; float dy = y - lastY; if (!isCanDrag) { isCanDrag = isCanDrag(dx, dy); } if (isCanDrag) { RectF rectF = getMatrixRectF(); if (getDrawable() != null) { isCheckLeftAndRight = isCheckTopAndBottom = true; // No left/right translation if image width is less than screen width if (rectF.width() < getWidth()) { dx = 0; isCheckLeftAndRight = false; } // No Up/Down translation if image height is less than screen height if (rectF.height() < getHeight()) { dy = 0; isCheckTopAndBottom = false; } scaleMatrix.postTranslate(dx, dy); checkMatrixBounds(); setImageMatrix(scaleMatrix); } } lastX = x; lastY = y; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: lastPointerCount = 0; break; } return true; }
From source file:com.cloverstudio.spika.CameraCropActivity.java
/** Determine the space between the first two fingers */ @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); }
From source file:com.intel.xdk.multitouch.MultiTouch.java
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); //get convenience reference to activity activity = cordova.getActivity();/*from w w w . jav a 2s . c om*/ activity.runOnUiThread(new Runnable() { public void run() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try { Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class); m.invoke(WebView.class, true); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } //WebView.setWebContentsDebuggingEnabled(true); } } }); touchy = new View.OnTouchListener() { private SparseArray<Long> pointerId2Identifier = new SparseArray<Long>(); @Override public boolean onTouch(View v, MotionEvent ev) { if (isMultitouchEnabled) { int pointerCount = ev.getPointerCount(); //get the correct action int maskedAction = ev.getActionMasked(); int idx = ev.getActionIndex(); try { String js = null; if (maskedAction == MotionEvent.ACTION_POINTER_DOWN || maskedAction == MotionEvent.ACTION_DOWN) { int x = (int) ev.getX(idx); int y = (int) ev.getY(idx); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(idx); //make a timestamp identifier and store it long identifier = System.currentTimeMillis(); pointerId2Identifier.put(id, identifier); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchstart'},", identifier, x, y, h, w); queueMultitouchData(js, id, maskedAction); } else if (maskedAction == MotionEvent.ACTION_POINTER_UP || maskedAction == MotionEvent.ACTION_UP) { int x = (int) ev.getX(idx); int y = (int) ev.getY(idx); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(idx); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchend'},", pointerId2Identifier.get(id), x, y, h, w); pointerId2Identifier.remove(id); queueMultitouchData(js, id, maskedAction); } else if (maskedAction == MotionEvent.ACTION_MOVE) { //send all events if it is a move for (int i = 0; i < pointerCount; i++) { int x = (int) ev.getX(i); int y = (int) ev.getY(i); int h = (int) v.getHeight(); int w = (int) v.getWidth(); int id = ev.getPointerId(i); js = String.format("{id:%d,x:%d,y:%d,h:%d,w:%d,type:'touchmove'},", pointerId2Identifier.get(id), x, y, h, w); queueMultitouchData(js, id, maskedAction); } } else { Log.e("[intel.xdk]", "got a MotionEvent that is not up/down/move:" + ev); } //Log.i("[intel.xdk]", "onTouchEvent:"+js); } catch (Exception e) { Log.e("[intel.xdk]", "Got an exception back from WebView: ", e); } return true; } else { return false; } } }; webView.setOnTouchListener(touchy); lock = this; messages = new ArrayList<String>(0); }
From source file:org.cocos2dx.lib.TextInputWraper.java
public boolean onTouchEvent(final MotionEvent event) { // these data are used in ACTION_MOVE and ACTION_CANCEL final int pointerNumber = event.getPointerCount(); final int[] ids = new int[pointerNumber]; final float[] xs = new float[pointerNumber]; final float[] ys = new float[pointerNumber]; for (int i = 0; i < pointerNumber; i++) { ids[i] = event.getPointerId(i);/* ww w . j a v a 2 s . c o m*/ xs[i] = event.getX(i); ys[i] = event.getY(i); } switch (event.getAction() & MotionEvent.ACTION_MASK) { case MotionEvent.ACTION_POINTER_DOWN: final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerDown = event.getPointerId(indexPointerDown); final float xPointerDown = event.getX(indexPointerDown); final float yPointerDown = event.getY(indexPointerDown); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown); } }); break; case MotionEvent.ACTION_DOWN: // there are only one finger on the screen final int idDown = event.getPointerId(0); final float xDown = xs[0]; final float yDown = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionDown(idDown, xDown, yDown); } }); break; case MotionEvent.ACTION_MOVE: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionMove(ids, xs, ys); } }); break; case MotionEvent.ACTION_POINTER_UP: final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT; final int idPointerUp = event.getPointerId(indexPointUp); final float xPointerUp = event.getX(indexPointUp); final float yPointerUp = event.getY(indexPointUp); queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp); } }); break; case MotionEvent.ACTION_UP: // there are only one finger on the screen final int idUp = event.getPointerId(0); final float xUp = xs[0]; final float yUp = ys[0]; queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionUp(idUp, xUp, yUp); } }); break; case MotionEvent.ACTION_CANCEL: queueEvent(new Runnable() { @Override public void run() { mRenderer.handleActionCancel(ids, xs, ys); } }); break; } if (debug) { dumpEvent(event); } return true; }
From source file:com.funzio.pure2D.demo.particles.NovaActivity.java
@Override public boolean onTouch(final View v, final MotionEvent event) { final int action = event.getAction() & MotionEvent.ACTION_MASK; // null check if (mNovaFactory == null) { return false; }//from www . j ava2s .c om if (action == MotionEvent.ACTION_DOWN) { mStage.queueEvent(new Runnable() { @Override public void run() { final int pointerCount = event.getPointerCount(); for (int i = 0; i < pointerCount; i++) { // for demo, limit the number of emitters if (mScene.getNumGrandChildren() < mNovaFactory.getPoolSize()) { addObject(event.getX(i), mDisplaySize.y - event.getY(i)); } } } }); } return true; }
From source file:android.support.v7.widget.DropDownListView.java
/** * Handles forwarded events.//w ww . ja va 2s . c o m * * @param activePointerId id of the pointer that activated forwarding * @return whether the event was handled */ public boolean onForwardedEvent(MotionEvent event, int activePointerId) { boolean handledEvent = true; boolean clearPressedItem = false; final int actionMasked = MotionEventCompat.getActionMasked(event); switch (actionMasked) { case MotionEvent.ACTION_CANCEL: handledEvent = false; break; case MotionEvent.ACTION_UP: handledEvent = false; // $FALL-THROUGH$ case MotionEvent.ACTION_MOVE: final int activeIndex = event.findPointerIndex(activePointerId); if (activeIndex < 0) { handledEvent = false; break; } final int x = (int) event.getX(activeIndex); final int y = (int) event.getY(activeIndex); final int position = pointToPosition(x, y); if (position == INVALID_POSITION) { clearPressedItem = true; break; } final View child = getChildAt(position - getFirstVisiblePosition()); setPressedItem(child, position, x, y); handledEvent = true; if (actionMasked == MotionEvent.ACTION_UP) { clickPressedItem(child, position); } break; } // Failure to handle the event cancels forwarding. if (!handledEvent || clearPressedItem) { clearPressedItem(); } // Manage automatic scrolling. if (handledEvent) { if (mScrollHelper == null) { mScrollHelper = new ListViewAutoScrollHelper(this); } mScrollHelper.setEnabled(true); mScrollHelper.onTouch(this, event); } else if (mScrollHelper != null) { mScrollHelper.setEnabled(false); } return handledEvent; }
From source file:cn.limc.androidcharts.event.SlipGestureDetector.java
public boolean onTouchEvent(MotionEvent event) { int pointers = event.getPointerCount(); switch (event.getAction() & MotionEvent.ACTION_MASK) { // ?/*from w ww .jav a 2s .c om*/ case MotionEvent.ACTION_DOWN: initalX = event.getX(); if (pointers > 1) { touchMode = TOUCH_MODE_MULTI; } else { touchMode = TOUCH_MODE_SINGLE; } break; case MotionEvent.ACTION_UP: startPointA = null; startPointB = null; break; case MotionEvent.ACTION_POINTER_UP: startPointA = null; startPointB = null; case MotionEvent.ACTION_POINTER_DOWN: olddistance = calcDistance(event); if (olddistance > MIN_DISTANCE) { touchMode = TOUCH_MODE_MULTI; startPointA = new PointF(event.getX(0), event.getY(0)); startPointB = new PointF(event.getX(1), event.getY(1)); } return true; case MotionEvent.ACTION_MOVE: if (touchMode == TOUCH_MODE_SINGLE) { final float finalX = event.getX(); // MotionEvent finalEvent = event; if (performLongClick) { return super.onTouchEvent(event); } else { if (finalX - initalX >= mStickScaleValue) { if (onSlipGestureListener != null) { onSlipGestureListener.onMoveRight((ISlipable) instance, event); } } else if (initalX - finalX >= mStickScaleValue) { if (onSlipGestureListener != null) { onSlipGestureListener.onMoveLeft((ISlipable) instance, event); } } initalX = finalX; // initalEvent = finalEvent; return true; } } else if (touchMode == TOUCH_MODE_MULTI) { newdistance = calcDistance(event); if (Math.abs(newdistance - olddistance) > MIN_DISTANCE) { if (onZoomGestureListener != null) { if (newdistance > olddistance) { onZoomGestureListener.onZoomIn((IZoomable) instance, event); } else { onZoomGestureListener.onZoomOut((IZoomable) instance, event); } } } olddistance = newdistance; return true; // startPointA = new PointF(event.getX(), event.getY()); // startPointB = new PointF(event.getX(1), event.getY(1)); } break; } return super.onTouchEvent(event); }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripView.java
@Override public boolean onTouchEvent(final MotionEvent me) { if (!mMoreSuggestionsView.isShowingInParent()) { // Ignore any touch event while more suggestions panel hasn't been shown. // Detecting sliding up is done at {@link #onInterceptTouchEvent}. return true; }//from ww w . j a v a 2 s .com // In the sliding input mode. {@link MotionEvent} should be forwarded to // {@link MoreSuggestionsView}. final int index = me.getActionIndex(); final int x = mMoreSuggestionsView.translateX((int) me.getX(index)); final int y = mMoreSuggestionsView.translateY((int) me.getY(index)); me.setLocation(x, y); if (!mNeedsToTransformTouchEventToHoverEvent) { mMoreSuggestionsView.onTouchEvent(me); return true; } // In sliding suggestion mode with accessibility mode on, a touch event should be // transformed to a hover event. final int width = mMoreSuggestionsView.getWidth(); final int height = mMoreSuggestionsView.getHeight(); final boolean onMoreSuggestions = (x >= 0 && x < width && y >= 0 && y < height); if (!onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) { // Just drop this touch event because dispatching hover event isn't started yet and // the touch event isn't on {@link MoreSuggestionsView}. return true; } final int hoverAction; if (onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) { // Transform this touch event to a hover enter event and start dispatching a hover // event to {@link MoreSuggestionsView}. mIsDispatchingHoverEventToMoreSuggestions = true; hoverAction = MotionEvent.ACTION_HOVER_ENTER; } else if (me.getActionMasked() == MotionEvent.ACTION_UP) { // Transform this touch event to a hover exit event and stop dispatching a hover event // after this. mIsDispatchingHoverEventToMoreSuggestions = false; mNeedsToTransformTouchEventToHoverEvent = false; hoverAction = MotionEvent.ACTION_HOVER_EXIT; } else { // Transform this touch event to a hover move event. hoverAction = MotionEvent.ACTION_HOVER_MOVE; } me.setAction(hoverAction); mMoreSuggestionsView.onHoverEvent(me); return true; }
From source file:com.kircherelectronics.accelerationfilter.activity.AccelerationPlotActivity.java
/** * Get the distance between fingers for the touch to zoom. * /*from w w w. j a v a 2 s .c om*/ * @param event * @return */ private final float fingerDist(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); return (float) Math.sqrt(x * x + y * y); }