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 ).
Related
so I am running into an issue when I'm trying to create transparent lines in my android drawing app. My desired functionality is for these transparent lines' alpha channels to remain consistent as I continue to draw. What is happening is that the transparent line is being created, but as I continue to draw with the same line, the opacity of the older parts of the line begins to increase. I added a sample of this and also the code snippets that correlate with this. I have tried playing around with the PorterDuffXfermode however it seems to yield the same result or the transparent line overwrites the lines it draws over. Any ideas, hints or links would totally be grateful. Cheers!
Code
Drawing
It looks like you are drawing over the faded line over and over in touchedMove(). As a result you line gets darker where there has been more overdraw and lighter where there has been less.
I would do all drawing in onDraw() or draw(). You invalidate the view, so continue to do that and draw only once. If you want to continue with what you have, only draw the portion of the line that the motion event represents.
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
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....
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?
I'm struggling with something I would expect to be straight forward with libgdx.
In short this is a "finger paint" app where I want to draw a path of a certain width where the user touches the screen.
I've earlier done this by using a plain Android android.view.View. I had a android.graphics.Path in which I stored the coordinates of the user's current touch. In the onDraw() method of the view I drew the path to the android.graphics.Canvas. Whenever the user released a finger I drew the path to an offline canvas/android.graphics.Bitmap which also was drawn in the onDraw() method. Plain and simple.
How can that be done using libgdx?
I have tried using a com.badlogic.gdx.graphics.Pixmap that I can draw a line to whenever the user moves a finger. This works well except the fact that I'm unable to control the witdh of the line using Gdx.gl.glLineWidth(). I know I can draw a rectangle instead of a line to set the width, but Pixmap doesn't seem to have any means of rotating, so I don't see how this can be done.
I can use a com.badlogic.gdx.graphics.glutils.ShapeRenderer for drawing lines (or rectangles) in com.badlogic.gdx.Screen.render(). As far as I can see I then need to store every single touch point of the current touch, and then draw all lines on render. Whenever the user relases a finger I guess I can store the screen as-is with something like com.badlogic.gdx.utils.ScreenUtils.getFrameBufferPixmap(). Hopefully there is a easier way to achieve what I want.
I ended up drawing circles on a pixmap where the line should be:
One circle on touchDown
Several circles from last touch point to next touch point reported to touchDragged
I'm not very happy with this solution, but it kinda works.
Maybe you can calculate line dot coordinates manually and use triangles to draw them on pixmap? Like use 2 triangles to form (rotated) box?