Android Event Propagation in Multi Layer Activity - android

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.

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.

Controls and parent touch in THorzScrollBox

I have a THorzScrollBox with 3 TLayout controls inside it.
I put some code to make HorzScrollBox1.AniCalculations.SetTargets go to the layout I want based on my scroll and it was a success running.
But when I put TListView inside the TLayout, I can't scroll it, because the HitTest of the TListView is enabled. I must disable it to scroll the THorzScrollBox, but if I do then the TListView can't scroll vertically.
If you look the alFmxControl.apk demo of alcinoe (https://github.com/Zeus64/alcinoe) you will see that it's handle something similar, but instead of TlistView it's a Tabcontrol and vertScrollBox.
To resume the idea both TabControl and the VertScrollBox receive the mousemove event and as soon as you move you finger more on the left or right then the vertscrollbox is deactivated and only the tabcontrol receive futur mouse event, or as soon as you move your finger more on the up or down then it's the opposite, tabcontrol is deactivated and only the scrollbox receive the mouse event.
Mouse event are handled via CMGesture that as i remember don't care if a child controls catch the mouse event via it's hittest property
You can inspire from this code to see how to transpose it to your TListView

Swiping to make ImageButton disappear / appear

I've a menu in Android app with several ImageButton (all grouped in a RelativeLayout) and I would like to make it disappear when swiping with finger towards the outside of the screen.
Swiping with finger towards the inside of the screen, instead, the menu should re-appear.
Any suggestion to do this ?
Try writing a gesture detection as given here Fling gesture detection on grid layout and in that code instead of toast write your code.

AS3: Swipe function acting up

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.

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