Android Question AHViewPager touch event conflict

max123

Well-Known Member
Licensed User
Longtime User
Hi all,

as I wrote here on explanation of this library I released .....
https://www.b4x.com/android/forum/t...er-that-can-do-slider-or-progress-bar.141213/
..... I'm happy with it, the only issue I've found is using it on top of AHViewPager, for vertical sliders no problems, but for horizontal sliders the touch conflicts with ViewPager and I don't know how to solve it.

It only works if after touching the slider I move the finger outside it (slide vertically).

Because I had the same problem with others similar my controls libraries, now I think it's time to investigate it.

This happen not only on my control libraries, I had the same issue on a WebView placed on the ViewPager where I need to use a finger to rotate a 3D scene created with threejs library, to grant touch control I need to swipe the view vertically, then it works, swiping horizzontally it fails and ViewPager use the touch event to swipe the page.

On opposed in my current project I use some my custom buttons, when I want to swipe to change the page, these buttons sometimes was clicked randomly and this is not good.

Attached a small video (and zip project) that reproduce this issue on class I already released, the project depends on CustomMinimalSlider library you can find in the link posted, here I posted the .jar, .xml files, but even 2 demo projects, in the first one there is a full class inline that can be recompiled as library.

Please, can someone help me to know how to solve this issue ?

Many thanks
 

Attachments

  • AHViewPager_Issue.gif
    AHViewPager_Issue.gif
    417 KB · Views: 226
  • CustomMinimalSlider_AHViewPager_Issue.zip
    8.8 KB · Views: 211
Last edited:

teddybear

Well-Known Member
Licensed User
Hi all,

as I wrote here on explanation of this library I released .....
https://www.b4x.com/android/forum/t...er-that-can-do-slider-or-progress-bar.141213/
..... I'm happy with it, the only issue I've found is using it on top of AHViewPager, for vertical sliders no problems, but for horizontal sliders the touch conflicts with ViewPager and I don't know how to solve it.

It only works if after touching the slider I move the finger outside it (slide vertically).

Because I had the same problem with others similar my controls libraries, now I think it's time to investigate it.

This happen not only on my control libraries, I had the same issue on a WebView placed on the ViewPager where I need to use a finger to rotate a 3D scene created with threejs library, to grant touch control I need to swipe the view vertically, then it works, swiping horizzontally it fails and ViewPager use the touch event to swipe the page.

On opposed in my current project I use some my custom buttons, when I want to swipe to change the page, these buttons sometimes was clicked randomly and this is not good.

Attached a small video (and zip project) that reproduce this issue on class I already released, the project depends on CustomMinimalSlider library you can find in the link posted, here I posted the .jar, .xml files, but even 2 demo projects, in the first one there is a full class inline that can be recompiled as library.

Please, can someone help me to know how to solve this issue ?

Many thanks
Disable paging when sliding ADC2.
B4X:
Sub CustomMinimalSlider2_Moved(Index As Int, Value As Int)
    Pager.PagingEnabled=False
    CMS2.UseOnlyTouchUP(True)
End Sub

Sub CustomMinimalSlider2_Released(Index As Int, Value As Int)
    Pager.PagingEnabled=True
    CMS2.UseOnlyTouchUP(False)
End Sub
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Thanks, I will try this solution.
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Hi @teddybear , thank you, your solution worked, today I modified the CustomMinimalSlider class, now it support by default both _Move and _Release events and both can be disabled separately this way:
B4X:
CMS1.FireTouchEventMove(False)
CMS1.FireTouchEventRelease(False)
or just comment the event callback sub.

Now the touch do not conflicts, sometime it fails if slider moved fast because the _Release event have a strange latency, maybe because I still use B4ABridge. I will try directly from USB.
I've added as your suggestion lines to Enable/Disable pager change, but now I've a very strange problem, when I move the slider to a min or max value, the _Release event fires, here I've put:
B4X:
Pager.PagingEnabled=True
but very strangely it do not reenable, so not possible to change pages.
To make it to work I need to set a value between min and max, eg, between 0 and 100 (default).
This very strange, I even put a Log, the event is fired, but Pagination remain disabled. The same issue if I put the slider to min or max value, all values in the middle correctly reenable it.

Have you an idea of what happen?

When I return to pc I will post the full zip project.
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
Here as promised the full zip project to reproduce the issue.

The CustomMinimalSlider class is inline, just need a reference of AnimationPlus library because depends on it for animations.

The issue is only on horizontal slider, now it do not conflicts, but paging is not reenabled when the slider is moved to zero or max value, the flag is true but really it is blocked and do not permits to change page.

Probably this is something that happen when I release the slider out of its bounds because if I click labels to set zero value or max value it is working.

Please, can you help me to fix it ?
 

Attachments

  • CustomMinimalSlider.zip
    18 KB · Views: 187
Last edited:
Upvote 0

teddybear

Well-Known Member
Licensed User
Here as promised the full zip project to reproduce the issue.

The CustomMinimalSlider class is inline, just need a reference of AnimationPlus library because depends on it for animations.

The issue is only on horizontal slider, now it do not conflicts, but paging is not reenabled when the slider is moved to zero or max value, the flag is true but really it is blocked and do not permits to change page.

Probably this is something that happen when I release the slider out of its bounds because if I click labels to set zero value or max value it is working.

Please, can you help me to fix it ?
Just add sleep(0) it will work well.

B4X:
Sub CustomMinimalSlider2_Released(Index As Int, Value As Int)
    sleep(0)
    Pager.PagingEnabled=True
End Sub
 
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
OOOOOK Thanks ... it worked ... you saved my life 2 times last day :D

What's your name? Angel ?

Note that yesterday I've tried to add DoEvents and it do not worked, but I've put it after enable the paging.

Now I want put another Initialize sub where I can pass an istance of Pager, so the library should do the work on horizontal slider internally without need the user have to add a Sleep(0) and disable/enable it on any callback sub, so trasparently, the user do not need to add anything like vertical slider.
I work on it.

Thanks so much
 
Last edited:
Upvote 0

max123

Well-Known Member
Licensed User
Longtime User
I'm happy to inform you that now the library can be used even on top of AHViewPager, no need to do anything, the library treat it internally by disabling/enabling the paging, this can be set on all sliders this way but only Paging is disabled internally on horizontal sliders:
B4X:
CMS1.UseViewPager(Pager) ' Pass the initialized AHViewPager to the library, it internally disable/enable paging to prevent touch conflicts

Now I disable paging not only on Touch_Move event, but even on Touch_Down event, and seem to work better, just need to wait some milliseconds after Page is changed, I think this depends on ViewPager internal animation that need to finish or have a timer, maybe it can be changed using JavaObject or Reflection.

Now I go to update the library on the forum.

Thanks for your help
 
Last edited:
Upvote 0
Top