Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.view.MotionEvent;
import android.view.View;

public class Main {
    /**
     * get coordinate in parent's coordinate system
     * 
     * @param view target view
     * @param location an array of two integers in which to hold the coordinates
     */
    public static void getCoordinateInParent(View view, MotionEvent event, int[] location) {
        if (view == null || event == null || view.getParent() == null || location.length < 2) {
            return;
        }
        int parentLocation[] = new int[2];
        ((View) view.getParent()).getLocationOnScreen(parentLocation);
        if (parentLocation != null && parentLocation.length > 1) {
            location[0] = (int) event.getX() - parentLocation[0];
            location[1] = (int) event.getY() - parentLocation[1];
        }
    }
}