Draw custom map tile images (.pngs) on top of Google Map - Android - java

I have png images of map tiles over parts of the UK and i want to draw them on top of the google maps view, I have everytyhing set up, just want to be able to draw the tile images now.
My main class extends 'MapActivity', can i add a canvas function to draw them?
ALso, I only obviously need to draw the tiles that are in view on the phone while the tiles out of view should not be drawn.

You can add an Overlay to the MapView, that will get you a canvas to draw on. See http://code.google.com/android/add-ons/google-apis/reference/com/google/android/maps/Overlay.html

Related

Drawing line or connection between Views in Canvas

I am trying to achieve something like in below image. I have several Buttons around a View and would like to connect them using Canvas on their background. I am able to place the Buttons and View in a manner required for my project, but I've no clue how to place a Canvas behind it and connect all of the Buttons to my View.
I've no clue how to place a Canvas for such requirement and how to find the Button's & View's center co-ordinates in Canvas so that I can draw line between View's Coordinate and Button's Coordinates.
For this, you will need a custom ViewGroup class (please refer to this doc).
You could also just start right away with Linear or RelativeLayout as a superclass, this way you will have all the chil-positioning logic ready for you.
You will need to override the dispatchDraw method. Inside dispatchDraw(), iterate through your children and draw your lines on the canvas. Please tale care to draw the children after you draw the lines.

How to create a custom Android view? Using XML objects or a drawing API?

I'm trying to create a new view that would:
load an image
allow the user to zoom and rotate the image with two fingers while a "cropping box" stays translucent over the top while the image extends beyond the "cropping box"
with the end goal of being able to mark the rotation and position of the main image (so that later i could crop out or show the area within the cropping box)
I'm wondering if I can do this with an ImageView holding the image in the background and another ImageView holding the crop box on top of it, then using TouchEvents to move the image, would this work?
Or do I need to use some drawing API on a 2D surface?
I'm just really new to creating custom objects in Android that aren't just customized out-of-the-box Views.
What's the standard way of creating something like this?
Thanks!
Create a Compound View by extending RelativeLayout with two overlapping ImageViews in it. Then override onTouch event or override onGestureDetector interface in that newly created View.
Official Documentation: http://developer.android.com/guide/topics/ui/custom-components.html
Another Tutorial: http://www.vogella.com/tutorials/AndroidCustomViews/article.html

android: make portion of an imageview selectable

How do I make part of an image view selectable with a resizable rectangle? (like the crop functionality) .
the image view:
EDIT:
I have successfully drawn a rectangle on the image view,by using canvas. how do I make the drawn rectangle dragable by the user?
I suggest you to extend the ImageView. You can have a Rect variable in your class which you can use to determine the cropping area. Than you can override onTouchmethod to handle touch events to manipulate the cropping rectangle and override the onDrawto draw the cropping area over bitmap.
There is also this cropper library you can use to avoid all the hard work by the way. https://github.com/edmodo/cropper

Options to put corners in Android ImageView

I'm trying to put corners im my ImageView and I find these "workarounds":
1 - Take the Bitmap soure and paint then
2 - put a second ImageView on my layout and use shape+corners as its source
It's not possible take the image view and put a corner around then?
In my app i have a List with a lot of ImageView (the Bitmap used in this ImageView's is programmatically) and I want to put corners in every ImageView.
There is any other option?
You can create a selector that contains shape with rounded corners, and then apply it as the ImageView's background using xml.
Look at this answers here
You can also do it via code by using PorterDuffXfermode. PorterDuffXfermode uses alpha compositing that will allow you to create and intersection (things of mathematical sets here) between the Canvas you get from onDraw() and an off screen Canvas you will have to create. You will use one of the PorterDuff.Mode flags to tell the framework you want to only render the pixels that intersect from the two Bitmaps in each Canvas.
More on Alpha Compositing

Animating a mask for png image in Android

So I am trying to develop an animation that fills a png into white like this:
For the transparent woman, I have a custom view that draws the png, and an AsyncTask for the animation that calls the view's invalidate() method.
I was able to draw and animate almost everything, but I cannot find a solution for filling the png from bottom to top. How can I create a "mask" that draws exactly the shape of the woman in white from bottom to top?

Categories