0

Hi I am stuck in a same situation. I am developing an application using OpenGL ES 2.0 where I need to test out the multi-touch part of the code. Below is my onTouchEvent. If the pointerCount is one then i'm rotating and if the user uses pinch action with two fingers I zoom in to the model.

@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
    touchedX = event.getX();
    touchedY = event.getY();
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
    if (event.getPointerCount() == 1) {
        activityRenderer.xAngle += (touchedX - event.getX()) / 2f;
        activityRenderer.yAngle += (touchedY - event.getY()) / 2f;

        touchedX = event.getX();
        touchedY = event.getY();
    } else if (event.getPointerCount() == 2) {

        float x = event.getX(0) - event.getX(1);
        float y = event.getY(0) - event.getY(1);
        float newDistance = FloatMath.sqrt(x * x + y * y);

        if (newDistance > oldDistance)
            activityRenderer.zoom += 0.05;
        else
            activityRenderer.zoom -= 0.05;

        oldDistance = newDistance;
    }
}
return true;
}

Below is the test case:

public void testZoomIn() {
mActivity = getActivity();
mActivity.startActivity(mActivity.getIntent());
Log.w("INSTRUMENTATION", (getInstrumentation() == null)?"yes":"no");
generateZoomGesture(getInstrumentation(), 1000, true, new Point(1, 2),
        new Point(20, 45), new Point(3, 4), new Point(25, 55), 2000);
assertTrue(true);
}

I used the same method for the generateZoomGesture that is shown here. The test class extends ActivityInstrumentationTestCase2. I used assertTrue just to see whether my code get covered or not. I will have to change the assert statement. But the problem here is that the test does not get inside the else if(event.getPointerCount() == 2) block. Can you help me find out where am I going wrong?

Community
  • 1
  • 1
Wizard
  • 1,154
  • 2
  • 14
  • 41

1 Answers1

0

You need to try switch case,write multi-touch need to use MotionEvent.ACTION_MASK,but you not. ps. I am new for android ,I hope this explain is right。

public boolean onTouchEvent(MotionEvent event) {
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        Log.d(TAG, "down");
    case MotionEvent.ACTION_POINTER_DOWN:
        Log.d(TAG, "pointer down");
    case MotionEvent.ACTION_MOVE:
        int pointerCount=e.getPointerCount();
        Log.d(TAG, "move");         
        if(event.getPointerCount() == 2){
           Log.d(TAG, "c =" + event.getPointerCount());
        }
    }
}
alei chen
  • 1
  • 1