Java tutorial
//package com.java2s; /* * Copyright (c) 2012 Jason Polites * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.graphics.PointF; import android.view.MotionEvent; public class Main { @SuppressWarnings("deprecation") public static float distance(MotionEvent event) { float x = event.getX(0) - event.getX(1); float y = event.getY(0) - event.getY(1); Math.sqrt(x * x + y * y); return (float) Math.sqrt(x * x + y * y); } public static float distance(PointF p1, PointF p2) { float x = p1.x - p2.x; float y = p1.y - p2.y; return (float) Math.sqrt(x * x + y * y); } public static double distance(float x1, float y1, float x2, float y2) { float x = x1 - x2; float y = y1 - y2; return Math.sqrt(x * x + y * y); } }