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,074
  • screenshot-1336034966953.png
    screenshot-1336034966953.png
    9.9 KB · Views: 7,329
  • AHViewPager2_21.zip
    39.8 KB · Views: 2,335
  • AHViewPager3_00.zip
    74.9 KB · Views: 2,241
Last edited:

boten

Active Member
Licensed User
Longtime User
Can't get AHViewPager to work - please help

Please help with AHViewPager!

My SDK manager does NOT show "Android Support package" under extras (under extras I see only Google usb driver package).

I manually downloaded android-support-v4.jar and copied it to 2 places:

a) my Libraries folder (under B4A directory)
b) in my tools\android-sdk-windows\extras\android\support\v4 (NEEDED to create the support\v4, as ...\android\support was empty)

Tried to run the AHViewPagerFixed and got this error:
B4X:
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 265)
java.lang.NoSuchMethodError: android.support.v4.view.ViewPager.getCurrentItem

   at de.amberhome.viewpager.FixedTabsView.notifyDatasetChanged(FixedTabsView.java:159)
   at de.amberhome.viewpager.FixedTabsView.setViewPager(FixedTabsView.java:111)
   at de.amberhome.viewpager.FixedTabsWrapper.Initialize(FixedTabsWrapper.java:29)
   at de.amberhome.viewpagerexample.main._activity_create(main.java:265)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at de.amberhome.viewpagerexample.main.afterFirstLayout(main.java:84)
   at de.amberhome.viewpagerexample.main.access$100(main.java:16)
   at de.amberhome.viewpagerexample.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)

The 2nd sample: AHViewPager gave this error:
B4X:
** Activity (main) Create, isFirst = true **
main_activity_create (java line: 316)
java.lang.AbstractMethodError: abstract method not implemented

   at android.support.v4.view.PagerAdapter.instantiateItem(PagerAdapter.java)
   at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:321)
   at android.support.v4.view.ViewPager.populate(ViewPager.java:441)
   at android.support.v4.view.ViewPager.onAttachedToWindow(ViewPager.java:563)
   at android.view.View.dispatchAttachedToWindow(View.java:6016)
   at android.view.ViewGroup.dispatchAttachedToWindow(ViewGroup.java:1116)
   at android.view.ViewGroup.addViewInner(ViewGroup.java:2005)
   at android.view.ViewGroup.addView(ViewGroup.java:1865)
   at android.view.ViewGroup.addView(ViewGroup.java:1845)
   at anywheresoftware.b4a.objects.ActivityWrapper.AddView(ActivityWrapper.java:107)
   at de.amberhome.viewpagerexample.main._activity_create(main.java:316)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at de.amberhome.viewpagerexample.main.afterFirstLayout(main.java:84)
   at de.amberhome.viewpagerexample.main.access$100(main.java:16)
   at de.amberhome.viewpagerexample.main$WaitForLayout.run(main.java:72)
   at android.os.Handler.handleCallback(Handler.java:587)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:123)
   at android.app.ActivityThread.main(ActivityThread.java:4627)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:521)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
   at dalvik.system.NativeStart.main(Native Method)
 

boten

Active Member
Licensed User
Longtime User
from java2s.com date of file is August 9, 2011
There's also some android-support-v4_patched.jar from October 7, 2011
If u're on it - what is the correct file and where should I put it (in both palces I did or just in 1 place?)
 

Informatix

Expert
Licensed User
Longtime User
from java2s.com date of file is August 9, 2011
There's also some android-support-v4_patched.jar from October 7, 2011
If u're on it - what is the correct file and where should I put it (in both palces I did or just in 1 place?)

This file is provided with the Android SDK. You don't have to download it.

Folder: android-sdk\extras\android\support\v4\

In the SDK manager, check "Android support library" under Extras.
 
Last edited:

boten

Active Member
Licensed User
Longtime User
Informatix;143671..... In the SDK manager said:
As i wrote in my 1st post, I do NOT have "android support library" under extras.
Here's what my SDK manager looks like:
 

Attachments

  • Image1.jpg
    Image1.jpg
    70.6 KB · Views: 183

boten

Active Member
Licensed User
Longtime User
EDIT: Copied the new files from the zipped DL'ed file manually. Now I see the "extra" will try and do it now.
thx for the help so far.



I'm completely buffled!

Went and updated tools.

1) Android SDK platform tools was updated from revision 9 to revision 12.

2) Android SDK tools did NOT update from rev. 15 to rev. 20 because of the warning msg (image below).

I disabled any anti-virus and did a cold-boot, started SDK manager from the start button (no windows explorer used) and still got that msg. Any ideas?

Needles to say: Extras still does not have the "support..."
 

Attachments

  • Image3.jpg
    Image3.jpg
    36.9 KB · Views: 163
Last edited:

GuyBooth

Active Member
Licensed User
Longtime User
Sticky AHView Panels

Let's try this again :)
I have four panels.
The first is loaded with a small number (< 100) of items in a custom listview
The second contains a Custom Listview with 900+ items
The third contains a Listview with approx 6000 items
The fourth contains an empty panel.

When I move between Panels 1 and 2 and 2 and 3, I have no problems. I can go back and forth and everything is smooth.
If I then go from panel 3 to panel 4 the movement is smooth. I can now go back and forth between panels 3 and 4 smoothly.

But now, when I go back from panel 3 to panel 2 there is a significant delay - about 2 seconds - before teh panels slides over.
Once at panel 2, I can once again move smoothly back and forth between panels 1, 2 and 3.
If I go back to panel 4 the behaviour repeats itself.

This happens on my Galaxy S3 running Jellybean. It does NOT show up in the simulator! In the simulator it is smooth all the way across all four panels.

Any ideas?
 

corwin42

Expert
Licensed User
Longtime User
Let's try this again :)

I have seen your question but I'm sorry, I have no idea why this happens. Have you tried it on different devices than emulator and S3? Without analyzing your code It would be hard to make a guess here.
 

GuyBooth

Active Member
Licensed User
Longtime User
I have seen your question but I'm sorry, I have no idea why this happens. Have you tried it on different devices than emulator and S3? Without analyzing your code It would be hard to make a guess here.

I'll see if I can set it up on a Galaxy Tab during the next couple of days.
 

GuyBooth

Active Member
Licensed User
Longtime User
The Galaxy Tab exhibits the same behaviour.

One thing is clear - when the number of items in the listviews attached to the sliding panels is small, the problem goes away. Can't put a number on it yet, nor can I tell if the problem gradually changes or if there is a threshhold.
 

cstangor

Member
Licensed User
Longtime User
Repost of question

Sorry for the repost, but I don't think was answered and I haven't figured it out.

How do I remove all of the pages to start over? I noticed that initializing the Class module doesn't do it.

merci
 

corwin42

Expert
Licensed User
Longtime User
How do I remove all of the pages to start over? I noticed that initializing the Class module doesn't do it.

You have to remove all pages from the container:

B4X:
Dim PC as AHPageContainer

[...]

For i = 0 To PC.Count - 1
   PC.DeletePage(0)
Next

Or Dim the container again and initialize the ViewPager again with it.
 

airblaster

Active Member
Licensed User
Longtime User
Regarding the bug that makes it impossible to swipe the viewpager on Icecream Sandwich and newer: Informatix found some new information, I'll try to relay it here.

Basically, the problem is that both ScrollView2D (which is used by Ultimate List View) and AHViewPager try to intercept the Scrolling events.
Due to some internal changes in Icecream Sandwich, AHViewPager doesn't receive the events anymore (ScrollView2D receives them first).
Informatix suggested that this could probably be fixed in AHViewPager by calling requestDisallowInterceptTouchEvent.

I hope this helps fixing this nasty bug.
 

Informatix

Expert
Licensed User
Longtime User
Regarding the bug that makes it impossible to swipe the viewpager on Icecream Sandwich and newer: Informatix found some new information, I'll try to relay it here.

Basically, the problem is that both ScrollView2D (which is used by Ultimate List View) and AHViewPager try to intercept the Scrolling events.
Due to some internal changes in Icecream Sandwich, AHViewPager doesn't receive the events anymore (ScrollView2D receives them first).
Informatix suggested that this could probably be fixed in AHViewPager by calling requestDisallowInterceptTouchEvent.

I hope this helps fixing this nasty bug.

It's not exactly that. The both views trap the touch events (and the ScrollView2D can consume them all because it handles vertical and horizontal moves). The AHViewPager is supposed to intercept these events and consume them when it uses them (so the horizontal swipe is reserved for its own use), but it's not what happens.
 

Informatix

Expert
Licensed User
Longtime User
Is it worth trying the latest android-support-v4.jar in case something has been fixed in that?

I don't think that Google will fix this because it seems that's the standard way of handling touch events. If a child requests some touch events for itself, the parent has to ignore these events. It's convenient when you want to disable the scrolling in a list for example, but it's strange to me that there's no possibility to accept or not this behavior. In brief, the parent always obeys to its children. I wasn't aware of that before.
With the new version, UltimateListView acts now as a good boy and doesn't request anything if you use the added function, so AHViewPager won't miss an event.
My Android knowledge increases every day... thanks to bugs. :)
 
Top