Android - Increase Area of Drop Zone - android

I am following http://developer.android.com/guide/topics/ui/drag-drop.html and what I currently struggling with is, that I want to drag a relatively big view on a smaller button.
It seems ACTION_DRAG_ENTERED is only fired, if the touchpoint (center of the drag shadow) is within the bounds of the target view. However, I would like it to accept drops when the bounds of the shadow and the dropzone overlap. Is this possible?
(Note: I know, I could define a separate view as the drop zone and make it bigger than the actual drop-zone button, but that really complicates my layout, and I would rather work with the current view).

Related

Overlapping views and drag events

I have two overlapping views which both consume the same drag event. Think a small circle under a much larger one. When the touch location cross over the smaller circle which is under (in zdepth) the larger one it triggers a ACTION_DRAG_EXITED event, even though the view's bounds have not been exited. The event is effectively hopping from the higher view to the lower view.
How can I prevent the lower view from triggering events when occluded?
thanks!
Nigel
In case anyone else encounters this, to fix it I used view.bringToFront() to ensure the larger circle view was on top. Interestingly even though it was drawing on top and its elevation was higher, android didn't consider it on top in the context of the drag event.

How to draw outside view bounds?

How can I draw (bitmap, line, etc) outside the bounds of a view? From the view's onDraw(), I've read this is not possible as everything drawn will get clipped to the view's bounds.
I did come up with one solution but I'm hoping there's a better one. What does work is to create a transparent view that is at the top of the z order and includes the area I want to draw in (the entire app client area). Then, whenever I want to draw outside some child view, I can simply translate to the coordinates to the transparent view and draw there.
I also read about SurfaceView hoping that would do what I want. But I think it's main purpose is to provide drawing in a separate thread and doesn't solve the problem I'm discussing.
To be clear, it isn't sufficient to simply draw in the parent of the target view because other views in the parent will be higher in the z order and hide the drawing.
Intuition tells me there's a "right way" to do this. Anyone know?
I'm drawing the conclusion that the right way is to do what I proposed - create a transparent view that is at the top of the z-order for the space you need to draw in.
I come to this conclusion after learning how the Navigation Drawer drawing works - exactly in this way. So, if Google uses this technique, I conclude that it's the best way available.

setClipChildren and hardware layers

I have a custom view group that I'm animating around on a screen based on touch events (drag and drop, for instance).
I want it to be able to draw slightly outside its bounds, and still animate smoothly.
I tried setting setLayerType(LAYER_TYPE_HARDWARE, null) on the dragging view, and performance was great, but anything outside the bounds was clipped.
I tried setting LAYER_TYPE_NONE, performance was still fine, but there was animation ghosting/streaking where the view had been dragged (as if it were smearing the screen).
Tried this on a Moto X and Nexus 4, same results.
What's the best way to approach this? Is setClipChildren(false) supposed to work with LAYER_TYPE_HARDWARE? Interestingly, LAYER_TYPE_SOFTWARE exhibits the same unexpected clipping as does LAYER_TYPE_HARDWARE.
Try to use following combination:
setClipChildren(false);
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
android:hardwareAccelerated="false"
As described here: ViewPager and setClipChildren(false) workaround for 2.x devices
I had a similar problem when doing exactly the same thing. I wanted a drop shadow beneath my views. The problem is that the system will only clean up the rectangle left by the view you have moved and since you are rendering outside that view by choosing to not clip children, the rectangle is not covering all of your tracks and remains of the rendered view leave a smudgy sort of mess behind.
The solution I used was to put the view I wanted to move inside another view (A RelativeLayout with the child view aligned to the parent's center) that is slightly larger and does cover the drop shadow or whatever else you are rendering outside the bounds of your child. You can set the background of that parent view to transparent/clear. Now attach the drag action to your parent view and the Rect that is cleaned up behind it will also clean up the child's mess.
The only other way I found to do it which was very costly in terms of performance was to re-render the views that show the mess at each frame. I couldn't find any other solutions.

Implementing wheel shaped interface navigation tool

I am interested in implementing a user interface navigation control mechanism based on a wheel shaped device (or pie chart shaped or circle shaped) in my Android app.
I would like only half of the wheel to be visible at any time. That is, only the top half of the wheel should be visible since the bottom half should be below the border of the screen. The user can then turn the 'half wheel' to show options hidden by the screen border. The visible top half should then be divided into three parts like a pie chart, so the user can press either one of them to invoke some action. The following pic should explain (it is an example with seven (A-G) options).
http://imgur.com/lNu1F
The rotation itself should not be hard, but I am having a hard time understanding how to position the wheel so that half of it is outside the actual screen. I am thinking that loading the entire wheel (but hiding half of it) is best, since that is that graphics I have and it will also allow a smooth animation when the user swipes to show some other options. How can I make Android show the wheel in this way?
Also. Any comment on how to implement the 'swipe along the wheel shape' would be appreciated.
Thank you.
So for the wheel - you are hving trouble knowing how to position the wheel because you are using XML to align you objects and would like to use something like "Align Object Center To Bottom" which does not exist.
Here is one approach that might work fine: Mask the wheel view.
Is it possible to mask a View in android?
As for swipe the wheel along, I would register the wheel to take touche events, and use only the horizontal componenet of move events to apply to the rotation of the wheel. This setup is common in audio software that uses knobs.
However if you want to have it stick to the users finger in a more realistic fashion, you will need to do the following:
When the user first touches the wheel, calculate the angle from the wheel center to the finger.
Every time the finger moves, check the angle from the wheel center to the finger - and rotate the wheel the amount that the angle has changed from the last touch event.
The formula for getting the angle between two points is this:
Float angleInRadians = Math.atan2(point1.y-point2.y, point1.x-point2.x);

Android: How to make position of View match the visual representation after animation

I am currently trying to animate a card game using an AnimationSet of Translate and Rotate animations. Although I am using setFillAfter(true) and see the card visibly move and stay in it's new position, the actual position of the ImageView is still at it's old location.
In the Google documentation it says:
Note: Regardless of how your animation may move or resize, the bounds of the View that holds your animation will not automatically adjust to accommodate it. Even so, the animation will still be drawn beyond the bounds of its View and will not be clipped. However, clipping will occur if the animation exceeds the bounds of the parent View.
This means that all of my old onClickListeners, etc are still being associated with the old position rather than the newly updated visual representation, and any new animation applied to the View occur from the initial spot, not the newly located one.
What is the best way to get the effect that I seek (a card sliding from my hand to the center of the screen, which is a different LinearLayout, and then in a later sequence sliding from that spot off the screen)?
I know what I seek is possible as the people at bytesequencing.com have accomplished this smooth animation effect in their android game "Hearts! (free)" which I discovered in the market.
Thanks!

Categories

Resources