List of usage examples for android.view MotionEvent getX
public final float getX()
From source file:Main.java
private static boolean isPointerOutside(View v, MotionEvent event) { float x = event.getX(); float y = event.getY(); if (x < 0 || x > v.getWidth() || y < 0 || y > v.getHeight()) return true; return false; }
From source file:Main.java
public static boolean isMotionOnView(View view, MotionEvent event) { final float x = event.getX(); final float y = event.getY(); if (x < view.getRight() && x > view.getLeft() && y < view.getBottom() && y > view.getTop()) { return true; }/*from w w w .j a v a 2 s . c o m*/ return false; }
From source file:Main.java
public static Point eventToPoint(@NonNull MotionEvent event) { return new Point((int) event.getX(), (int) event.getY()); }
From source file:Main.java
public static float getX(MotionEvent e, int pointerIndex) { if (!isMultitouch) { return e.getX(); }//from w ww .j a va 2 s . co m try { float pointerCount = (Float) motionEvent_GetX.invoke(e, new Object[] { pointerIndex }); return pointerCount; } catch (Exception ex) { return e.getX(); } }
From source file:Main.java
public static boolean isEventInView(MotionEvent ev, View view) { int[] location = new int[2]; view.getLocationInWindow(location);// w ww . ja v a2s. co m if (ev.getX() > location[0] && ev.getX() < location[0] + view.getWidth() && ev.getY() > location[1] && ev.getY() < location[1] + view.getHeight()) { return true; } return false; }
From source file:Main.java
public static boolean isMotionFocusOnView(View view, MotionEvent event) { Rect focusBound = new Rect(); view.getFocusedRect(focusBound);/*www. j av a 2 s . c om*/ return focusBound.contains((int) event.getX(), (int) event.getY()); }
From source file:Main.java
/** * Checks if touch event is treat as single tap * * @param context android context/*from w w w .ja v a 2 s. co m*/ * @param downX axis x of touch down * @param downY axis y of touch down * @param upEvent MotionEvent for touch up * @return true if it's single tap, otherwise false */ public static boolean isSingleTap(Context context, float downX, float downY, MotionEvent upEvent) { return isSingleTap(context, upEvent.getDownTime(), upEvent.getEventTime(), downX, downY, upEvent.getX(), upEvent.getY()); }
From source file:Main.java
public static String formatTouchPoint(MotionEvent mv) { if (mv == null) { return ""; }//from w w w . ja v a 2 s .c o m return String.format(Locale.ENGLISH, "x:%f, y:%f rawX:%f rawY: %f", mv.getX(), mv.getY(), mv.getRawX(), mv.getRawY()); }
From source file:Main.java
public static boolean inRangeOfView(View view, MotionEvent ev) { int[] location = new int[2]; view.getLocationOnScreen(location);//from w w w. j a va 2s. c o m int x = location[0]; int y = location[1]; if (ev.getX() < x || ev.getX() > (x + view.getWidth()) || ev.getY() < y || ev.getY() > (y + view.getHeight())) { return false; } return true; }
From source file:Main.java
public static float getY(MotionEvent event, int index) { float value;//from w w w . j av a 2s . co m try { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR) { if (index == 0) { value = event.getX(); } else { value = 0; } } else { value = ((Float) (event.getClass().getMethod("getY", new Class[] { int.class }).invoke(event, new Object[] { Integer.valueOf(index) }))).floatValue(); } } catch (IllegalArgumentException e) { throw new RuntimeException(e); } catch (SecurityException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } return value; }