Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.lang.reflect.InvocationTargetException;
import android.os.Build;
import android.view.MotionEvent;

public class Main {

    public static float getY(MotionEvent event, int index) {
        float value;
        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;
    }

    public static float getX(MotionEvent event, int index) {
        float value;
        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;
    }
}