B4A Library AHViewPager library - Sliding panels now perfect

This library is a B4A implementation of the ViewPager object provided by the compatibility class from google. With this library it is possible to add sliding panels to your apps.

AHPageContainer - This object is a container for the pages of the AHViewPager. You should add Panels to this object.

AHViewPager - This is the main object which provides the sliding panels.

All the Tabs objects are deprecated now. You can use them but I don't enhance them anymore. For nice looking Tabs please use the DSTabLayout object of the DesignSupport library.
Alternatively you can use the TabStripViewPager.


Installation:
  • From V3.00 on the library requires B4A 6.0 or later.
  • This library depends on the Android Support library so you need to install the Android Support repository in the Extras section with SDK Manager.
  • Copy the AHViewPager.xml and AHViewPager.jar files to your additional libraries folder.
Example project:

For an example project for this library see the Design Support Library.


Version History:

1.00:
- initial version

1.01:
- Added AHViewPagerFixedTabs object for a fixed tab indicator
- Fixed a bug that it was impossible to get the canvas of a panel which was added to the container (It was impossible to display charts on a page)
- Example for AHViewPagerFixedTabs tab indicator

1.02: (Never released)
- Fixes problem with tab height (Line is now always on the bottom)

1.03:
- Fixes problem with Line sometimes not updating correctly on Android 4.0+
- Fix UppercaseTitle property

2.0:
- Complete Rewrite of the Swipey tabs code to fix some bugs with newer android versions.

2.01:
- New property for the AHViewPager object: PagingEnabled - Enables or disables paging for the ViewPager.

2.02:
- New events PageScrolled and PageScrollStateChanged (with SCROLLSTATE constants)
See post 227 for details

2.20:
- Use raiseEventfromUI() in most events
- New SupportTabs object
- New SupportTitles object
- Support for Designer (as a Custom View)
- some minor internal changes and bug fixes

2.21:
- Use raiseEvent() for PageCreated and PageDestroyed event again to prevent double UI refreshes
- Added @RaiseSynchronousEvents annotation to GotoPage() (to make it better compatible with rapid debugger.

3.00:
- Support for Designer Custom Properties.
- Uses maven repository to access support library. (B4A 6.0 or later required)

Attention: V2.20 has an API change which makes the ViewPager incompatible with older versions. The AHPageContainer parameter is removed from the Initialize() method. Initialize2() has the old signature. If you use Initialize() (or add the View to the Designer as a custom view) then you have to set the container object with ViewPager.PageContainer = <YourContainer>

The examples use the old Initialize method, so they are broken. I was too lazy to fix them because I recommend the tab indicator from the Design Support library for a nice looking Material Design app.
 

Attachments

  • screenshot-1336034831196.png
    10.1 KB · Views: 8,298
  • screenshot-1336034966953.png
    9.9 KB · Views: 7,564
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,540
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,495
Last edited:

corwin42

Expert
Licensed User
Longtime User
As in most events you can access the triggering Object with the "Sender" object.

Alternatively you can store references to your objects in global variables.
 

sorex

Expert
Licensed User
Longtime User
@corwin42 ,

I want to display some tabular data. multiple ones that is.

Can I use that with the library knowing that it might need to scroll down to see all data?

Wouldn't the scroll events overrule the swiping/touch event on the panel since the scrollview is overlaying the panel?
 

corwin42

Expert
Licensed User
Longtime User
Scrolling vertically in a listview or scrollview should be no problem. You will only get problems when your views will use horizontal scrolling.
 

ferya

Member
Licensed User
Longtime User
I got this error with v2.2:
java.lang.NullPointerException
in this line: pager.Initialize("Pager")
pls help me.
 

corwin42

Expert
Licensed User
Longtime User
I got this error with v2.2:
java.lang.NullPointerException
in this line: pager.Initialize("Pager")
pls help me.
Sorry but how should we help you with this little information you gave us?
You should post at least the full stack trace and the relevant code or better a sample project which shows the problem.
 

woniol

Active Member
Licensed User
Longtime User
Hi Corwin42,
What's the:
recommend the tab indicator from the upcoming Design Support library for a nice looking Material Design app
mentioned in the first post?
Is this a new library your are going to release?
 

ferya

Member
Licensed User
Longtime User
Hi Corwi42,
Sorry about my littel info.
I try to run your example in the first post and my lib version is 2.20
I got this error that happend on

tabs.Initialize(pager)

main_activity_create (java line: 388)
java.lang.NoSuchMethodError: No virtual method addOnPageChangeListener(Landroid/support/v4/view/ViewPager$OnPageChangeListenerV in class Lde/amberhome/viewpager/internal/CustomViewPager; or its super classes (declaration of 'de.amberhome.viewpager.internal.CustomViewPager' appears in /data/app/de.amberhome.viewpagerexample-2/base.apk)
at de.amberhome.viewpager.AHViewPager.innerInitialize(AHViewPager.java:100)
at anywheresoftware.b4a.objects.ViewWrapper.Initialize(ViewWrapper.java:65)
at de.amberhome.viewpager.AHViewPager.Initialize(AHViewPager.java:89)
at de.amberhome.viewpagerexample.main._activity_create(main.java:388)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at de.amberhome.viewpagerexample.main.afterFirstLayout(main.java:100)
at de.amberhome.viewpagerexample.main.access$100(main.java:17)
at de.amberhome.viewpagerexample.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5972)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)

plese help me.

best regards
 

corwin42

Expert
Licensed User
Longtime User
A NoSuchMethodException is not a NullPointerException.

Your android-support-v4.jar is too old. Update it with SDK Manager, copy the new jar to your custom libs folder and do a right click->refresh on the libraries tab in the B4A IDE.
 

corwin42

Expert
Licensed User
Longtime User
Hi Corwin42,
What's the:
mentioned in the first post?
Is this a new library your are going to release?
Yes, it will support SnackBar and TabLayout from the Design Support Library in the first version.
 

ferya

Member
Licensed User
Longtime User
Hi,
I changed my android-support-v4.jar to the last version.
but I got bellow error on line tabs.Initialize(pager)

java.lang.IllegalStateException: The pager's adapter has to implement ViewPagerTabProvider.
at de.amberhome.viewpager.internal.ViewPagerTabs.setViewPager(ViewPagerTabs.java:157)
at de.amberhome.viewpager.AHViewPagerTabs.Initialize(AHViewPagerTabs.java:30)
at de.amberhome.viewpagerexample.main._activity_create(main.java:432)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at de.amberhome.viewpagerexample.main.afterFirstLayout(main.java:100)
at de.amberhome.viewpagerexample.main.access$100(main.java:17)
at de.amberhome.viewpagerexample.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:145)
at android.app.ActivityThread.main(ActivityThread.java:5972)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1399)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
 

Walter Brunmueller

Member
Licensed User
Longtime User
Hello corwin42!

Thank you for your Sliding Library.
With the new Version it seems, that the
create of the panels takes alonger time,
because the screen is black for a short time.

I use 3 sliding panels at the same time, because
I have 3 areas (top-, middle- and bottom-area)
for sliding.

In library version 2.02 there was no black screen.
This appears mostly when I use 'GotoPage' and
the destination page is not created.

best regards
 

Walter Brunmueller

Member
Licensed User
Longtime User
In the attachement I send you a Testapplication.
You have 3 sliding panels
If you slide on the top or middle panel andafterwards click on it,
so the day panel jumps directly to the day.

In Library 2.02 everything is ok
In Library 2.20 you get a black day panel for a short time


PS:
Is it posible to get an information, that the change-event comes from
a) sliding
b) GotoPage

So it is possible for me make selective GotoPage's
For example when I
slide the month-panel so I have to jump to the correct Day
slide the year panel I have to jump to the correct month and to the correct day

This I have to do from the changed-event
In this event I am also if I slide the day panel
And here the snake bytes into his tail - I hope you understand me.
 

Attachments

  • SlideTest.zip
    26.5 KB · Views: 337

corwin42

Expert
Licensed User
Longtime User

v2.21 should fix this.


You cannot see it from the PageChanged event.

But you can use PageScrollStateChanged event for this.
Set a global flag when state is changing to dragging and clear it for idle. In pagechanged event you can test this flag. State dragging will never be fired for GotoPage.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…