Draw a rounded corner square in android canvas - android

Picture 1 depicting path to draw. Picture 2 depicting the final result
This is a bit more of a geometry-inside-java question. Basically, I want to round a single corner of a square I drew on a canvas, sometimes it's on the top left, other times on the top right, or bottom left or right. How could a shape like the red highlight be drawn and filled using Android's drawing methods? I've read the drawing tutorials on Oracle, but I can't still figure out how to draw something like that in that position. Any help would be greatly appreciated.

Related

Draw Arc horizontally on a view layout

Task : To animate arc with alpha, scaling pulse
I have done almost everything using this Code : "https://github.com/booncol/Pulsator4Droid/blob/master/pulsator4droid/src/main/java/pl/bclogic/pulsator4droid/library/PulsatorLayout.java"
The only change I want to do instead of full circle I want half of it only arc would be great. But this drawn shape should be from bottom to top and placed horizontally on view.
I have searched half of the Internet for implementing this silly thing but
my drawn arc or circle is either like : "(" or ")" I want this curved shape to be facing top like in Some outgoing radiation type.
Have a refference from this link
https://github.com/DevLight-Mobile-Agency/PulseView
This will generate a wave from your icon's shape..
So i believe, for semi-circle wave, the requirement will be a semicircle icon .

Draw text on oval path in the centre

I'm trying to draw some text on path using the canvas in Android. I can successfully get the text to draw on the top oval line. What i'm struggling to do is make sure that the text is centered.
The problem is that while i can measure the text before it gets drawn round the top line of the oval, i cannot measure it after. This makes estimating where the text should be drawn on the top oval line problematic as it's always a little bit out. This is because when i measure the text to be drawn initially it is measured in a straight line and not as presented on the top line of the oval.
I've tried applying setTextAlign(Paint.Align.CENTER) but this makes the text get drawn about 3/4's of the way round and not what i want.
Does anyone have any ideas how i could calculate the point to draw the text so it is drawn dead centre of the top oval line or any alternative method that may help?
This has to be drawn using the canvas. It can't be done using XML TextViews etc.
Thanks.
You can check how this library done it: https://github.com/amulyakhare/TextDrawable
Its using the same approach. But for multiple lines its almost impossible, theres an issue on this library where me and other developers tried to implement it, and we end up using just xml (a round drawable as a linearLayout view background and one textView inside it).

How can i create a border on custom view with many drawing shapes

I want to apply the border to this custom view shape
which created by many canvas.draw...() in onDraw()
The border that i want to create and apply to my custom view should have equal range all the way with some distance from the custom view and it should also cover small circle in each slice.
Any idea how to make this?
Thanks.
This isn't so much an answer, but more of a recommendation. Take a look at the Porter-Duff modes available to you. Worst case you may need to do some per pixel image manipulation which should be fine as long as the view isn't animated.
On second thought, here's an idea: why not create two images: one large circle which will always draw behind everything and a second which will always draw behind the small circles. The large circle would just be the complete border you want displayed, whereas the small circles would actually only be a semi circle border, which would render on top of the large circle (covering the large circle border under it). The key would then be to rotate the small border circle depending on where it's located. I hippie that makes sense, but it should work and be very efficient too.
Another option would be to separate the rendering into white circles and slightly larger border color circles. If you render the slightly larger (border color) circles first, then render the normal circles (white) on top, then you won't have to worry about any rotations and it will render correctly if the small outer circles begin to overlap.
So the idea is similar to the first suggestion. You'll still need a large circle and small circle (both white), but in addition, you'll need slightly larger border colored large and small circles.
I hope this description is a little clearer, but I assume that you are comfortable enough with compound drawables to figure out the rest, given that you've gotten this far in making your view.
All the best implementing it, and feel free to ask for any clarification! :)

Android: how to make a drawn shape move & how to draw just part of a shape like a 3/4 solid circle

Animation:
All the animations on the Android books I read are made on an existing image. They load an image on the SD card and use animation functions (like alpha, scale, translate and rotate) to make it move. However, what if I want to make the shapes I drew move on the screen. For example, I just draw a circle on the screen and want to make it move from left to right. How can I do this?
Painting:
Functions like drawCircle can draw complete geometric shapes but I just want to draw part of a shape, for example, a 3/4 solid circle. How should I do? If I use drawArc, there will be a 'V' recess on the circle and I want it to be flat.

Drawing a circle in openGL for android

So I'd like to be able to draw a circle where I can specify the amount of circle drawn as shown in the following diagram.
AS an opengl newbie I'm not really sure how to approach this.. I've previously drawn full circles using GL_TRIANGLE_FAN
You already know how to draw a circle using a triangle fan. Now you just have to calculate the angles of the cutoff corners, use those as the beginning and end of the arc and place the hub of the triangle fan at the middle of the cutoff edge.
you could use a glScissor test to cut off the parts of the circle that you don't want.
http://www.khronos.org/opengles/sdk/1.1/docs/man/glScissor.xml

Categories

Resources