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:

NilsBe

Member
Licensed User
Longtime User
As describe here:

http://www.b4x.com/forum/additional...sliding-panels-now-perfect-14.html#post133866

I used your example and just changed one line. The behaviour is ok when the app is created on one system and weird (as shown in the screencast) when created on a seconds system.

I am trying now to find the differences between these two systems. First I thought it's the android version, then I thought it's the jdk version. Both assumptions were wrong. So I am trying to figure out what else could be different...
 

NilsBe

Member
Licensed User
Longtime User
Solved. Just pick the right version of android-support-v4.jar

I noticed that there were at least two different files with this name:

android-support-v4.jar

Below are filesizes and md5/sha1 of the two versions which I had on my systems.


ok:
android-support-v4.jar filesize: 242 KB (247.894 Bytes) md5: bcf017dfe2243c8d72b4b2aa40101040, sha1: 7329492e76650ee661f6af7704b0c79151d8e1ef

not ok:
android-support-v4.jar filesize: 341 KB (349.252 Bytes) md5: 7c357558b1ef5cd16f1d312fe87c38a0, sha1: 612846c9857077a039b533718f72db3bc041d389


I don't know anything about the file itself. I just followed the instructions how to copy them from the android sdk. Maybe somebody can clarify more about this.
 
Last edited:

Stulish

Active Member
Licensed User
Longtime User
Help :(

Is there a simple way to create the AHViewer

I have created 3 basic layouts, called pag1.bal, page2.bal and page3.bal, each one just holds an imageview with a picture at the moment.

What do i need to do ti just initialize so that when i RUN the program, i get page one displayed (with no tabs or anything), and i can just slide to page 2/3.

I looked at NJDudes post number #8 but i keep getting:

Error occured

An error has occured in sub:
main_activity_create (java line: 253)
java.lang.NullPointerException
Continue?

The Log contains:

** Activity (main) Create, isFirst = true **


main_activity_create (java line: 253)


java.lang.NullPointerException
at anywheresoftware.b4a.objects.PanelWrapper.LoadLayout(PanelWrapper.java:89)
at com.viewpager.com.main._activity_create(main.java:253)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
at com.viewpager.com.main.afterFirstLayout(main.java:84)
at com.viewpager.com.main.access$100(main.java:16)
at com.viewpager.com.main$WaitForLayout.run(main.java:72)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4517)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:760)
at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException

the original example at post #1 runs fine, so i am not sure what is going wrong.

I am using B4A version 2.26 and the library versions are:

AHViewPager version 1.03
core version 2.25

:sign0163:
 
Last edited:

Stulish

Active Member
Licensed User
Longtime User
from the sample app you uploaded in post #8.

When i have tried to create my own app i get a null pointer error, so i thought i was doing something wrong, that's why i used your example.

the only thing i don't understand is the original example from post #1 works fine.
 

Stulish

Active Member
Licensed User
Longtime User
Ah thanks, i didn't see that, i will revert back and try
 

Stulish

Active Member
Licensed User
Longtime User
Yep works fine with 2.25 :)
 

sea121

Member
Licensed User
Longtime User
AHViewPager Help

Please is there a method to lock a specified page in this library ?

I would like to stop move the slider and to lock a page, i tried with pager.enabled = false without success.

Thank you.

Fabrizio
 

Gunther

Active Member
Licensed User
Longtime User
Still Panel Canvas Problems with Charts?

Hello,

does the AHviewPager do have still problems with access to the panel canvas as written in history 1.01 when Layout is loaded?

I am running V1.03 and Android 4.0.3 and have attached the test project adding the viewpage and charts.bas from Klaus.

I am getting the failure "BD.Canvas.Initialize(BD.Target)" line.

Any ideas?
 

Attachments

  • test AHviewpager.zip
    13.1 KB · Views: 199
Last edited:

corwin42

Expert
Licensed User
Longtime User
does the AHviewPager do have still problems with access to the panel canvas as written in history 1.01 when Layout is loaded?
No, this problem is fixed.

Your problem is that you try to add the graph to the canvas when it is not layed out completely.

Try to move the code for creating the graph into the Pager_PageCreated Sub. At this time you can be sure that the panel has correct layout parameters and it should work.
 

Gunther

Active Member
Licensed User
Longtime User
Ok thanks I will try...
 

airblaster

Active Member
Licensed User
Longtime User
First of, great tool!
I'm looking forward to using AHViewPager.

Regarding the bug mentioned in Post 134 (http://www.b4x.com/forum/additional...sliding-panels-now-perfect-14.html#post133727), I'm experiencing it even on the unmodified example.

To reproduce it, navigate to any page other than page 0 (the only page not affected by the bug) and insert a new page.

Some data on the systems used:
Basic4Android: Version 2.30
OS: Windows 8
Phone: LG P990 / ICS Beta

I hope this helps nailing the bug down.

Regards
 

airblaster

Active Member
Licensed User
Longtime User
Just noticed: The bug also appears if you delete any page other than page 0. Or any page that becomes the first page after deleting page 0.
 

airblaster

Active Member
Licensed User
Longtime User
Seems there is a bug with the integrated listview:

Steps to reproduce:
1. Add the following code to the example project:
B4X:
Sub lv_ItemClick(Index As Int, Value As Object)
   ToastMessageShow("Index " & Index & " Value " & Value, False)
End Sub
2. Run the demo, add a new listview tab
3. Click an item in the new listview - toast message is shown as expected
4. Scroll to a different listview page
5. Click an item in the list view - nothing happens
6. Scroll the list view
7. Click an item again - toast message is shown

Expected result:
Toast message also shown in step 5
 

corwin42

Expert
Licensed User
Longtime User
Just noticed: The bug also appears if you delete any page other than page 0. Or any page that becomes the first page after deleting page 0.

I see this now. Will take a look into this.

Seems there is a bug with the integrated listview:

Steps to reproduce:
1. Add the following code to the example project:
B4X:
Sub lv_ItemClick(Index As Int, Value As Object)
   ToastMessageShow("Index " & Index & " Value " & Value, False)
End Sub
2. Run the demo, add a new listview tab
3. Click an item in the new listview - toast message is shown as expected
4. Scroll to a different listview page
5. Click an item in the list view - nothing happens
6. Scroll the list view
7. Click an item again - toast message is shown

Expected result:
Toast message also shown in step 5

I can't reproduce this. Works fine here.
 

paulrweber

New Member
Licensed User
Longtime User
Converting from "Pages" to AHViewPager

Greetings,

I have an app that has 3 pages. I use static, button controlled switching between pages. Way too "old school". :sign0137:

I would like to convert these 3 pages to AHViewPager.

I have a variety of spinners, tables, panels, etc. to transport.

Any suggestions/hints/warnings before I begin the conversion ? :sign0163:

Thanks!

:sign0087:
 

airblaster

Active Member
Licensed User
Longtime User
Thanks for looking into this!

As far as the other bug is concerned:
It seems to depend on the Android Version.
The bug does not Appear on a Motorola Milestone with Android 2.0.1.
Neither does it appear on a HTC Wildfire with Android 2.1.
However, it appears on an LG P990 with Android 4.0.4.
 
Top