Android Tutorial Accesing third party Jar with #Additionaljar and JavaObject - Picasso

Discussion in 'Tutorials & Examples' started by Erel, May 12, 2014.

  1. ppgirl

    ppgirl Member Licensed User

    In activity module.

    this is B4A's java code

    //BA.debugLineNum = 120;BA.debugLine="wdj.InitializeNewInstance(\"com.qq.e.ads.InterstitialAd\",Array (GetContext ,\"1101721111\",\"9079537215654558411\"))";
    mostCurrent._wdj.InitializeNewInstance("com.qq.e.ads.InterstitialAd",new Object[]{(Object)(_getcontext().getObject()),(Object)("1101721111"),(Object)("9079537215654558411")});
     
  2. stevel05

    stevel05 Expert Licensed User

    Can you zip and post your project (and the library jar) and a link to the documentation / demo code.
     
  3. ppgirl

    ppgirl Member Licensed User

    Hi Stevel,

    There is the SDK and B4A demo code.

    SDK is a whole Java demo code sample.zip and jar.

    B4A demo code sdkdemo.zip is made by me , you can check the problem.

    please copy those jar to library directory.

    Thanks!
     

    Attached Files:

  4. stevel05

    stevel05 Expert Licensed User

    OK, the constructor doesn't want the context as an argument, it wants the activity, which you can get using this code (Requires the reflection library):

    Code:
    Sub GetActivity As Object
        
    Dim R  As Reflector
        
    Return R.GetActivity
    End Sub
    Then:

    Code:
    Sub Activity_Create(FirstTime As Boolean)
        
    'Do not forget to load the layout file created with the visual designer. For example:
        Activity.LoadLayout("main")

        wdj.InitializeNewInstance(
    "com.qq.e.ads.InterstitialAd",Array (GetActivity ,"1101721115","9079537215654558411"))
        wdjop1=wdj.CreateEvent(
    "com.qq.e.ads.InterstitialAdListener""callbackwdj"Null)     
        wdj.RunMethod(
    "setAdListener",Array(wdjop1))
        wdj.RunMethod(
    "loadAd"Null)   
    End Sub
    Without the JavaDoc, it's not going to be possible to help much further I'm afraid. I tried translating their website into English, but couldn't find anything useful.

    I hope this get's you up and running.
     
  5. ppgirl

    ppgirl Member Licensed User

    Great! It is OK , the SDK is a AD SDK.

    I forget it can get activity by Reflector.

    Thanks!!!
     
  6. ivan.tellez

    ivan.tellez Active Member Licensed User

    Hi

    Im triing to use use an external jar to render SVG files https://code.google.com/p/androidsvg/

    Code:
    Sub GetSVG(SVGString As StringAs JavaObject
      
    Dim jo As JavaObject
      
    Return jo.InitializeStatic("com.caverock.androidsvg.SVG").RunMethod("getFromString"Array(SVGString))
    End Sub




    Sub Button1_Click
       
    Dim Canvas1 As Canvas
       
    Dim MyBMP As Bitmap
       MyBMP.InitializeMutable(
    512,512)
       Canvas1.Initialize2(MyBMP)
       
       
    Dim SVGString As String = File.ReadString(File.DirAssets, "android.svg")
       
       
    'Log(GetSVG(SVGString).RunMethod("getDocumentWidth", Null))     'This works
       
       
    'GetSVG(SVGString).RunMethod("renderToCanvas", Array(Canvas1))   'This is not working
       'GetSVG(SVGString).RunMethod("renderToPicture", Null)        'Returns an Android.Graphics.Picture, How to convert to Android.Graphics.Bitmap?
    End Sub
    I can load the SVG file, but cant use the render methods, any idea in how to get this working?

    Thanks
     
    Last edited: Jul 20, 2014
  7. stevel05

    stevel05 Expert Licensed User

    The B4a Canvas is a wrapper for the android.graphics.Canvas object. You need to get the android object from the wrapper:

    Code:
    Dim CnvJO As JavaObject = Canvas1
    GetSVG(SVGString).RunMethod(
    "renderToCanvas"Array(CnvJO.GetField("canvas")))
    I hadn't come across the android.graphics.Picture class, but looking at the documentation, to make it usable in B4a you'll need to render it to a canvas. So it seems a bit redundant unless you want the functionality of the Picture class itself. A quick test didn't work properly so that'll be an investigation you'll need to carry out if you want to use it.
     
    Last edited: Jul 20, 2014
  8. ivan.tellez

    ivan.tellez Active Member Licensed User

    Well, Actually It works...


    Thanks
     
    Last edited: Jul 21, 2014
  9. ivan.tellez

    ivan.tellez Active Member Licensed User

    Hi, can you help me with another question please, how can you use a Type that its not accesible in B4A

    For example, if there is a function in the java code like

    public RectF getDocumentViewBox()

    How can use the RectF object in B4A? If I use a standard Rect, it raises an error

    Code:
    Dim tRect as Rect
    Thanks
     
  10. stevel05

    stevel05 Expert Licensed User

  11. ivan.tellez

    ivan.tellez Active Member Licensed User

    Wow, it works the other way too.

    Code:
    Dim rect1 As JavaObject
        rect1.InitializeNewInstance(
    "android.graphics.RectF"Null)
        rect1 = 
    SVG.RunMethod("getDocumentViewBox"Null)

    Thanks :D
     
    Last edited: Jul 22, 2014
  12. Steini1980

    Steini1980 Member Licensed User

    Code:
    GetPicasso.RunMethodJO("load"Array(url)).RunMethodJO("into"Array(img1))
    Works fine, but how can I save the Image in ImageView "img1" ???
    Img1.Bitmap seems empty, but the Image will be shown on Imageview.

    Could someone help me saving the Image loaded via Picasso into File?!
     
    picenainformatica likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    Are you calling img1.Bitmap in Callback_Event? Only then will the image be ready.
     
  14. Steini1980

    Steini1980 Member Licensed User

    At the moment I have tried only without callback event. But I have used Sleep Function to wait 10 Seconds, i saw the picture in ImageView befor timer was zero. But the img1.Bitmap was empty too. Did you think I should try with Callback? Maybe the Bitmap will stored as Background Image or if possible only drawed at the control? What can I try else? Is it possible to catch the data directly from content:// url, without storing in ImageView (I also tried via httpUtils2 but it doesn't it seems only working with http:// urls?
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Try the callback. It is very simple. Check the value of Log(img1.Background).
     
  16. Steini1980

    Steini1980 Member Licensed User

    If I try Callback with Log("IMG1 BG: "& img1.Background &" BMP: " & img1.Bitmap,True) then

    Background has a Value and Bitmap is Null in Callback.
    Because Background has also a Value when I start Activity, I don't know if the value has changed after Callback.

    How can I catch the Background Value as File?
     
    Last edited: Aug 7, 2014
  17. a2stepper

    a2stepper Member Licensed User

    i have copy and pasted your example from above and get this error:

    Parsing code. Error
    Error parsing program.
    Error description: Attribute not supported: additionaljar
    Occurred on line: 16
    #AdditionalJar: picasso-2.2.3

    using B4A version 3.20.
    is there anything else i need to do to get working.
    thanks.
    paul
     
  18. a2stepper

    a2stepper Member Licensed User

    when i copy and pasted the code from the above, and ran it i got this message

    #AdditionalJar: picasso-2.2.3 is unknown??

    im using B4A ver 3.20

    is there something else to get working?
    thanks.
    paul
     
  19. Erel

    Erel Administrator Staff Member Licensed User

    #AdditionalJar attribute was added in v3.80.
     
  20. tunderin

    tunderin Member Licensed User

    A no java knowledge question - can I use #AdditionalJar with a .so library?
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice