Example usage for android.view MotionEvent getClass

List of usage examples for android.view MotionEvent getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:Main.java

public static float getY(MotionEvent event, int index) {
    float value;/* w  ww.j  a v a 2  s.c o  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;
}

From source file:Main.java

public static float getX(MotionEvent event, int index) {
    float value;/*from  www . j  a v a 2  s .  com*/
    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("getX", 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;
}