I'm trying to add pan to my app, I think for pan I should subtract older finger position from new position and then translate , is it what I want ?
- boolean surfaceTouchEvent(MotionEvent event) {
- pointNum=event.getPointerCount();
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
- case MotionEvent.ACTION_DOWN:
- //User is pressing on finger
- float x0=event.getX(0);
- float y0=event.getY(0);
- mode = false; //DRAG
- break;
- case MotionEvent.ACTION_POINTER_DOWN:
- x1=event.getX(0);x2=event.getX(1);
- y1=event.getY(0);y2=event.getY(1);
- float z4 = dist(x1,y1,x2,y2);
- mode = true; // pinch
- break;
- case MotionEvent.ACTION_POINTER_UP:
- // User is released one of the fingers.
- break;
- case MotionEvent.ACTION_MOVE:
- if (mode = false){
- x1=event.getX(0)-x0;
- y1=event.getY(0)-y0;
- }
- if (mode = true){
- x1=event.getX(0);x2=event.getX(1);
- y1=event.getY(0);y2=event.getY(1);
- float z3 = dist(x1,y1,x2,y2);
- if ( z3 > z4 ){
- zoom += 0.1;
- }
- else if ( z3 < z4){
- zoom -= 0.1;
- }
- }
- break;
- }
- return super.surfaceTouchEvent(event);
- }
I saved older positions in
case MotionEvent.ACTION_POINTER_DOWN for zoom and
case MotionEvent.ACTION_DOWN for pan
this is the errors :
- -compile:
- [javac] Compiling 2 source files to C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\bin\classes
- [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:118: variable x0 might not have been initialized
- [javac] x1=event.getX(0)-x0;
- [javac] ^
- [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:119: variable y0 might not have been initialized
- [javac] y1=event.getY(0)-y0;
- [javac] ^
- [javac] C:\DOCUME~1\T0P4568\LOCALS~1\Temp\android893850823480544580.pde\src\changethispackage\beforesubmitting\tothemarket\sketch_may28a\sketch_may28a.java:125: variable z4 might not have been initialized
- [javac] if ( z3 > z4 ){
- [javac] ^
- [javac] 3 errors
please help!
1