Android drag and drop issue with sending DragEvents - android

I integrated Drag And Drop Framework in my project. In the layout I have my own custom grid of cells that I want to be able to drag for swipe the order of them or to put 2 together in folder.
To achieve this what I did is to build custom RelativeLayout and to override the onDragEvent() callback.
Basically everything working fine, but I have issues when in the dragging process I put 2 cells into big folder .
This folder is in layout from the start of the process with GONE visibility ,and I change it visibility to VISIBLE with copy of those cells. The problem is that the RelativeLayout folder have issues with the stream of the Drag events. The stream is stop sometimes and continue just if I stop the movement for some time.
I think of moving all the dragging logic to the parent so just 1 view will get all the event but I really prefer to find solution and stay with my logic because it taking advantage the framework data about which View is currently below the Dragging view.

After a lot of tries and research I found out that the Drag And Drop Framework stops to send most of the DragEvents when the alpha prperty of the View is different from 1.

Related

Change parent of view in Kotlin/Android Studio?

I got an app that utilizes drag and drop, and I want to reset the position of ImageViews (and then also the parent of the dragged image I guess).
I can't find any good info, and Google is no help.

Android: How to Auto Scroll a GridView vertically on dragging an item to the edge

I am trying to implement drag and drop on a GridView in android (ICS), but when I drag the item to the edge of the screen, the GridView doesn't scroll. How can I implement this functionality?
First of all if you don't need to support android 2.x ( API <11 ) this Andorid Drag and Drop tutorial is what you are looking for. I've never tried that way cause i had to implement it on 2.x but i took a look at it seems pretty straight forward.
To implement the autoscroll i guess you could use ACTION_DRAG_EXITED or ACTION_DRAG_LOCATION on the grid view and fire the scroll manually when you see that the location is next to the view bounds.
If you instead have to implement it on 2.x then it's going to be much more hard, you basically need to implement all the DRAG events, or a subset of them, by yourself.
I did in once with a ListView and what you have to do is:
Override the gridView touchEvent.
Use the actions ACTION_MOVE, ACTION_DOWN, ACTION_UP to fire the Drag events
Enable the drawing cache on the GridView items( setDrawingCacheEnabled ) and use getDrawingCache() to copy the bitmap of the view on DRAG_START.
Than what you have to do is to use that bitmap drawn on top of the GridView at the position that the ACTION_MOVE event gives you.
it's not easy but if you take your time you can manage to get it.
what more, I haven't check today but maybe you can try to google a bit an see if someone took the time to implement it and release it Open Source.

Android move items with acceleration

I cant seem to find the answer to this, mainly because I don't know what it is called.
I am going to expand a few features in my app, currently users can touch and drag to move forward in a list of images. What I want is for the users to "swipe" there finger and then all of these images will move under acceleration and will slowly come to a stop.
Is this a gesture? If so is it the "Fling" gesture?
There are several ways to do so.
Use ListView
Use Gallery
Use ScrollView
Use HorizontalScrollView
Write your custom ViewGroup or View
For the last approach, you have to detect the Fling gesture as you said and handle all the scrolling animations involved.

Android widget slide animation

I need to create a custom toggle-silder widget, like in the iphone, things like on-off items etc...
For the task i chose to inherit from LinearLayout, define it as Vertical and grab some xml attributes like the drawables that will be using for the buttons (one for on, one for off) and i just place two Views with the drawables as their backgrounds.
Now the issues i'm facing are:
i can catch onKeyDown and
onTouchEvent to discover swipe and
right-left-fire events so i'll
switch states for the button, but i
do wonder if there is a swipe event
read in the android system onSwipe
or should i try messing with the
GestureDetector ?
i want the sliding to be animated, i have no idea how to do that, any ideas where to start looking ?
ok if we take a look on this page:
http://developer.android.com/guide/topics/graphics/view-animation.html
we can see that we have simple way to create the animation, once onClick or onTouchStart is discovered (if not already processing), start the animation preloaded from the xml and disable touch on the View until animation ends(you cann add animation listener to animation object).
you should make sure fillAfter is true so the values will stick after animation ends.
the only issue with it is that it doesn't allow dragging like in iphone, possible solution would be to allow dragging up to certain delta and if that delta is passed ignore any onTouchMove events, disable touch and start the animation.
ofcourse deltas and animations should be updated according to the state of the button.
i might post code soon.

ViewFlipper caching issue

The views are not cached in a ViewFlipper. Is there a way wherein we can get an image of the view and show it to user so that he sees the Ui as we see on Home scrren(when we swipe the previous view also moves along and when we lift our finger, only then the next view is shown completely.)
What I want to do is that when the user starts moving his finegr on screen, the view should also move along(create an image of view).
I am not getting to do this, as when we swipe the present view goes and next view comes, we do not get both visible when we r moving our finger on screen.
Please if anyone gets what I am trying to do, do help me.
Thanks,
Farha
It's tricky to get scroll and swipe tracking working on Android, while using ViewAnimator or its subclasses.
They allow you to set in and out animations and start them at a given moment, but they work with discrete, either-this-or-the-other-view animations. They are actually using FrameLayout and after in or out animation is executed, other views' visibility is set to View.GONE to hide them from showing up under/over your current View.
The Launcher and the Gallery application are actually doing the functionality you want, by using a different approach.
They track the user touch input (onTouchEvent()), on MotionEvent.ACTION_MOVE they perform animations manually and on MotionEvent.ACTION_UP snap to the appropriate view, just like in the iPhone.
Unfortunately, this approach is actually more complicated than it looks like.
With the manual handling, you have to ensure that you are taking care of everything related to the touch input. This includes a lot of flag-raising, value-checking, event-delegating, etc.
If you want to get better acquainted with this, take a look at these classes from Gallery3D or Launcher's source code.
One other way to get nice horizontal scrolling is to use HorizontalScrollView.
You have to figure out a way to recycle your views, like you would with a ListView and you have to add the snap-to-view logic, but if you have to take care of a small number of views it could be the easiest approach.
Hope that helps.

Categories

Resources