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: 2,638
  • DoubleNavigationDrawerExample1_0.zip
    324 KB · Views: 1,837
  • AHNavigationDrawer1_40.zip
    27.8 KB · Views: 1,535
Last edited:

Alisson

Active Member
Licensed User
Corwin42, my test result one fail.
I receive the message: "The Navigation Drawer stopped".
What can I do?
 

corwin42

Expert
Licensed User
I have one error:

View attachment 40427
How can solve the problem?

It seems that the nineoldandroids library is added multiple times. What Libraries do you use in your project and/or do you use #AdditionalJar property to add it manually?
 

shashkiranr

Active Member
Licensed User
Hi All,

After using the material menu along with appcompact actionbar and navigation panel,It is occupying more space in the actionbar. i have added a edittext to the actionbar to show the difference.

Before adding the material menu to upindicator,

before.png


After adding the material menu to upindicator.

after.png


Update : used the gravity property and fixed it.

Best,
SK
 
Last edited:

infow

Member
Licensed User
Getting this running, trying to open AD:
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Resume **
An error occurred:
(Line: 0) End Sub
java.lang.Exception: Sub drawer_drawerslide signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject actn.drwr.actiondrawer_subs_0._drawer_drawerslide(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
 

uniplan

Active Member
Licensed User
I would like to know if I can open the SecondaryDrawer with a command (for example with a dedicated button) and not just by sliding the right of the screen.
 

corwin42

Expert
Licensed User
I would like to know if I can open the SecondaryDrawer with a command (for example with a dedicated button) and not just by sliding the right of the screen.
B4X:
NavDrawer.OpenDrawer2(NavDrawer.GRAVITY_RIGHT)
 

Dave O

Well-Known Member
Licensed User
Hi @corwin42 , thanks for this control! I'm trying it in my next app.

It did take me a few tries to figure out that I should:
- initialize the nav drawer to the activity directly
- load my layout from the drawer.contentPanel, not the activity

Additional question: On long clicks on a view, I show a tooltip toast message. The code that calculates the tooltip's position goes up the view hierarchy to accumulate the left and top offsets. However, my code can't yet handle the nav drawer (which it encounters when climbing up from the view to the content panel to the drawer).

It crashes when the code below encounters a "drawerLayout":

B4X:
Sub getScreenPosition(viewArg As View) As Int()
   Dim position(2), parentPosition(2) As Int
   If viewArg.parent Is ScrollView Then
     'the scrollview's panel has no layout, so ignore
     Dim sv As ScrollView = viewArg.Parent
     position(0) = sv.left
     position(1) = sv.Top - sv.ScrollPosition
     Return position
   else If viewArg.parent Is AHNavigationDrawer Then     '<< this never gets triggered, so it climbs one more to the activity
     position(0) = 0
     position(1) = 0
     Return position
   else if viewArg.parent = getCurrentActivity Then
     Log("viewArg = " & viewArg)
     Log("viewArg.parent = " & viewArg.parent)
     position(0) = viewArg.Left                                '<< crashes here (because drawer has no Left property?)
     position(1) = viewArg.Top
     Return position
   Else
     parentPosition = getScreenPosition(viewArg.parent)
     position(0) = viewArg.Left + parentPosition(0)
     position(1) = viewArg.top + parentPosition(1)
     Return position
   End If
End Sub

Any tips on how to handle the nav drawer in this situation?

Thanks again!
 

Stern0m1

Member
Licensed User
I having trouble getting the android-support-v4.jar file. Can anyone send me a direct link?

by me in C:\Android\extras\android\m2repository\com\android\support\support-v4\22.1.0
I have support-v4-22.1.0-sources. I tried puting that file in the extra libraries folder but im still getting the error asking for the android-support-v4.jar file. I tried renaming it also.


Thanks
 

corwin42

Expert
Licensed User
I having trouble getting the android-support-v4.jar file. Can anyone send me a direct link?

by me in C:\Android\extras\android\m2repository\com\android\support\support-v4\22.1.0
I have support-v4-22.1.0-sources. I tried puting that file in the extra libraries folder but im still getting the error asking for the android-support-v4.jar file. I tried renaming it also.

You don't need the android-support-v4.jar file anymore.

Just add:
B4X:
#AdditionalJar: com.android.support:support-v4
and it should work. You will need B4A 6+
 

MichalK73

Active Member
Licensed User
yes but there was a problem with old B4A versions. Be sure to use B4A 4.00 or above and use the Activity_ActionBarHomeClick event.

I have
B4X:
Sub Activity_ActionBarHomeClick
    Log("NavDrawer open")
    NavDrawer.OpenDrawer
End Sub

Does not work. In general it does not execute code. How to solve it?
 

corwin42

Expert
Licensed User
I have
B4X:
Sub Activity_ActionBarHomeClick
    Log("NavDrawer open")
    NavDrawer.OpenDrawer
End Sub

Does not work. In general it does not execute code. How to solve it?

As I wrote in another thread:

Call ToolBar.InitMenuListener
and use the ToolBar_NavigationItemClick event.
 

MichalK73

Active Member
Licensed User
Is it possible use of two NavDrawer the left and right? I would like in some moments of the program that was NavDraver on the right side of the other options. It is possible?
 
Top