user3290805
user3290805

Reputation: 475

Handling multiple touch in android such as Pinch In and Pinch Out

I am trying to achieve multi touch in such as way that when user pinch out with two finger outside I need to handle one event and on pinching In other event. No ZOOMING IN or ZOOMING OUT NEEDED.

So I am handling onTouchEvent on layout, but could not get conditions true for pinching in and pinching out.

Here is code,

 layout.setOnTouchListener(new View.OnTouchListener() {
        private int mActivePointerId;
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            mActivePointerId = motionEvent.getPointerId(0);
            Log.d(TAG, "COUNT"+motionEvent.getPointerCount());
            if(motionEvent.getPointerCount() > 1){
                if((motionEvent.getAction() == motionEvent.ACTION_UP) && (motionEvent.getAction() == motionEvent.ACTION_POINTER_DOWN))
                Log.d(TAG, "Multi Touch Upwards ");
                return true;
            } else if((motionEvent.getAction() == motionEvent.ACTION_DOWN) && (motionEvent.getAction() == motionEvent.ACTION_POINTER_UP)){
                Log.d(TAG, "Multi Touch DownWard ");
                return true;
            }
             else{
                Log.d(TAG, "It is signal Touch");

            }
            return true;
        }
    });

I referred this link but not very clear example Any suggestion to make it work...thanks

Upvotes: 2

Views: 1112

Answers (2)

JNI_OnLoad
JNI_OnLoad

Reputation: 5442

You can make it work with the help of ScaleGestureDector. Just need to check the scalefactor if the scale factor would be more then 1 then it would be Pinch Out otherwise Pinch In.

Here is good example, it is very easy and fits your need well, Just follow the instruction from this link ScaleGestureDector

Upvotes: 2

Vlad
Vlad

Reputation: 910

So , you need to use a GestureDetector.

Whatsoever you need to do with that pinching out and in, you can most likely do with a gesture listener.

Check out this link and take 5 minutes to read, your answer is there for sure: http://developer.android.com/training/gestures/detector.html

Just for the record:I have been using GestureListener recently ,so it's a "sure thing".

Upvotes: 0

Related Questions