Reputation: 1904
I am working on an app for Android, which is supposed to get an image from another activity, display it, and then one should be able to zoom in and out on this image using pinch to zoom. I tried to achieve this with the following code, however I get an error on onTouchListener. It says "onTouchListener cannot be resolved to a type", but I don't get why. I can't import it or anything, and I think the syntax is ok. Anyways, do any of you know what the problem is?
public class ImageEditing extends Activity implements onTouchListener {
ImageView selectedImage;
Intent intent;
private float oldDistance = 0f;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.imageediting);
// Load the selected image
selectedImage = (ImageView) findViewById(R.id.selectedImage);
String imagePath = getIntent().getStringExtra("com.andriesse.henk.path");
Bitmap bitmap = BitmapFactory.decodeFile(imagePath);
selectedImage.setImageBitmap(bitmap);
selectedImage.setOnTouchListener(this);
}
public boolean onTouch(View v, MotionEvent event) {
if((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) {
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) {
oldDistance = newDistance;
} else {
oldDistance = newDistance;
}
}
}
return true;
}
}
EDIT:
The issue with onTouchListener is solved, but pinch to zoom doesn't work. Does anybody have a clue why?
Upvotes: 0
Views: 1845
Reputation: 14472
public class ImageEditing extends Activity implements onTouchListener {
OnTouchListener is a class interface and therefore begins with an uppercase letter.
public class ImageEditing extends Activity implements OnTouchListener {
Upvotes: 2