Android Open Source - Verlet Multy Touch Verlet Handler






From Project

Back to project page Verlet.

License

The source code is released under:

Copyright 2013 Devicement http://devicement.com/ Copyright 2013 Sub Protocol and other contributors http://subprotocol.com/ Permission is hereby granted, free of charge, to any person obtaining a co...

If you think the Android project Verlet listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.verletandroid.Handlers;
/*  w w w  .  ja v a  2 s . c  o m*/
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import org.verletandroid.VerletCore.Verlet;

/**
 * Created with IntelliJ IDEA.
 * User: George
 * Date: 02.05.13
 * Time: 12:46
 * To change this template use File | Settings | File Templates.
 */
public class MultyTouchVerletHandler implements View.OnTouchListener {

    private Verlet verlet;
    private final float scaleX;
    private final float scaleY;

    public MultyTouchVerletHandler(Verlet sim, float scaleX, float scaleY) {

        this.verlet = sim;
        this.scaleX = scaleX;
        this.scaleY = scaleY;
    }


    @Override
    public boolean onTouch(View view, MotionEvent event) {

        int action = event.getAction() & MotionEvent.ACTION_MASK;
        int pointerIndex = (event.getAction() & MotionEvent.ACTION_POINTER_ID_MASK)
                >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        int pointerId = event.getPointerId(pointerIndex);

        switch(action) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_POINTER_DOWN:
                verlet.onTouchDown(event.getX(pointerIndex)*scaleX, event.getY(pointerIndex)*scaleY, pointerId);
                Log.v("Touch", String.format("ACTION_DOWN x:%.2f y:%.2f index:%d", event.getX(pointerIndex), event.getY(pointerIndex), pointerId));
            break;
            case MotionEvent.ACTION_MOVE:
                int pointerCount = event.getPointerCount();
                for(int i = 0; i < pointerCount; i++) {
                    pointerIndex = i;
                    pointerId = event.getPointerId(pointerIndex);
                    verlet.onTouchMove(event.getX(pointerIndex)*scaleX, event.getY(pointerIndex)*scaleY, pointerId);
                    Log.v("Touch", String.format("ACTION_MOVE %d", pointerId));
                }
            break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_CANCEL:
                verlet.onTouchUp(event.getX(pointerIndex)*scaleX, event.getY(pointerIndex)*scaleY, pointerId);
                Log.v("Touch", String.format("ACTION_UP %d", pointerId));
                break;
        }

        return true;
    }
}




Java Source Code List

com.northerneyes.VerletObjects.SpiderWeb.java
com.northerneyes.VerletObjects.Spider.java
com.northerneyes.VerletObjects.Tree.java
com.northerneyes.activities.MainActivity.java
com.northerneyes.activities.SampleList.java
org.verletandroid.Graphics.Graphics.java
org.verletandroid.Graphics.IGraphics.java
org.verletandroid.Graphics.IPixmap.java
org.verletandroid.Graphics.PixmapFormat.java
org.verletandroid.Graphics.Pixmap.java
org.verletandroid.Handlers.AccelerometerVerletHandler.java
org.verletandroid.Handlers.InputVerletHandler.java
org.verletandroid.Handlers.MultyTouchVerletHandler.java
org.verletandroid.VerletCore.Composite.java
org.verletandroid.VerletCore.IEntity.java
org.verletandroid.VerletCore.Particle.java
org.verletandroid.VerletCore.Utils.java
org.verletandroid.VerletCore.Vec2.java
org.verletandroid.VerletCore.Verlet.java
org.verletandroid.VerletCore.Contraints.AngleConstraint.java
org.verletandroid.VerletCore.Contraints.DistanceConstraint.java
org.verletandroid.VerletCore.Contraints.IConstraint.java
org.verletandroid.VerletCore.Contraints.PinConstraint.java
org.verletandroid.VerletCore.Objects.Cloth.java
org.verletandroid.VerletCore.Objects.LineSegments.java
org.verletandroid.VerletCore.Objects.Tire.java
org.verletandroid.componets.IUpdatable.java
org.verletandroid.componets.RenderView.java