We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Could you please provide me an example code in processing i3 that i can make zoom with two fingers in my App,in Android Mode??I would like to zoom in the whole screen, not only in a shape..
Answers
I tried to use the method void onPinch() like:
but i cant find what i might put instead of rextSize to zoom the whole app, whole screen.
@ermina===
i dont know with only processing but using android apis you can do that very quickly; guidelines:
you import onTouchListener && import android.view.MotionEvent && import android.graphics.Matrix;
you add your listener to some object (let us say your imageView) and its initial matrix (which is 1): myImage.setScaleType(ScaleType.MATRIX);
you create on touch() method; it returns the touch event and transmits it to the main method: onTouchEvent(MotionEvent event)
in this method you count the pointers (event.getPointersCount()) and get the coordinates x && y for them with event.getX, event;getY() or event getRawX() && event getRawY(); so you have 4 values (if two pointers: you can add here some restriction in order to eliminate the case that two pointers are very very near: they are 2 if(....)
now you can calculate the (euclidian) distance between the points and according to it you have to scale the bitmap to the new matrix: which can be greater (1.5....10.....) or smaller (0.1, 0.5........) ; dont forget to center the matrix on the midpoint of the bitmap.
finally you have to add a timer in order to get rid of the old values (from getX()...)
that's done!
more details: https://developer.android.com/reference/android/view/View.OnTouchListener.html
PS: you can also use the onScaleGestureDetector API: https://developer.android.com/reference/android/view/ScaleGestureDetector.OnScaleGestureListener.html
I am using grafica library to make plots..Maybe is there special functions for zooming the graph??
I know that in Java Mode i can zoom the graph with the function
plot.activateZooming()
but when i turn into Andoid Mode doesn't worked.Is there an example code for zooming with two fingers in a plot??
I am not familiar with grafica and I know even less about zooming. You should have a look at the source code here:
https://github.com/jagracar/grafica/blob/master/src/grafica/GPlot.java
Go to line 2606 and 2651 (Sorry I could provide you links but my browser is playing tricks on me this morning)
For instance:
To succeed, you need to understand how this operation is managed in the Java side by Grafica. Then you will need to translate it to Android. In the Java side, I can see that the activateZooming also defines, as a minimum, what mouse buttons are required to zooming in and out. Can you override or re-defined the behavior so to use gestures in Android? Not sure. What you should do is forget activateZooming() for a moment and dig into the code and follow zoomingIsActive which is a boolean variable. Understand how this variable affects the zooming action on a Grafica Plot object. After you understand this, then you can try to use Android gestures.
Kf
@ermina===
Though i never used this lib i can see that zooming is triggered by the mouse buttons and wheel, which of course do not exist for android. So you have to forget it and implement androi!d TouchEvents as i have explained.
@akenaton i can not understand how it works..Is there an example or a template??And will it works with grafica library??
@ermina===
as i have said i never used this lib; yet if using it you can write code which runs except for touch events (and reading your posts that seems the case) you can try the way i told. As for examples i cannot be more precise: depends of what you want to zoom in/out...
I hope one can hook android gestures to the zooming in Grafica. It will be an useful tool in the Android arsenal. For this, one needs to dig in the source code as I mentioned in my prev post. At this pt, not sure if it is doable without major changes. Did you file a tix in the grafica repo as a feature request? If not, please do so and cross-link your tix with this post.
Kf
Hi, this example shows how you can implement the zooming effect using the mouseClicked method. I'm not an expert in Android but I guess you can do the same using the touch event methods.
Cheers, javier
I have just made some changes and it worked only zoom in..Any ideas how to zoom out???
Check if the d value from onpinch is positive or negative. This is pinching in or out which should be related to zooming in or zooming out. So, in your code you zoom in with 1.3 so zoom out with 0.8, for instance.
Kf