Draw a line between view and shadow - android

I am trying to implement drag and drop in Android now. I want to draw a line between View and its DragShadow. It should looks like this:
image here
I have already tried to implement it in two different ways:
First, I tried to update the end of the line when DragEvent.ACTION_LOCATION occurs. But it's not smooth, because frequency of this event is not appropriate.
My second approach was to create custom DragShadowBuilder but I couldn't draw a line on Canvas of DragShadow because it has fixed size and follow cursor.
How could I implement this properly?

Related

How to draw custom shape in android using canvas in viewgroup

I want to create a shape like this image.
I searched a lot for drawing on canvas with different shapes.
I didn't got anything on StackOverflow or Google.
Here is the link I referred
In this tutorial I got to know how to use the curves with canvas.quadTo();
Android How to draw a smooth line following your finger
How to draw a curve according to a control points list that has more than 3 points
//here i got to know about canvas.cubicTo() method which will give curves from start point to end point with middle point.
I don't have any code to show, so, I need to start from scratch.
I need this to be created as ViewGroup, so that I can add 1 View to this ViewGroup. If I add another View into this ViewGroup then the background should look like this.

Android spinning wheel (pizza)

I am trying to create a circle wheel divided in a fixed number of sections. Each section should be clickable.
How I approach this? Should I make an image and set as a background or is there a way to draw all parts in java?
Shortly:
Create .png with pizza.
Create new widget, extending View.
Override onDraw() and draw it to canvas with some rotation. Optionally you can draw lines with java if it's margeritta not a pepperoni.
If necessary - change rotation call invalidate() to redraw view
Add onTouch() listener, get position ot tap, calculate what sector was touched.
One Solution would be to draw different paths for each piece on a Canvas (path.lineTp and path.addCircle - think so). Then you can add ClickListeners to the paths and they will be clickable....

Draw a line on top of entire layout in Android?

I am drag and dropping an ImageView on to another ImageView.
I am following this http://developer.android.com/guide/topics/ui/drag-drop.html
While I can display a drag shadow and change drop targets with different colors and drawables. I am happy with the article.
But I am looking for a little bit more. I am looking to draw a straight line between my drag shadow and the source. I want this line to be straight and update it's length and direction as I drag the item around. When I finally drop the item in my drop zone I want the line to stay permanently (unless I remove it later).
Like this:
Drag without line, this is my current situation
Drag with a line following, this is what I want
I should also mention that I want to do this with multiple sources and single target (maybe multiple target in future).
Here is the code that I am working on https://github.com/ishanatmuz/HelloDrag
I think you will need to override onDraw( Canvas ) and then when you are dragging call a routine to draw your line.
When you are not dragging draw the lines between the boxes.
both routines as sub-routines of onDraw
If you do this don't forget to call super.onDraw( Canvas ).

Android - custom view and animation

I am experimenting with Views in Android and am trying to create a custom 'widget'. What I want to do is create a portion of a circle with an indicator at 12'o clock. I'd then like to to swipe over the circle and when I do, I'd like to see the indicator move to left or right corresponding to a swipe to the left or the right.
I have looked up a number of sources however I am unsure of how to draw an 'indicator' within the arc. In addtion, what needs to be done to animate the arc ? Can this be achieved without OpenGL ?
I am aware of the circlular progress bar and I believe the problem is quite similar, however I didn't have to add a marker inside the circle.
Here is an image of the screen shot of the View I would like to recreate:
This approach would work,Creating a View with rounded corners and position it to bottom to make it seem like arc

Drawing curved lines in AndEngine

I am new to AndEngine and very happy that it's very easy and exciting thing to do. Unfortunately I am unable to draw a curved line in AndEngine.
Actually my scenario is that I have an animated sprite say Object. I want to move this object on a Line with the points given onToucing and dragging it. Now the problem is that I can't find any method to draw a line on points in a way that it does not produce corners. I want a smooth line with no corners.
Suppose I touch the object and drag it on the screen with the points of a square type region. But I don't want the corners in it. I want curves. Previously I am doing this by using quadTo(..) function of android to do this. All I want is a complete alternative to quadto function in AndEngine but with same functionality.
You have to stitch together the curved line from many many small straight lines.
Moving an object along a line is a very different task though. You'd want to have a look at CubicBezierMoveModifier and QuadraticBezierMoveModifier for those.
Maybe you can actually use the code in those modifiers to create your 'smooth' line.

Categories

Resources