Example usage for android.view MotionEvent getRawX

List of usage examples for android.view MotionEvent getRawX

Introduction

In this page you can find the example usage for android.view MotionEvent getRawX.

Prototype

public final float getRawX() 

Source Link

Document

Returns the original raw X coordinate of this event.

Usage

From source file:Main.java

public static boolean isTouchInView(MotionEvent ev, View v) {
    int[] vLoc = new int[2];
    v.getLocationOnScreen(vLoc);//from ww w  . jav a2s.  co  m
    float motionX = ev.getRawX();
    float motionY = ev.getRawY();
    return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth()) && motionY >= vLoc[1]
            && motionY <= (vLoc[1] + v.getHeight());
}

From source file:Main.java

public static String formatTouchPoint(MotionEvent mv) {
    if (mv == null) {
        return "";
    }/*from w  ww  . jav a  2s. 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 isInRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);/*from  w  w  w  .  j ava 2s.  c o m*/
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth()) || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static void focusOnTouch(Camera camera, MotionEvent event) {
    Rect focusRect = calculateTapArea(camera, event.getRawX(), event.getRawY(), 1f);
    Rect meteringRect = calculateTapArea(camera, event.getRawX(), event.getRawY(), 1.5f);

    Camera.Parameters parameters = camera.getParameters();
    parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    int version = Build.VERSION.SDK_INT;
    if (version > Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getMaxNumFocusAreas() > 0) {
        List<Camera.Area> focusAreas = new ArrayList<Camera.Area>();
        focusAreas.add(new Camera.Area(focusRect, 1000));

        parameters.setFocusAreas(focusAreas);
    }/*from w  w  w  .  ja v  a 2 s  . c  o  m*/

    if (version > Build.VERSION_CODES.ICE_CREAM_SANDWICH && parameters.getMaxNumMeteringAreas() > 0) {
        List<Camera.Area> meteringAreas = new ArrayList<Camera.Area>();
        meteringAreas.add(new Camera.Area(meteringRect, 1000));

        parameters.setMeteringAreas(meteringAreas);
    }

    camera.setParameters(parameters);
}

From source file:net.nym.napply.library.behavior.HeadOffsetBehavior.java

public static boolean inRangeOfView(View view, MotionEvent ev) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);/*from  w ww  .jav a 2 s  . co m*/
    int x = location[0];
    int y = location[1];
    if (ev.getRawX() < x || ev.getRawX() > (x + view.getWidth()) || ev.getRawY() < y
            || ev.getRawY() > (y + view.getHeight())) {
        return false;
    }
    return true;
}

From source file:Main.java

/**
 * <pre>//  ww  w. j  a  v  a 2s .c om
 * Determine whether a {@link MotionEvent} is on a {@link View}
 * </pre>
 */
public static boolean motionEventOnView(MotionEvent event, View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);
    int x = location[0];
    int y = location[1];
    int w = view.getWidth();
    int h = view.getHeight();
    Rect rect = new Rect(x, y, x + w, y + h);
    return rect.contains((int) event.getRawX(), (int) event.getRawY());
}

From source file:it.sephiroth.android.library.imagezoom.ScaleGestureDetector.java

/**
 * MotionEvent has no getRawX(int) method; simulate it pending future API
 * approval./*from w w  w .j  a v a2  s  .  c o m*/
 */
private static float getRawX(final MotionEvent event, final int pointerIndex) {
    final float offset = event.getX() - event.getRawX();
    return event.getX(pointerIndex) + offset;
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static void setClearAction(final EditText target) {
    target.setOnTouchListener(new View.OnTouchListener() {
        final int RIGHT = 2;

        @Override// w  w w. j  a  v a2s .c o  m
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                int leftEdgeOfRightDrawable = view.getRight()
                        - target.getCompoundDrawables()[RIGHT].getBounds().width();
                // when EditBox has padding, adjust leftEdge like
                // leftEdgeOfRightDrawable -= getResources().getDimension(R.dimen.edittext_padding_left_right);
                if (event.getRawX() >= leftEdgeOfRightDrawable) {
                    // clicked on clear icon
                    target.setText("");
                    target.clearFocus();
                    return false;
                }
            }
            return false;
        }
    });
}

From source file:com.schedjoules.eventdiscovery.framework.widgets.ClearableEditText.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    mClearIcon = new TintedDrawable(getContext(), R.drawable.schedjoules_ic_clear_black_24dp,
            new AttributeColor(getContext(), R.attr.schedjoules_appBarIconColor)).get();

    addTextChangedListener(new AbstractTextWatcher() {
        @Override//from   w ww.java 2 s  . c  om
        public void afterTextChanged(Editable text) {
            Drawable clearIcon = text.length() > 0 ? mClearIcon : null;
            setCompoundDrawablesWithIntrinsicBounds(null, null, clearIcon, null);
        }
    });

    mGestureDetector = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent event) {
            if (event.getRawX() >= getRight() - getTotalPaddingRight()) {
                setText("");
            }
            return false;
        }
    });
}

From source file:org.onebusaway.android.util.UIUtils.java

/**
 * Returns true if the provided touch event was within the provided view
 *
 * @return true if the provided touch event was within the provided view
 *//*from  www.  j a v  a 2  s . co  m*/
public static boolean isTouchInView(View view, MotionEvent event) {
    Rect rect = new Rect();
    view.getGlobalVisibleRect(rect);
    return rect.contains((int) event.getRawX(), (int) event.getRawY());
}