# onPinch() not working (ketai library)

**URL:** <https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603>\
**Category:** Processing for Android\
**Created:** [October 11, 2019, 8:41am UTC](https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603 "2019-10-11T08:41:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [October 11, 2019, 8:41am UTC](https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603/1 "2019-10-11T08:41:17Z")

</div>

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

```auto
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**
>
> ```auto
> 
> /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 🙄 the onPinch method is not called (neither know why in the other examples I tried the method onPinch is called…)

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [October 15, 2019, 11:34am UTC](https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603/2 "2019-10-15T11:34:48Z")

</div>

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:

```auto

    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 😅 !!

Hope someone find it helpful too 🤗

---

<div class="post-metadata">

**Author:** ![technew](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/technew/32/6364_2.png) [@technew](https://discourse.processing.org/u/technew)\
**Post date:** [October 15, 2019, 12:52pm UTC](https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603/3 "2019-10-15T12:52:48Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [October 15, 2019, 1:05pm UTC](https://discourse.processing.org/t/onpinch-not-working-ketai-library/14603/4 "2019-10-15T13:05:48Z")

</div>

Daaaamn, is truth, I forgot it… 🤯🤯🤯🤯 !!! ( and wasted many time 😓)

Thanks @technew 🤗
