In my application, I save data in my sqlite db a variable number of notes composed of: (IDNote,title,body, date of creation, owner of note, icon_name). When i save and query the DB, my data are all ok, so my question is, Is possible to implement GestureDetection for moving and restore a single icon that correspond at a single note ? Because a found an example but all the icons are moved, but i want to move only one icon at time simulating all the gesture of the icons of Desktop computer.
Thanks in advance.
Marco
Set an OnTouchListener on the view that holds your icon. This listener is called when an ACTION_DOWN event on the view is caught.
Here register it somewhere as the 'currently dragged object'. Make sure onTouch() returns false, so the event is propagated further to your views parent.
This parent is responsible for checking whether a view has been registered as the 'currently dragged object'. Also, it has to call your Gesturedetector, which in onScroll will do the actual scrolling and moving.
This is just an idea, tell how it went!
Related
I want to implement touch listener that detects
Click/tap on chess piece in order to select ot
Swipe/move of chess piece immediately.
How to do it?
Unfortunately, I am not sure what you mean by a "chess piece", but let's assume that the board is a view in the background, and inside you have inner views which are chess pieces.
To achieve the select/unselect given piece effect you should add a simple View.OnClickListener interface to your view. Each of your pieces should have a view class and some data connected to it (like a position, a type of piece, id, etc.). After clicking the piece update the state of some global variable, for example, selectedPiece with an ID assigned to a given piece. You should also change the UI of a given piece, for example change the border to show the selected piece to a user. Then after clicking a new field for moving the piece you should update the UI by moving your piece view to an appropriate position. Also, the data of a piece or a game should be updated - depending on the place of storing the pieces' positions.
For this you should implement the drag&drop feature which is described here: https://www.tutorialspoint.com/android/android_drag_and_drop.html. You should determine the places where the user can move a piece and in case of dropping the piece in the wrong place, cancel the move and go with the piece to a start position.
Basic response to touch events using event.x and event.y works:
https://developer.android.com/develop/ui/views/graphics/opengl/touch
https://suragch.medium.com/how-touch-events-are-delivered-in-android-eee3b607b038
...more info:
Android Touch Listener
Let's say
-I have a button that listens to a "tap" event, and directs to a function that does something.
-I put an ImageRact that covers the button. One layer up.
When I click on the cover image just above the area the buttons lies behind , the event function STILL executes.
How do I avoid this?
example:
local function hidebg()
display.remove(logo3)
logo3=nil
end
local logo2= display.newImage("logo.png")
logo2.x=display.contentCenterX
logo2.y=280
logo2.width=200
logo2.height=74
logo2:addEventListener("tap", hidebg)
local cover =display.newImageRect("NEW GAME A.png", 480,320)
cover.x=display.contentCenterX/2
cover.y=display.contentCenterY/2
The hidebg() function is still executed although the "logo2" is covered by "cover" image.
I know I could make the button isVisible=false and solve the problem, but I have dozens of buttons in different groups in different layers, and I wonder how to do it in a smart way. Maybe somehow disable a whole group? I don't know.
There are 2 ways that you can disable that button in your project.
1) Just create a listener to cover as below and return true as follows:
function coverPressed()
return true;
end
cover:addEventListener("tap",coverPressed)
2) Check if cover exists, and then remove the listener of logo2 as:
logo2:removeEventListener("tap", hidebg)
Keep Coding............ 😃
Control Touch Propagation
The reason that this problem can be solved by adding a touch event listener that returns true to the masking DisplayObject, as suggested in the accepted answer, is that this handles or halts the propagation of the touch. Having been handled by the masking object, the touch will never reach the listener on the button located further down in the display hierarchy (or further back, if you prefer).
This is explained in the Corona SDK documentation on tap/touch propagation:
When the user touches the screen, the event is dispatched to the display hierarchy. Only those display objects that intersect the touch location on the screen will receive the event.
Tap and touch events propagate through these objects in a particular order. By default, the first object to receive the event is the front-most display object in the display hierarchy that intersects the touch location. The next object to receive the event is the next object back in the hierarchy that intersects the touch location, and so on.
Tap and touch events propagate until they are "handled." This means that if you have multiple objects overlaying each other in the display hierarchy, and a tap or touch event listener has been applied to each, the event will propagate through all of these objects. However, you can stop propagation to the next underlying object by telling Corona that the event has been handled. This is as simple as returning true [emphasis mine] from the event listener — this stops the propagation cycle and prevents any underlying objects from responding to the hit event.
Change Widget Properties
If your button is from the widget.* library, you can achieve the same result more simply by disabling it and making it invisible:
button:setEnabled( false )
button.isVisible = false
By the way, the advantage of using isVisible (rather than changing alpha) is that you don't need to keep track of the alpha value before hiding the button. If you later do button.isVisible = true, the ButtonWidget will have the same alpha value as before.
I search for a good and handy user interface to put items from list 1
to a empty list 2 with drag&drop. I need this function for Android 2.2.
Have anybody heard about this feature?
EDIT
I found this website and i think it is also interesting.
http://techdroid.kbeanie.com/2010/04/simple-drag-n-drop-on-android.html
Look also at the comments.
It may also be helpful to reference my simple Drag and Drop list. You can find here
if u don't getting then use this
An example of this in github https://github.com/mtparet/Drag-And-Drop-Android
It could help you.All contribution are welcome
Take a look at this sample that Drag and drop inside a List View..
Refer to the drag and drop API launched in API Version 11
http://developer.android.com/guide/topics/ui/drag-drop.html
A drag and drop operation starts when the user makes some gesture that you recognize as a signal to start dragging data. In response, your application tells the system that the drag is starting. The system calls back to your application to get a representation of the data being dragged. As the user's finger moves this representation (a "drag shadow") over the current layout, the system sends drag events to the drag event listener objects and drag event callback methods associated with the View objects in the layout. Once the user releases the drag shadow, the system ends the drag operation.
I am designing an application which requires Drag&Drop functionality to transfer items from one list to another.
Is there any way to drop item into another list, as i have seen applications to drag and drop items in the same list(Reordering the list)?
This is more of a direction to investigate than an answer: Have you tried listening to the button/touch down event in one list to get the item the use wants to drag, and then listening to the button/touch up event in the other list so that you know what index to insert the item at?
In the button/touch down event handler, the View object being touched is passed in. In order to recover the original object that you used to create the View, you can attach it to that view via the setTag() function and recover it from the getTag() function within the event handler.
This wouldn't take care of any animation, but might achieve the desired functionality.
In one of my Activities I have a ListView that displays a list of locations. For each list item I want a little arrow icon that points in the direction of the corresponding location. I implemented this icon by extending ImageView. This custom View has a listener that reacts to changes of the device's orientation by rotating the icon image accordingly. I register the listener in the onAttachedToWindow() method and unregister it in onDetachedFromWindow(). This kind of works but the problem is that onDetachedFromWindow() sometimes gets called only a long time after the containing Activity has paused. Also, the whole layout overall seems a little hacky. So my question is: Is there a proper way to unregister the listeners or would you implement this in a completely different way to begin with?
I think you're having difficulty because your design is hacky like you acknowledge. I think what you should probably do is have your Activity listen for the device orientation and use onPause/onResume to handle the registering for orientation changes. Then have a custom cursor that is updated by the Activity when it changes. The custom cursor then can call notifyDataSetChanged to tell the ListView to update. Then in the getView call you can pass in the data necessary for your arrow to display correctly. This way the only arrows that will be updated are those that are visible. You'll only have one place where you are receiving orientation data and later you can handle the onScrollStateChanged and stop updating the arrows when the user is scrolling if it impacts the scroll animations too much.