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.

Your support:
Creating libraries and wrappers for existing library projects is a lot of work. The use of this library is totally free and you even don't need to mention in your app that you use it.
But if you use this library in your projects and you think it is useful to you please consider to make a donation:

Thanks very much for your support.

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
    screenshot-1336034831196.png
    10.1 KB · Views: 8,073
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,326
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,332
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,237
Last edited:

wimpie3

Well-Known Member
Licensed User
Longtime User
Pager_PageChanged fires already before the animation is finished... if you add and remove pages here, the animation is interrupted.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
That's not the best solution either. It takes a second or two before the animation is completely finished so you end up with stutter. Plus if you swipe really fast, the animation state does not go idle.
 

Esteve

Member
Licensed User
Hi, I'm using the example FixedTabsIconText, I can not put a transparent panel in front of the tabs to disable,
Activity.AddView(PanelProteccion,0,0,100%x,100%y)
This is always below the DSTabLayout.
is this possible?
If not possible, what would be the correct way to disable the movement of panels?

Thanks
 

techknight

Well-Known Member
Licensed User
Longtime User
AHViewPager is broken on Android Wear if I use anything newer than API level 4. Just so your aware!
 

corwin42

Expert
Licensed User
Longtime User
What is the difference between .Enabled and .PagingEnabled ?

with .Enabled the view itself gets enabled and disabled. With .PagingEnabled you can disable the touch scrolling.

AHViewPager is broken on Android Wear if I use anything newer than API level 4. Just so your aware!

Explain "broken"
 

techknight

Well-Known Member
Licensed User
Longtime User
Wont slide back right again after sliding left, Android wear assumes this means exit app, so it kills the app.

Using API 4 works. Anything above that, nope.
 

corwin42

Expert
Licensed User
Longtime User
Updated the library to V3.00 in the first post.

Adds support for Designer custom properties and uses the maven repository for the support library (B4A 6.0 or above required).
 
Last edited:

Mashiane

Expert
Licensed User
Longtime User
Hi there

For each of my pages I am loading a layout that has a panel with controls inside that I have anchored in case the screen size changes. I want the views inside the panel to resize themselves to fit into the panel irrespective of the screen size. I however want the panel to resize itself to fit the page area.

How do I ensure that the panel in the layout sized itself to the AHPageContainer on all sized?

B4X:
' load my view
Activity.LoadLayout("viewdays")
    container.Initialize
    pager.Initialize(container, "Pager")
    'Now we can add the pager to the activity, the pager will resize itself irrespective of screen size.
    Activity.AddView(pager, pnlLeft.width, pnlHeader.height, 100%x - pnlLeft.Width, 100%y - pnlHeader.height)

Then each page is added like this.

B4X:
Dim pg As Panel
            pg = CreatePanel(userup)
            container.AddPage(pg,user_id)

where my CreatePanel method is like...

B4X:
Sub CreatePanel(xupload As String) As Panel
    Dim pan As Panel
    pan.Initialize("")
    pan.LoadLayout("tur")
    ' the parent panel inside the layout
    pnlTUR.Left = 0dip
    pnlTUR.Top = 0dip
    pnlTUR.Width = 100%x
    pnlTUR.Height = 100%y

Is it sensible to resize the parent panel like this i.e. pnlTUR?
 

wimpie3

Well-Known Member
Licensed User
Longtime User
Any idea on how we can use this lib for vertical scrolling? This page offers some suggestions that might be easy to integrate.
 

wimpie3

Well-Known Member
Licensed User
Longtime User
I'm using version 3.0 and once in a while I get the following messages in the logs:
B4X:
Unexpected event (missing RaiseSynchronousEvents): mypager_pagescrolled
 

corwin42

Expert
Licensed User
Longtime User
I'm using version 3.0 and once in a while I get the following messages in the logs:
B4X:
Unexpected event (missing RaiseSynchronousEvents): mypager_pagescrolled

With my understanding this is not a problem and the messages won't harm. AHViewpager raises synchronous events, when the pages are changed with the finger. There is an annotation @RaisesSynchronousEvents which a developer can add to a library method when it generates synchronous events. Problem here is that there is not really a method which generates this events but it is the touching of the view which is completely handled internally by the support libraries viewpager class.

So I have no idea how these messages can be avoided. Maybe Erel can comment on this?
 

corwin42

Expert
Licensed User
Longtime User
How do I ensure that the panel in the layout sized itself to the AHPageContainer on all sized?

If a page is added to the PageContainer, it is not directly added to the ViewPager and so at this time there is no layout.

The panel is added to its parent view just before ViewPager_PageCreated event is called. It is sized exactly the same size as the ViewPager at this time. So the best time to load a layout to a Container-Page is in the PageCreated event sub.
If you do this you should remove all views from the Container panel on PageDestroyed event.

That is the cleanest way.

If you don't want to destroy and recreate the contents of the panel every time you may store the status in a global array so that you only load the layout in PageCreated when it was not loaded before.
 

BarryW

Active Member
Licensed User
Longtime User
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.

How to trigger an event when tab has been clicked or long clicked... Tnx
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Hello All,

I was wondering if there's a way to hide the viewpager? So what I want to do is to have the pages on the tabs (using DSTabLayout) contain a listview (ULV) and when a user scrolls the list, hide the view pager or the tabs or even the toolbar so that the list takes up most of the space.

Will appreciate any tips in implementing this.
 

corwin42

Expert
Licensed User
Longtime User
Hello All,

I was wondering if there's a way to hide the viewpager? So what I want to do is to have the pages on the tabs (using DSTabLayout) contain a listview (ULV) and when a user scrolls the list, hide the view pager or the tabs or even the toolbar so that the list takes up most of the space.

Will appreciate any tips in implementing this.

I'm currently working on a new feature of the DesignSupport library which will support the CoordinatorLayout and CollapsingToolbarLayout. With this new feature all your mentioned effects will be possible.
 
Top