B4A Library AHNavigationDrawer - Native Google Navigation Drawer

This is a wrapper library for the native NavigationDrawer introduced by Google at Google I/O 2013.

It contains two objects:

AHNavigationDrawer - This implements the Navigation Drawer
SlideDrawable - This is a special type of drawable used to create an indicator for the NavigationDrawer
MaterialMenuDrawable - This is a drawable which can be used to create the Material Design burger->arrow->cross->check animation.

This Library uses the android-support-v4.jar library which is part of the Android SDK. You have to install it with the Android SDK Manager. In the SDK Manager please add/download the "Extras/Android Support" package. Then you will need to copy the android-support-v4.jar file from <SDK root folder>\extras\android\support\v4 to your B4A custom libs folder!
You need at least the API17 version of the library!

The MaterialMenuDrawable uses the NineOldAndroid animation library. Download the nineoldandroids-2.4.0.jar from here and place it in your custom libs folder (you don't need an xml file for it)

The example uses the mListView library by icefairy333 and the reflection library by agraham.

Changelog:
V1.0:
- Initial version

V1.1:
WARNING: Signature of the event subs have changed!
- Added support for secondary drawer
- Ability to change drawer edge touch sensitivity size

V1.20:
- Fixed the "glitch" while opening the drawer (Sometimes the drawer got "stuck" while swiping open)

V1.21:
- Fixed bug when using NavDrawer.ContentPanel.LoadLayout()

V1.30:
- Some internal changes which should make it compatible with ULV (Ultimate ListView)
- New MaterialMenuDrawable object for Material Design Burger/Arrow/Cross/Check animation
Attention: The MaterialMenuDrawable needs the NineOldAndroids library. See above.

V1.40:
- changed typo for nineoldandroids jar file (Name change: nineoldandroid-2.4.0.jar to nineoldandroids-2.4.0.jar). If you update from older version just change nineoldandroid-2.4.0.jar in your CustomLibs folder to nineoldandroids-2.4.0.jar

Screenshot_2013-08-01-09-49-05.png
 

Attachments

  • AHNavigationDrawerExample1_1.zip
    323.7 KB · Views: 3,305
  • DoubleNavigationDrawerExample1_0.zip
    324 KB · Views: 2,413
  • AHNavigationDrawer1_40.zip
    27.8 KB · Views: 2,099
Last edited:

corwin42

Expert
Licensed User
Longtime User

corwin42

Expert
Licensed User
Longtime User
Version 1.1 added to first post. This adds support for secondary drawer (drawer on the right side) and methods for setting and getting the touch sensitivity edge size.
 

moster67

Expert
Licensed User
Longtime User
Hi,

I have been using your latest sample app (with your latest library) and I like it very much.

One problem though: With your sample app, I noted that if I change the orientation 3-4 times on my Nexus7, then after a while the images are being downsampled due to lack of memory and eventually the app will crash. What would be the best way to resolve this?

Thanks!
 

corwin42

Expert
Licensed User
Longtime User
Thats a common problem of discarding and recreating ImageViews/Bitmaps. Search the forum for out of memory problems. You will find a lot of threads discussing this. It's not a problem of this library.
 

peggjones

Active Member
Licensed User
Longtime User
I keep getting "unfortunately stopped" message when I try to run the example on a Nexus 10 or 7. I've copied the .jar file to my additional libraries folder. Any ideas?

Thanks
 

corwin42

Expert
Licensed User
Longtime User
You should see an error in the unfiltered log.

The most common problem is that you have not copied the support library or the support library is too old.
 

alexwekell

Member
Licensed User
Longtime User
Parsing code. 0.01
Running custom action. 0.03
Compiling code. Error
Error compiling program.
Error description: Unknown member: selectedbackground
Occurred on line: 60
LV1.SingleLineLayout.SelectedBackground = cd
Word: selectedbackground

I keep getting these errors, what am I doing wrong?
 
Last edited:

corwin42

Expert
Licensed User
Longtime User

corwin42

Expert
Licensed User
Longtime User
New version 1.20 available.

Fixes a bug (in the standard implementation from Google) which sometimes caused some "glitches" while opening the drawer.
 

corwin42

Expert
Licensed User
Longtime User
Is there an example combining AHNavigationDrawer with AHActionBar?

Using AHNavigationDrawer with AHActionBar should be quite simple except of setting the drawer indicator. AHActionBar uses a complete different up indicator method so it would not be easy to display a navigation drawer indicator with AHActionBar.
 

Uitenhage

Member
Licensed User
Longtime User
Hi Corwin42,

I downloaded the library (and AHActionBar; I already have Reflection) Without any changes I try to run it I get this log:

LogCat connected to: B4A-Bridge: samsung SAMSUNG-SGH-I747-351873050255442
--------- beginning of /dev/log/main
Connected to B4A-Bridge (Bluetooth)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:de.amberhome.NavDrawer
** Activity (main) Create, isFirst = true **
(Main, 40) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
java.lang.NoClassDefFoundError: de.amberhome.navdrawer.DrawerLayout$ViewDragCallback
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:232)
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:222)
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:218)
at de.amberhome.navdrawer.NavigationDrawer.Initialize2(NavigationDrawer.java:84)
at de.amberhome.navdrawer.NavigationDrawer.Initialize(NavigationDrawer.java:63)
at de.amberhome.NavDrawer.main._activity_create(main.java:315)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at de.amberhome.NavDrawer.main.afterFirstLayout(main.java:98)
at de.amberhome.NavDrawer.main.access$100(main.java:16)
at de.amberhome.NavDrawer.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)



Help!

Thanks,

Jim


EDIT: Never Mind. This is what happens with the wrong "android-support-v4.jar". Got the right one and it works beautifully. Thank You!
 
Last edited:

luke2012

Well-Known Member
Licensed User
Longtime User
This is a wrapper library for the native NavigationDrawer introduced by Google at Google I/O 2013.

It contains two objects:

AHNavigationDrawer - This implements the Navigation Drawer
SlideDrawable - This is a special type of drawable used to create an indicator for the NavigationDrawer

This Library uses the android-support-v4.jar library which is part of the Android SDK. You have to install it with the Android SDK Manager. In the SDK Manager please add/download the "Extras/Android Support" package. Then you will need to copy the android-support-v4.jar file from <SDK root folder>\extras\android\support\v4 to your B4A custom libs folder!
You need at least the API17 version of the library!

The example uses the mListView library by icefairy333 and the reflection library by agraham.

Changelog:
V1.0:
- Initial version

V1.1:
WARNING: Signature of the event subs have changed!
- Added support for secondary drawer
- Ability to change drawer edge touch sensitivity size

V1.20:
- Fixed the "glitch" while opening the drawer (Sometimes the drawer got "stuck" while swiping open)

View attachment 18708

Outstanding library!
It's possible to add icons on the left of the navigation drawer ?
 

corwin42

Expert
Licensed User
Longtime User
The navigation drawer itself is just a panel. You can add to it what you want. In my example I added a mListView list. But you can use a custom layout, UltimateListView, CustomListView or whatever you want.
 

luke2012

Well-Known Member
Licensed User
Longtime User
Hi Corwin42,

I downloaded the library (and AHActionBar; I already have Reflection) Without any changes I try to run it I get this log:

LogCat connected to: B4A-Bridge: samsung SAMSUNG-SGH-I747-351873050255442
--------- beginning of /dev/log/main
Connected to B4A-Bridge (Bluetooth)
sending message to waiting queue (CallSubDelayed - UpdateStatus)
Installing file.
PackageAdded: package:de.amberhome.NavDrawer
** Activity (main) Create, isFirst = true **
(Main, 40) FullScreen or IncludeTitle properties in layout file do not match the activity attributes settings. (warning #1004)
java.lang.NoClassDefFoundError: de.amberhome.navdrawer.DrawerLayout$ViewDragCallback
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:232)
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:222)
at de.amberhome.navdrawer.DrawerLayout.<init>(DrawerLayout.java:218)
at de.amberhome.navdrawer.NavigationDrawer.Initialize2(NavigationDrawer.java:84)
at de.amberhome.navdrawer.NavigationDrawer.Initialize(NavigationDrawer.java:63)
at de.amberhome.NavDrawer.main._activity_create(main.java:315)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at de.amberhome.NavDrawer.main.afterFirstLayout(main.java:98)
at de.amberhome.NavDrawer.main.access$100(main.java:16)
at de.amberhome.NavDrawer.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5455)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
at dalvik.system.NativeStart.main(Native Method)



Help!

Thanks,

Jim


EDIT: Never Mind. This is what happens with the wrong "android-support-v4.jar". Got the right one and it works beautifully. Thank You!

I got the same error...

SOLVED with the right "android-support-v4.jar"
 
Last edited:

socialnetis

Active Member
Licensed User
Longtime User
Hi, If I add a Listview to the activity, and then add the navigation drawer, I can't open the navigation drawer with the swipe gesture.
If I first add the navigation drawer and then the listview to the activity, I can't scroll the listview, but the swipe gesture to open the nav drawer does work. It seems that there is a conflict in the touch events, is there any workarround?

EDIT: The solution is to put the listview in the contentPanel of the Navigation Drawer, now everything works!
 
Last edited:
Top