Android Code Snippet DynamicToast Library & JavaObject

You know this simple and fantastic wrapper by @Johan Schoeman ( DYNAMICTOAST ) this you can found in GitHub( MyDinamicToastMessage ) and you have this nice result:

mydynamictoast1.png


Now the library @Johan Schoeman ( thanks Johan ;) ) already work without problem, but browsing the library i saw that you can customize the toastmessage ( and i dont see this in wrapper )
Infact you found in documentation this point:

B4X:
5) Custom Toast

User can customize Toast as like bellow exampe.

MyCustomToast myCustomToast = new MyCustomToast(MainActivity.this);
myCustomToast.setCustomMessageText("custom toast message..");
myCustomToast.setCustomMessageTextSize(18);
myCustomToast.setCustomMessageTextColor(Color.WHITE);
myCustomToast.setCustomMessageIcon(R.drawable.ic_success, MyCustomToast.POSITION_LEFT);
myCustomToast.setCustomMessageIconColor(Color.WHITE);
// myCustomToast.setCustomMessageBackgroundColor("#853657");
myCustomToast.setCustomMessageBackgroundDrawable(R.drawable.info_message_background);
myCustomToast.setCustomMessageDuration(MyCustomToast.LENGTH_LONG);
myCustomToast.setGravity(Gravity.CENTER, 0, 0);
myCustomToast.setCustomMessageTypeface("cambriai.ttf");
myCustomToast.show();

so i think with JavaObject/B4X ALL IS POSSIBLE and so i translated To the Java code to Javaobject.
The translate code is:

B4X:
rclass.InitializeStatic("com.desai.vatsal.mydynamictoast.R.drawable")
    Log(rclass.GetField("ic_error"))

    Dim sizechar As Float = 18
    
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    jo.InitializeNewInstance("com.desai.vatsal.mydynamictoast.MyCustomToast", Array(ctxt))
    jo.RunMethod("setCustomMessageText", Array("custom toast message.."))
    jo.RunMethod("setCustomMessageTextSize", Array(sizechar))
    jo.RunMethod("setCustomMessageTextColor", Array(Colors.White))
    jo.RunMethod("setCustomMessageIcon", Array(rclass.GetField("ic_success"), jo.GetField("POSITION_LEFT")))
    jo.RunMethod("setCustomMessageIconColor", Array(Colors.White))
    jo.RunMethod("setCustomMessageBackgroundColor", Array("#853657"))
    jo.RunMethod("setCustomMessageBackgroundDrawable", Array(rclass.GetField("info_message_background")))
    jo.RunMethod("setCustomMessageDuration", Array(jo.GetField("LENGTH_LONG")))
    jo.RunMethod("setGravity", Array(Gravity.CENTER, 0, 0))
    jo.RunMethod("setCustomMessageTypeface", Array("cambria.ttf"))
    jo.RunMethod("show", Null)


With this result:
mydynamictoast5.png


Really very very power JavaObject
 

Attachments

  • DynamicToast2.zip
    198.9 KB · Views: 733
Last edited:
Top