Best way to have a zoom and pan image overlay on Android? - android

I'm relatively new to Android development, and I'm currently developing an app that requires a pinch-zoomable and pannable image that will have other images overlaid on top of it, similar to a MapView but without using the Google Maps API.
I've done a bit of looking and found that I may be able to accomplish the overlay portion by doing the method in this question: Draw images on top of each other in android
However, I don't know if that would make the ability of doing a pinch-zoom and/or panning a large image feasible. Would it be worth it to create a GLSurfaceView and just implementing the needed functionality, or is that overkill because I'd be reinventing the wheel?
For what it's worth, the large map image itself will be fetched from a server (but if needed it can be split into smaller square regions), and the icon that will be overlaid at various positions on the map will be embedded in the app itself.

Sony Ericsson made an excellent PinchZoomable ImageView class. I modified it for my needs. I merged their pinch zoom and single-point touch zoom (for phones that didn't have multitouch) http://code.google.com/p/motivatormaker-android/source/browse/MakeMotivator/src/com/sonyericsson/zoom/ImageZoomView.java
Their tutorial is here: http://developer.sonymobile.com/2011/04/12/how-to-take-advantage-of-the-pinch-to-zoom-feature-in-your-xperia-10-apps-part-2/
I got pretty good performance out of using these classes without needing to use OpenGL.

Related

Scaling and dragging vector graphics in Android

I would like to be able to incorporate hand gestures to several hundred to thousand dynamically generated polygons so that I can pinch to zoom and drag all of them (not individually) simultaneously in Android. What is the best way to achieve that? Obviously, if there is a library that would be great, but if not could/should I scale/drag the canvas or the view object? An alternative is to convert the vector to a bitmap image, but I think for my purposes it would be very computationally intensive to do all that processing.

How to Create a 2D Map for an RPG Game

I am working on a text RPG game for Android, and would like to create some kind of an area map for the player's reference. I Googled it but was directed to Tiled. I am not trying to create a playable level map, just a basic map that the player can open to see areas explored so far for easier navigation. I would probably create these graphics myself using Fireworks.
The problem is a phone screen is only so big, and I need to somehow allow the player to swipe left/right/up/down to see all parts of the map. I guess on the biggest tablets perhaps the whole map would fit, but I need to support smaller resolutions as well.
So basically I think I need a way to display the map image in an activity (which I know how to do, duh), and allow the user to scroll around it because it will be way bigger than the screen.

Implementing Pinch and Zoom on Android SurfaceView

I am using a SurfaceView to display a large image (usually bigger than the screen, but not always) in an Android App. This is really trivially simple graphics, and it is easy to implement scrolling using an OnTouchListener or GestureDetector. Graphics run in a Render loop, but performance seems to be more than adequate for all real devices (the emulator can be a bit of a pain, though).
I'm considering implementing Pinch and Zoom on the image as well, but I would prefer to avoid having to go to OpenGL, since I have very little experience with OpenGL and using OpenGL seems like pretty much overkill for something this simple.
It seems as if the android.graphics.Camera class might allow me to implement the zoom functionality that I would like.
Does anyone know of any good examples that show the implementation of a pinch-zoom like functionality on a basic Android SurfaceView?
Also if you have implemented something like this, any thoughts on performance? Is OpenGL worth the extra hassle, given that what is required here is so simple?
Is the question unclear here, or am I missing some blindingly obvious documentation/code on the Android developer site that I should have found?
OK - having finally had time to really work and research on this for some length of time, I actually found a solution that solves the problem I had.
The solution relies on the BitmapRegionDecoder (API10+). What this does is allow the app to load in a part of a bitmap, rather than attempting to load the entire bitmap in one go.
The essence of the solution:
A downsampled version of the entire bitmap is kept in memory. Because this version is downsampled, it can be kept there permanently.
A thread loads in the current viewport (or a bit more) of the bitmap to memory continually (using BitmapRegionDecoder). As this is at most slightly larger than the screen, this should also fit comfortably in memory.
The rendering thread draws the appropriate version to the Canvas; i.e., if you are zooming out or the bitmap is not available (e.g., because it is loading in the background), then the downsampled version is used.
Pan, Fling, and Zoom are handled with GestureListeners.
Credit goes to John Lombardo for the first implementation of the idea I've found.
I open-sourced my own implementation along with some of my other utility classes at https://github.com/micabyte/android_game
It's a pretty recent implementation, so its not had the baptism of fire from real users at this time. However, I've run tests with displaying 8000x4000 pixel bitmaps and had no issues so far. Performance certainly seems adequate for my needs.
Implementing pinch and zoom is something that you would do with a combination of the ScaleGestureDetector and the Canvas interface with a transformation matrix. You'll want to make use of the same transformation matrix to handle both scale and translation.
Take a look at the One Finger Zoom example on the Sony Ericsson developer site.
http://developer.sonymobile.com/wp/tag/zoom/

AndEngine VS Android's Canvas VS OpenGLES - For rendering a 2D indoor vector map

This is a big issue for me I'm trying to figure out for a long time already.
I'm working on an application that should include a 2D vector indoor map in it.
The map will be drawn out from an .svg file that will specify all the data of the lines, curved lines (path) and rectangles that should be drawn.
My main requirement from the map are
Support touch events to detect where exactly the finger is touching.
Great image quality especially when considering the drawings of curved and diagonal lines (anti-aliasing)
Optional but very nice to have - Built in ability to zoom, pan and rotate.
So far I tried AndEngine and Android's canvas.
With AndEngine I had troubles with implementing anti-aliasing for rendering smooth diagonal lines or drawing curved lines, and as far as I understand, this is not an easy thing to implement in AndEngine.
Though I have to mention that AndEngine's ability to zoom in and pan with the camera instead of modifying the objects on the screen was really nice to have.
I also had some little experience with the built in Android's Canvas, mainly with viewing simple bitmaps, but I'm not sure if it supports all of these things, and especially if it would provide smooth results.
Last but no least, there's the option of just plain OpenGLES 1 or 2, that as far as I understand, with enough work should be able to support all the features I require. However it seems like something that would be hard to implement. And I've never programmed in OpenGL or anything like it, but I'm willing very much to learn.
To sum it all up, I need a platform that would provide me with the ability to do the 3 things I mentioned before, but also very important - To allow me to implement this feature as fast as possible.
Any kind of answer or suggestion would be very much welcomed as I'm very eager to solve this problem!
Thanks!

Android - Generic Zoom

Are there any android zooming solutions that can be applied to a generic android view?
My app needs to push a lot of information onto the screen, and on some phones, screen is so small that this data becomes unreadable.
I want to get zooming functionality that works for textview's and image buttons in particular. I imagine a zoomView that works for these two built-in's would work for most of the others too.
I've looked around on the web and haven't found any easy solution yet. Most of the discussion seems to be focused on zooming images or a webview.
If there is not an existing solution, can anyone suggest a good approach to take?
Are there any android zooming solutions that can be applied to a generic android view?
That is not possible except perhaps on Android 3.0. On Android 3.0 (API Level 11), you have getScaleX() and getScaleY() which might suit your needs.
If there is not an existing solution, can anyone suggest a good approach to take?
Design a different UI optimized for smaller screens.
Or, use a ScrollView (or HorizontalScrollView) and use bigger widgets (effectively pre-zooming your content).
You can try to implement your own pseudo-zoom by changing the text size and button sizes based upon user input (e.g., options menus to zoom in/out), but I'm not sure how well that will work.

Categories

Resources