AS3: Swipe function acting up - android

So I have made a swipe function that allows the user to swipe menus from the top of the screen and the side of the screen (Note: There are arrows that are peaking in from the sides of the screen that the user is garbing to swipe the menu in). Now it all works great, but for one thing... The menu's will only work with the .stage in there event listeners. This wouldn't be a problem but I have screens that also are using a swipe function to change what is on the screen. But the odd thing is that the screens using the swipe function do not need the .stage in there event listener. Below I will post the event listeners, I've been stuck on this for a few days just does not add up to me on why it's doing this.
//Side Menu Swipe
smenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, onSwipe);
//Top Menu Swipe
tmenu_mc.stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, downSwipe);
//Screens Swipe
Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe);

What you can do, is on swipes that will be occurring on-top of a display object (like presumable your Games object), you can listen with a higher priority and cancel the event.
Games.addEventListener(TransformGestureEvent.GESTURE_SWIPE, lrSwipe, false, 999); //the fourth parameter is the priority of the listener, when there are multiple event listeners for the same event, the listener with the higher number priority will be run first
function lrSwipe(e:TransformGestureEvent):void {
e.stopImmediatePropagation(); //this make the event stop and not trigger other listeners after this one
//...rest of your code
}
Again (as demonstrated in my answer to your other question), you're not going to want multiple listeners for a stage swipe event. With the code you've posted, when the user swipes over top of the Games screen, all three of your functions (lrSwipe, then downSwipe then onSwipe) will get called at the same time.

Related

How to detect screen tap on non-clickable and swipe-able area alone in Android?

My use case is, that I need to hide the toolbar and bottom navigation view after a delay and reveal it once the user taps anywhere on the screen.
But I shouldn't reveal those when the user touches the screen to click on a View/Compose or when the user performs a swipe/scroll gesture.
I achieved this partially using GestureDetectorCompat.onSingleTapConfirmed. The gesture detector doesn't call this method for swipe gestures, but it calls this for click events for clickable views/compose inside the screen.
So when I click an actionable icon in the screen, that click action is executed and the toolbar and bottom bars are revealed. I need to ignore the tap events when the tap occurs on a clickable view/compose.
I mention as view/compose because, my project has both XML-based views and Compose views, so the solution should work for both click events.
Any help is much appreciated, thanks.

How can I trigger a swipe event in Android

I want to simulate a swipe event in Android app.this link is for touch event
Basically I want to slide to the next view when a user swipe on the screen or when he click a button, and the first one is trivial. The second one is complecated that I have to simulate or trigger a swipe event in the OnClickListener of the Button. How can I do that?
If you already use ViewPager
viewpager.setCurrentItem(i)
where i is a numer of page you want slide into

Android Event Propagation in Multi Layer Activity

I tried to add swipe event for the screen which has got bunch of buttons. the swipe is not working for buttons. In other words, if i swipe on top of buttons, swipe event is not recognized. So, I tried 2 (top and bottom) layers of layout in Activity. Top for handling swipe and bottom for buttons and other UI elements. But, the top layer is taking all the event and Bottom is not accessible. Is there any ways to that i can send the click event to bottom layer.
The main requirement is, handling swipe and click in a screen with bunch of button. Swipe is not recognized by buttons.
How to solve this problem.
Your onTouchEvent() for the top layer must return false if it wants anything underneath to see the touch event. It should return true only if it has handled the event and it does not need to be propagated any further.

blinking in custom drag/tap implementation

I have implemented custom view with some children. The view can be scrolled using standard drag gesture. Also every child can be clicked. The problem is, that when I start dragging the view, one of children gets 'down' event and it changes its state to 'pressed' for a second. I would prefer standard listview behavior - the child goes into pressed state when the user keeps pressing this child with his/her finger for like 50ms. It would reduce blinking caused by misread press event.
I know, that I need at least 2 events to detect if the user is tapping or dragging the view. For now I'm using TimerTask to shedule 'down' event. When I get 'move' event before my 'down' event is executed, I know that the user is dragging and I can cancel the sheduled event.
I know it's quite hacky. I also tried gesturedetector to detect drag and tap events, but it needs some additional work to properly implement changing view state from pressed to default when the user moves finger and starts to drag the view.
My question is - how this is implemented in android listview? I tried to copy their solution from listview implementation, but it's so huge I can't handle it. Simply I don't see the code responsible for handling such situation.
I managed to understand a gesture detection logic in ListView and, in general, in android views. I wrote my own gesture detector, which is somewhat better than the original one. It reports more gestures (multiple taps, dragging) and has some configurables (timeouts, move epsilon). You can find it open-sourced here: Better Gesture Detector on code.google
The library uses Handler class and postDelayed()/removeCallbacks() method combination to detect, handle and cancel motion events and gestures. It's quite simple and one should be able to get the idea by just reading the code.
This repository also contains a simple demo. Please note that this code is provided 'as is', contains some useless comments, logs and should be cleaned up a bit.

Gesture problems with a ViewFlipper that contains a ListView

I have a ViewFlipper where one of the views is a ListView. To move back and forth between the views, I have a GestureListener that detects left and right swipes. Sometimes the left & right swipes interfere with the ListView. That is, when I want to switch to the next view by swiping left/right, I may accidentally click on an item in my list.
Is there a good way to prevent this interference?
Have a look at http://android-journey.blogspot.com/2010/01/android-gestures.html.
The SimpleGestureListener from this page is a great solution to gesture detection. When run in dynamic mode (the default), it intercepts touch events that are determined to be gestures to prevent them from performing other actions. Other touch events are not interfered with.
If you are only interested in swipe gestures I recommend disabling the code for detecting tapping and only listening for swipes.
If you want something a little snazzier than a ViewFlipper (something more like the Android home screen) try out this new addition to the Android compatibility libs: http://android-developers.blogspot.com/2011/08/horizontal-view-swiping-with-viewpager.html?m=1

Categories

Resources