How to implement a zoom in method in a View? - android

I Have created a guidance application which consist a map. This map is drawn dynamically using the data from the database.[rectangle coordinates] To draw the map i have used a View class and overriden the Ondraw method.
The problem is that i cant find a way to implement the zoom in functionality. I have already used Gesture Detector class to handle OnLongPress and the OnTouchEvent methods. I was thinking of the Pinch-to-Zoom-in functionality but have no idea of how to do it.
Looking forward for some great ideas. Thank you!
Classes extends
View
GesturDetector

Can you give us some more information about how you are drawing this dynamic map? For now, I'll make an assumption and run with it. If you are drawing shapes on a canvas you can point the canvas at a Bitmap to draw onto:
Bitmap myDynamicMapBitmap = new Bitmap(MAP_WIDTH, MAP_HEIGHT, Bitmap.Config.ARGB_8888);
mapCanvas.setBitmap(myDynamicMapBitmap);
// Draw your map on the canvas here
Now that you have a bitmap representation of your map, you could utilize this open source project, which is basically an adaptation of the built in Android photo gallery app that allows users to pan and zoom images:
ImageViewZoom on GitHub
I've used that project before for an app, and it works really well. You may need to tweak it some to get your desired behavior (for example disabling panning, since you didn't say you wanted that).
Then all you have really have to do is:
imageViewZoomInstance.setImageBitmap(myDynamicMapBitmap);
That view includes built-in pinch zooming. You'll probably want to merge it with your current View that you've created.

Related

Android dynamic custom views on a map

I'm struggling to find a solution to the following problem in Android:
there should be custom views on the map which should animate/expand/etc just like regular views. For instance I need a current user location indicator which "pulsates" on the map, or I need some kind of marker clustering with the following behavior: when I tap on the cluster all the pois from this cluster are animated out evenly spread around the cluster so you can click them individually.
I've seen solutions involving periodically drawing into bitmap canvas and then updating the marker's bitmap, but it doesn't help when you want to click on the expanded items in the bitmap, also animating a marker with updating it's bitmap would look horrible and clunky.
On iOS for example there is a class MKAnnotationView which you can override and draw however you want, why doesn't android have such a simple feature? How can this be achieved in Android? Any help is appreciated.

Pinch and Zoom,Drag n Drop,Rotate Multiple Images in SingleView in Android

I am trying to create an app which would allow me to add images to a view using button click . Once added the images could be scaled,dragged,rotated depending on the touch gestures individually . I tried out all codes available out there, like:
1.https://android-developers.blogspot.jp/2010/06/making-sense-of-multitouch.html
2.//github.com/judepereira/android-multitouch
3.//github.com/Almeros/android-gesture-detectors
4.http://www.c-sharpcorner.com/UploadFile/88b6e5/multi-touch-panning-pinch-zoom-image-view-in-android-using/
5.//github.com/MikeOrtiz/TouchImageView/blob/master/src/com/ortiz/touch/TouchImageView.java
6.//www.codeproject.com/Articles/319401/Simple-Gestures-on-Android
In all above codes which worked great,I found one common thread that is they were implemented using Canvas and manipulated just one bitmap.I tried using canvas but that ensued another problem, How can I draw bitmaps to canvas dynamically, which would be like redrawing the canvas. I did try it but couldn't find a way to get reference to existing canvas object which is available only inside onDraw method while I needed to trigger the onDraw method from the parent Activity class. It would be great help if someone could guide me .

Android Games specifically bitmaps

I'm building an android game and this is more of just best practices and performance question.
For the bitmaps that I have that the user interacts with, should I place them in an imageView and set an onTouchListener for each of them individually or should I just draw them onto the canvas and use the custom view's onTouch method to obtain the x and y of the touch and see if it falls in the range of any of the bitmaps to detect a touch.
My custom view takes up the entire screen, and I don't know how if it is even possible to draw an imageview onto the screen using a canvas which is why as of now I just use the onTouch method.
Thanks for any insight.
Depending on how dynamic your bitmaps render will be, you should go for either GLSurfaceView or SurfaceView, for something simple as just bitmaps i would recommend you to use SurfaceView as "renderer" where you can get the canvas from and of course you can draw on the whole screen if your surfaceview match the screen size.
TouchListener should be completely separated handled on its own listener promoting encapsulation and reuse of code for future apps that you want to do. I've found this quiet helpful for the last games i've developed asingning a surface view as renderer and just creating Objects which takes the canvas as parameter and drawing them self into it, the only thing you have to take on count is the bitmap resource management, but if you are careful of releasing and creating them when is proper, you should have no problems...
Regards!

PinchZoom and paning using surfaceView

I am developing a RDP application using android 3.0. I am using surface view to display the images. Is there any way to implement pinch zoom functionality for surface view(I am trying to zoom the image).
Subclass surfaceview and implements onTouchEvent(). Use a GestureDetector and GestureListener to modify a matrix representing the current state of manipulation and draw your canvas modified by this matrix.
It works, but is a piece of software to figure out. Took me around 6 weeks to have everything set up correctly, especially if you want some overlay items which also listen to touch events. I'd think about publishing that code, but it's company code...

Can somebody suggest me svg library for android?

Can somebody suggest me svg library for android? I have a list of objects with coordinates and I need to draw them like circles on a svg picture and on click a new activity shall be opened. It is importanrt that I can implement zoom in/out on that map.
You can extend a view and override the onDraw method which gives you the canvas.
Using the canvas you can draw circles.
One svg library that works on mobile devices is d3.
It can do everything you described. (Take a look at this code example with zoomable circles).
Here you can find a video tutorial that explains how to use d3 for mobile devices.

Categories

Resources