Context: I tried to implement a flingable VelocityViewPager. The flinging motion works properly. I like that the page "snaps" to center after the flinging motion. Despite this, I've had a few issues with it so far. One issue is that the page doesn't snap to center when you drag it passed a certain amount. I've solved this issue using this code so this is just for context. Another issue is below...
Problem: After beginFakeDrag() -> FlingRunnable (flinging motion) -> endFakeDrag(), endFakeDrag()'s internal code "snaps" the page to center. When I try to fling again during the snap motion, it waits until after the animation completes--putting the flinging motion on queue.
How can I cancel the snap motion on touch down so that it doesn't delay the flinging motion?
Attempt 1: On touch down, I tried to beginFakeDrag() but it doesn't cancel the endFakeDrag() snap motion.
Attempt 2: Instead of calling endFakeDrag(), I tried to mimic the snap motion during fake drag so that I can implement the cancellation myself and only call endFakeDrag() when the page is already centered. I tried this via SnapRunnable using Scroller's startScroll().
This might be my best option, but I can't figure out how much distanceX to scroll to in order to center the page. I tried to look into the original ViewPager.class but the algorithms confused me and it seems to depend on more internal code that the VelocityViewPager.class can't access.
Related
I wrote a fade in fade out method for views. It works perfectly, but, as I understand, each view's animation is handled by a separate thread in the background, tackled by the android system.
That is a problem, because, I want to blink and the same pace.
Is it possible to do that? I tried to put my blinking method in a runnable and restart it every time a new View starts its animation, but it is not working because 1. you cannot simply restart a thread, 2. even if you can, the Animation will be handled by the system with different threads each running independently anyway.
How should I do this?
Let me narrate my goal again: I tap on a view, it starts blinking, fade in fade out style, using a method I wrote. Then I tap on another, both blinking at the same pace, with the first one perhaps noticeably changes its original blinking pace to be in sync with the 2nd one. Then I tap on another, another... no matter how many I enable blinking animation on, these views all fade in and fade out at the same pace.
Can you offer any advice? Either a specific one or a general one.
So I've recently been abusing Google for an answer, however just can't find one, and my head's starting to ache. I've recently released my second game on the Google Play Store, and only now have I been getting feedback that the people aren't too crazy about the button pressing mechanics (same mechanics as the first game). My game can be found here if you want to give it a go, unfortunately I don't have an HTML version hosted elsewhere.
Making the game, I used LibGDX, and for the UI, I've used Scene2D that comes with LibGDX. My game requires that you press the green "bug" button to get a point (the "bug" buttons cycle around at random), you are forced to play against a timer, so you would obviously want to go faster for a higher score (think Piano Tiles).
Now, to the problem at hand, one of the game modes in my new game is called "Zen", two buttons, one gives you 1 point, the other 2 points. The problem I'm experiencing is that if you hold both "bug" (bottom right and bottom left) buttons down, and release one of the buttons, the released one triggers a score increase, and the other button resets as if it was never pressed on in the first place (even if your finger is still on it). Here's the code for my Scene2D buttons (working off memory, don't have my code near me at the moment):
// All is initialized correctly, no crashes, here's the part about the listener.
leftBugButton.addListener(new ChangeListener()
{
#Override
public void changed(ChangeEvent event, Actor actor)
{
// Run code here when button has been released.
}
}
// And the right hand button's code. Initialization is perfect, no problems.
rightBugButton.addListener(new ChangeListener()
{
#Override
public void changed(ChangeEvent event, Actor actor)
{
// Run code here when button has been released.
}
}
Getting to my question, what I want to go for is that if a button press has been completed (pressing and then releasing), I don't want the other buttons to reset to an unpressed state.
Any tips, or perhaps a different Listener I should use, or even dumping Scene2D for these buttons (using sprites with InputListener for example)? Any help would be greatly appreciated.
Thanks in advance,
TV
Don't use ChangeListener for that, use a ClickListener (button.addClickListener(new ClickListener...)) and handle your process on touchUp event, ChangeListener gonna process if ANYTHING on the button change and it's not a good approach to handle a button release event.
Found my problem, I kept rebuilding the Stack after every button press, resulting in the odd behavior, opted instead for a .setStyle() on my buttons which is working a lot better.
I would like to know how can I create a mouse move after pressing a button?
I am a fish in coding starting with a simple project and would love to create a step by step clicking process where the mouse will be scrolling and pointing in a certain point, img, or maybe to a class of my project?
Currently, there is no way to force a mouse movement via Javascript mainly due to its security implications.
In your case, you can use focus to guide the user to the specific portion of the page that you want.
You cannot move the mouse in JavaScript for the moment. What you can do however is scrolling the page so that a elements goes under the mouse cursor.
My idea is to move the element you want with JavaScript under the mouse cursor. When the user clicks your button, you can, in the event handler capture the mouse coordinates and use those to place any element exactly under the mouse cursor.
The result of the mouse cursor is above this element can be achieved that way.
try to Create COM, then client will ask to accept some installation.
see here ; http://febru.soluvas.com/2015/02/javascript-move-mouse.html
I'm new to posting, but have been using the site for help for a while now. So thanks for that!
I'm working on a new app, got everything running well. It's a kids' soundboard. 2 pages of imagebuttons in a relative layout, with onclick listeners which triggers SoundPool.
My question is this:
in testing I've discovered if you're finger is anywhere on the screen where a button is not (say pressing on the background) and then you try to touch a button (multitouch) ... the button press doesn't register. Any way to fix this?
Thanks!
You have to cover additional event types for multi-touch, if you are not covering below Actions, you are not covering multi-touch
MotionEvent.ACTION_POINTER_DOWN: This event happens for any additional finger that
touches the screen after the first finger touches
MotionEvent.ACTION_POINTER_UP:This gets
fired when a finger is lifted up from the screen and more than one finger is touching
the screen.
The explanation is quite tedious. I suggest you to google multi-touch for android. One helpful link is: http://android-developers.blogspot.in/2010/06/making-sense-of-multitouch.html
I'm trying to reproduce a feature I've seen on several apps:
I have a GUI app with several JDialogs.
I'd like to easily organize them tightly on screen:
when I move one JDialog, and one of its borders gets "close" (within 5 pixels for example) to another JDialog, I'd like it to automatically snap and stick right along it.
any idea how to achieve that ?
Add a ComponentListener to the dialog and listen for the comopnentMoved() event.
You can use the Window.getWindows() method to get all the Windows. Then you loop through the Windows and get the bounds of each window. Whenever you are near a window you manually set the size of the window you are moving.
Of course you will also need to handle the situation when you want to move the window away from another window so maybe you need to start a Timer with every componentMoved event and only manually position the window after events have stopped being generated.