B4A Library MSMaterialMenu - Animating icons

This library simulates some animations on the drawer icon on the titlebar that are coming in on the material design.
It comes from this library: https://github.com/balysv/material-menu

68747470733a2f2f7261772e6769746875622e636f6d2f62616c7973762f6d6174657269616c2d6d656e752f6d61737465722f6172742f64656d6f2e676966


Dependencies:
- The NineOldAndroid java package, is included in the zip file.

Credits:
Thanks to Informatix for his NineOldAndroids library and for modifying it for me.

Sample:
B4X:
    Dim StdABHelper As StdActionBarHelper
    Dim MMenu As MSMaterialMenu
    StdABHelper.Initialize
    MMenu.Initialize("MMenu")

    MMenu.setScaleAndStroke(1,2)
    MMenu.Color = Colors.Black
    StdABHelper.Icon = MMenu.Drawable


Sub StdAB_ButtonClicked
    If MMenu.State = "BURGER" Then
        MMenu.animatePressedState("X")
        NavDrawer.OpenDrawer
    Else
        MMenu.animatePressedState("BURGER")
        NavDrawer.CloseDrawer
    End If
End Sub

This will work best with StdActionBar+StdActionBarHelper (wish they were merged).
 

Attachments

  • MSMaterialMenu.zip
    119.5 KB · Views: 2,398
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Thanks. But my question was how to use MSIconicDrawable to get a bitmap? This is in reference to using Icon Fonts instead of directly loading a bitmap(image).

EDIT: I believe the initial link took me to material design icons page on git hub. Thanks for updating the link.
If you are lucky this might work:
B4X:
Dim bmd as BitmapDrawable = MyIconicDrawable.Drawable
Activity.AddMenuItem3(...bmd.Bitmap...)
 

Haris Hafeez

Active Member
Licensed User
Longtime User
If you are lucky this might work:
B4X:
Dim bmd as BitmapDrawable = MyIconicDrawable.Drawable
Activity.AddMenuItem3(...bmd.Bitmap...)
Thanks tds. But I have already tried it as well as tried using mutable bitmap to draw to a canvas. But they dont work :(
 

Haris Hafeez

Active Member
Licensed User
Longtime User
I get the following:


generalhelper_getbitmapfordrawable (java line: 31)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawPath(android.graphics.Path, android.graphics.Paint)' on a null object reference
at com.mikepenz.iconics.IconicsDrawable.draw(IconicsDrawable.java:497)
at anywheresoftware.b4a.objects.drawable.CanvasWrapper.DrawDrawable(CanvasWrapper.java:401)
at com.maximussoft.appcompatdrawer.generalhelper._getbitmapfordrawable(generalhelper.java:31)
at com.maximussoft.appcompatdrawer.main._activity_create(main.java:347)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:187)
at com.maximussoft.appcompatdrawer.main.afterFirstLayout(main.java:100)
at com.maximussoft.appcompatdrawer.main.access$100(main.java:17)
at com.maximussoft.appcompatdrawer.main$WaitForLayout.run(main.java:78)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5257)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.graphics.Canvas.drawPath(android.graphics.Path, android.graphics.Paint)' on a null object reference

The helper code is:
B4X:
Public Sub GetBitmapForDrawable(pDrawable As MSIconicDrawable) As Bitmap
    Dim b As Bitmap
    b.InitializeMutable(24dip,24dip)
    Dim c As Canvas
    Dim r As Rect
    r.Initialize(0,0,24dip,24dip)
    c.DrawDrawable(pDrawable.Drawable, r)
    Return c.Bitmap
End Sub
 

Haris Hafeez

Active Member
Licensed User
Longtime User
Also give this a shot:
B4X:
Dim jo as JavaObject = MyIconicDrawable.Drawable
Dim bmp as Bitmap = jo.RunMethod("toBitmap",null)
Thank you. This is the one that works. As for the canvas object, I wasn't sure whether to initialize it or not as it takes a View as param. In my case, I just wanted to write to a rect. Perhaps I need to read up a bit on Canvas :)

Cheers.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Thank you. This is the one that works. As for the canvas object, I wasn't sure whether to initialize it or not as it takes a View as param. In my case, I just wanted to write to a rect. Perhaps I need to read up a bit on Canvas :)

Cheers.
Yes you would need a view to draw on quickly, doevents, then hide it. Not ideal.
 

ArminKH

Well-Known Member
CAN u please tell me how i can use ARROW, CHECK state ?
OOOOOOOPS Solved
just try it with Legacy Debuger and not Rapid Debuger
 
Last edited:

ArminKH

Well-Known Member
@ thedesolatesoul
are u sure the icons are 24*24 ? when i use a 24*24 icon for my imageview the icon is in center and the dimensions is equel to other 24*24 icons
but when i want to load the drawabe of your lib like BURGER OR ARROW then the drawable is not in center and is a bit larger than 24*24
can u please check this? or replace the icons with material standard icons?please
 

dragonguy

Active Member
Licensed User
Longtime User
How do make it work on lollipop device, my app only work perfect on below lollipop version.
 
Last edited:

jarda

Member
Licensed User
Longtime User
MSMaterialMenu
do not work on Android 5.1.1

I can't actually open the menu, I try pressing the nav drawer icon and nothing appears to happen on my OPO
 
Last edited:

shashkiranr

Active Member
Licensed User
Longtime User
Hi @thedesolatesoul ,

I want to change the icon from up arrow to cross. I am not able to set the icon initially to arrow. It always comes as a BURGER. Is there a way I can set it to arrow ?

Best,
SK
 

Valounours

Member
Licensed User
Longtime User
Hello from France,

I have copy and paste your code to my projects but i have a error with this line :
"StdABHelper.Icon = MMenu.Drawable"

Any idea ?
 

Valounours

Member
Licensed User
Longtime User
Sorry, the log :

Installing file.
PackageAdded: package:com.maximussoft.materialdrawer
** Activity (main) Create, isFirst = true **
Error occurred on line: 106 (Main)
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.ActionBar.setIcon(android.graphics.drawable.Drawable)' on a null object reference
at de.amberhome.actionbarhelper.ActionBarHelper.setIcon(ActionBarHelper.java:99)
at com.maximussoft.materialdrawer.main._activity_create(main.java:635)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:702)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:246)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
at com.maximussoft.materialdrawer.main.afterFirstLayout(main.java:102)
at com.maximussoft.materialdrawer.main.access$000(main.java:17)
at com.maximussoft.materialdrawer.main$WaitForLayout.run(main.java:80)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
** Activity (main) Resume **
 
Top