How to Use Customized fonts on Canvas(3 Questions included inside) - android

How to use Customized fonts on Canvas?
I have customized view (PIECHART DRAWN ON CANVAS) on left side of the screen and list view on right of the screen. When ever I touched on the canvas list view values has to be changed. is it possible. My listview is in Activity A class.And view is in B class.
I have piechart with n no of arcs. On tapping on that i have to known which arc is tapped. Is there any formula for it. (Like for rectangle basing on left,top and width hegiht we can check.)

In the drawText function in the canvas you have to provide a Paint object. Well the paint object has a function that accepts a typeface and it is called setTypeface(). Look more into that function and its uses and perhaps this tutorial and you will see that it is rather straightforward to use any font that you like in Canvas.
My advice would be to make questions 2 and 3 separate questions in their own right and improve your explanation of what you want to happen.

Related

How to create two circles of arcs moving by touch in Android

can someone please give me advice or instruction how to create custom view, which draws two circles with different (or maybe same) count of arcs, and the most important, enable rotating each circle independently anti/clockwise by touch move? But no moving on center hole.
I think image describe it best
rotating circles
I needed something like this and I can't find a component so I implement one.
A custom view that uses Canvas in onDraw method .
For each wheel you can add a list of String to show in each section and a list of Paint to paint that section .
https://github.com/mehdi-azizi/Nested-Wheels-View/blob/master/NestedWheelApp/app/src/main/java/com/ma/nestedwheels/NestedWheelsView.java

Android - How to create circle view with Android?

I am creating a View as below design here (like apple music).
pic 1:
pic 2:
The pink circle with physical interaction and fly. Can you suggest ways to make them?
Indeed, you should take a look at the custom view documentation.
What you should do to obtain such a result is to first override the onDraw() method in order to make your custom drawing inside.
Using the canvas, you will be able to create circle by calling :
canvas.drawCircle(x, y, radius, paint);
In order to make the circles look as you want, just take a look at the Paint documentation.
You can create as much circle as you want (the app efficiency is, of course, affected by the number of circle you draw).
With your custom view, you will be able to handle interactions easily, through the onTouchEvent() and to animate the circle modifying their properties over time.
You need to write own View as documented here https://developer.android.com/training/custom-views/index.html and then in your onTouchEvent() check if tap is inside or outside of area you consider checkable (in this case inside the given radius).

Drag and Drop Bitmap and TextView on Canvas- Android

I am trying to implement the drag and drop functionality in Android. I have a Custom View that overrides the onDraw(Canvas canvas) method to draw a Bitmap on a canvas that acts as my background. Then, I have created it so I can select different colors and paint in this area.
Now, I am trying to add the ability to select photos from the gallery and place them into the canvas. Also, I want to add the ability to create and add textboxes to the canvas area as well. How would I implement this?
I have read through several tutorials looking to create multiple views that are placed in a Canvas, but have not found an example of this being one. Am I understanding the Canvas and View classes incorrectly and is there a simpler way to do this? Any help is very much appreciated. Thank you.

Morph a retangler view into a circle [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I am trying to animate/morph a rectangular view/layout, as all views are rectangular. The user case for this would be: The user long-clicks a view that contains an ImageView or just the main view with a background, a new view would be generated being the size of the screen, then this view would shrink into a circle of a certain size. Possible solution I have found is extending the view class, therefore creating my own view and implementing a custom method, but I am confused on how to animate the view to shrink. Also the view would have to follow the users touch location continuously as it animates/morphs, adding more to the confusion.
A quick, not-so-thorough explanation to at least get you thinking in the right direction:
I think the big thing to keep in mind here is that whatever solution you find, the animation is going to be painfully slow unless you perform the transformations entirely within the view's onDraw(Canvas canvas) method. In other words, avoid anything that requires the view to measure and lay out for every frame of the animation. With this approach, you simply perform a frame transition and call invalidate() on the view to update. Keep in mind that you will lose most of your ability to interact with anything within the view in its circular rendering.
Since there are no shape-transforming animations built into Android, you will probably need to use something like Property Animation to roll it yourself. If you're supporting devices prior to Honeycomb (3.0), you will probably need to bring in the NineOldAndroids library and use its property animation capabilities instead. Essentially, you'll need to animate the values of the corner radius. Best case scenario, you're transforming a square into a circle. Otherwise, you need to do some cropping or dimension transformations as well.
To animate the view, you will first need to obtain a bitmap representing the latest render of that view. You can do that using the following code:
// Creates a bitmap in the size of the view
Bitmap bitmap = Bitmap.createBitmap(myView.getWidth(), myView.getHeight(), Bitmap.Config.RGB_565);
// Creates a new canvas that draws to the bitmap
Canvas canvas = new Canvas(bitmap);
// Draws the contents of the view to the bitmap via the canvas
view.draw(notifyCanvas);
You should only perform this once per animation, and it should occur just prior to performing the animation.
Next, you most likely need to create an empty extended View simply to hold the animated representation of the view you want to modify.
Implementing the transformation logic in onDraw(Canvas canvas) (which is done by extending the view as mentioned above), you have access to the Canvas object. Essentially, the Canvas object is the final layer that contains all the "draw" calls that render the view on the screen. Overloading the onDraw method on your new custom view, you can then use canvas.drawRoundedRect(...) to draw a rectangle with rounded corners and paint in the bitmap of the view we created in the code above. Within your custom view, you can keep a variable that stores the radius used by drawRoundedRect. As you animate, you set that radius to be larger and larger until you get a circle (granted, you'll only get a circle if the original shape is a square). This does get pretty complicated, and I've definitely skipped a few steps, but you can see a good example of a rounded view by checking out the RoundedImageView on GitHub. There are lots of good ideas in that library that you could borrow.
Apologies for not pulling together a more complete explanation. It's quite a complex task!

How to draw a shape in Android as one of other layout objects?

I've been working on this for a while but can't find anything that exactly addresses my question (at least not something easy to understand).
I have a main layout XML file where I define various layout objects like a Button or a TextView (and I know I can add SurfaceView, View, and view and other things too). I want to draw a shape (in my case it's an arc) in just one of these objects so it doesn't take up the whole screen and so I can position it relative to other things.
(In my case it will ultimately re-draw the arc kind of like a circle with a gap in a different position every time I call a method depending on a value I pass to the method, but that's separate from my basic question.)
I know the answer will have something to do with a canvas, an onDraw method, maybe Paint, probably a view. I have been able to draw a circle from a custom View object by setting the main java file's layout as that View (as opposed to R.layouts.main), but that takes up the whole screen, and I'm unsure how I might be able to have that dynamically draw with modifications.
A really clear explanation or better yet an actual example would just be awesome.
As i see it u need to draw a specific shape on widget and not on complete screen. Try using layer List.
you can refer this link for sample Link

Categories

Resources