onPinch() not working (ketai library)

Hi there…

I’m trying to use Pinch, so I started to try the ketai library, tried on android mode, exported to AS (Android Studio) and it works fine. But my problem is trying to use it in my code… I don’t know why it doesn’t work or what I’m doing wrong…

I took the library ketai from my exported ketai example exported to AS, and I copy/paste to my own code in /libs/, then I added this to my code

import android.view.MotionEvent;
import ketai.ui.*;


public class MySketch extends PApplet {
    KetaiGesture gesture;

    public void setup() {
        gesture = new KetaiGesture(this); }

    public boolean surfaceTouchEvent(MotionEvent event) {
        super.surfaceTouchEvent(event);
        return gesture.surfaceTouchEvent(event);
    }
    void onPinch(float x, float y, float d)
    {
        println("PINCH");
        Log.d(TAG, "PIINCH");
    }
}

And the prints never happens… Please, any help

I got this from the logcat

/System.out: motionEvent called inside kgesture
/System.out: KGesture got a MotionEvent!
    motionEvent called inside kgesture
    KGesture got a MotionEvent!

But don’t know why or where :roll_eyes: the onPinch method is not called (neither know why in the other examples I tried the method onPinch is called…)

Finally I found a solution;

How I couldn’t figure out how to use the method onPinch() (don now how to use it yet), I have been looking for a way to detect multitouch and it coordinates, using the surfaceTouchEvent(); I found the answer:


    public boolean surfaceTouchEvent(MotionEvent event) {

        super.surfaceTouchEvent(event);
        final int actionPeformed = event.getAction();

        switch(actionPeformed){
            case 261:{  //event.getAction(); didn't get the same index for ACTION_POINTER_DOWN
                flagMultiDedos = 1;  // this a variable to detect if there are multiple fingers or not
                                     // Dedos = Fingers  1 = true, 0 = false

                pdedo1X = event.getAxisValue(0,0);  // pdedo is previous finger
                pdedo1Y = event.getAxisValue(1,0);  // the coordinates X & Y
                pdedo2X = event.getAxisValue(0,1);  // and the index of the finger
                pdedo2Y = event.getAxisValue(1,1);
                break;
            }
            case 6:{ //event.getAction(); didn't get the same index for ACTION_POINTER_UP(0)
                flagMultiDedos = 0;
                break;
            }
            case 262:{ //event.getAction(); didn't get the same index for ACTION_POINTER_UP(1)
                flagMultiDedos = 0;
                break;
            }

            case MotionEvent.ACTION_MOVE:{
                dedoIncremento  = 0;  // fingerIncrement
                pdedoIncremento = 0; // previous finger increment
                if(flagMultiDedos == 1){
                    dedo1X = event.getAxisValue(0,0);
                    dedo2X = event.getAxisValue(0,1);
                    dedo1Y = event.getAxisValue(1,0);
                    dedo2Y = event.getAxisValue(1,1);

                    // calculating the distance to set the increment 
                    pdedoIncremento = dist(pdedo1X,pdedo1Y,pdedo2X,pdedo2Y);
                    dedoIncremento = dist(dedo1X,dedo1Y,dedo2X,dedo2Y);

                    // update your zoom variable (I usually put it in scale)
                    zoom += pdedoIncremento - dedoIncremento;

                    // update your last finger coordinates
                    pdedo1X = dedo1X;
                    pdedo1Y = dedo1Y;
                    pdedo2X = dedo2X;
                    pdedo2Y = dedo2Y;
                }
                break;
            }
        }

Well, is not the most beautiful solution, but it works for me :sweat_smile: !!

Hope someone find it helpful too :hugs:

1 Like

onPinch has no problem at all. I used this library in my app.

You forgot to use public.

public void onPinch(float x, float y, float d) {
println(“called!”);
}

Android studio won’t auto public function like processing IDE.

2 Likes

Daaaamn, is truth, I forgot it… :exploding_head::exploding_head::exploding_head::exploding_head: !!! ( and wasted many time :sweat:)

Thanks @technew :hugs: