Java Question Wrapping Library with xml files required

walterf25

Expert
Licensed User
Longtime User
Hello all, i'm trying to wrap a CircularProgressBar library, i'm just trying to do this for fun, i've wrapped a few other libraries before but i'm a little confused with this library, since it requires a few xml libraries to be included. Here's what i have so far.

Code: Copy
package com.genesis.circularprogressbar;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.DependsOn;
import anywheresoftware.b4a.BA.Permissions;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

import com.lylc.widget.circularprogressbar.example.CircularProgressBar;



@Version(1.0f)
@ShortName("B4ACircularProgressBar")
@ActivityObject
@Permissions(values={"android.permission.INTERNET"})
@Author("Walter F")
@DependsOn(values = { "CircularProgressBar" })

public class B4ACircularProgressBar {
   
    public void Initialize(BA ba, String eventname){
        CircularProgressBar c1 = new CircularProgressBar(ba.context);
        c1.setProgress(45);
    }

}

The library compiles just fine in Eclipse, but i get a Resource Not found error when I try to use it in my B4A project, of course this has to do with the xml files that are needed.

How can I call this files or include them in my project so that i get rid of this error?

I know it might be a simple answer, but my brain keeps farting at the moment.

I'd really appreciate it if anyone can point me in the right direction.

The original project can be found here.https://github.com/ylyc/circular_progress_bar

Thanks everyone in Advance.

Cheers,
Walter
 
I would love to know this too. I 'm not understand how to create library(How to convert) when we have the original project. Please give me only example. I think I will clearly.

Should I start at this java file ?


@Walter I think it should be below.
import com.lylc.widget.circularprogressbar.example;
 
Last edited:
@Erel I've be understand 2 examples in simplewrapper tool. The first,it is easy function,the second,it is sdk and has jar file . And the third is this which I still not understand how to create it.
 
Have you tried to copy the resource files to your project Objects\res (and make them readonly)?
Hi Erel, yes i tried copying the resource files to my objects/res folder, but it doesn't seem to work.

Thanks,
Walter
 
Use the AdditionalRes attribute in the project, to point to the res folder for the library.

Also, as a tip for views, use ViewWrapper to wrap it.

i.e.
Code: Copy
public class B4ACircularProgressBar extends <ViewWrapper> CircularProgressBar {
Thanks for that tip tds, i will try that.

Cheers,
Walter
 
I used the extend viewWrapper<CircularProgressBar> and also tried the AdditionalRes attribute but i get this error.

PackageAdded: package:com.genesis.circular
** Activity (main) Create, isFirst = true **
android.content.res.Resources$NotFoundException: Resource ID #0x7f040000 type #0x5 is not valid
at android.content.res.Resources.getColor(Resources.java:1697)
at com.lylc.widget.circularprogressbar.example.CircularProgressBar.init(CircularProgressBar.java:95)
at com.lylc.widget.circularprogressbar.example.CircularProgressBar.<init>(CircularProgressBar.java:68)
at com.genesis.circularprogressbar.B4ACircularProgressBar.Initialize(B4ACircularProgressBar.java:31)
at com.genesis.circular.main._activity_create(main.java:319)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.genesis.circular.main.afterFirstLayout(main.java:98)
at com.genesis.circular.main.access$100(main.java:16)
at com.genesis.circular.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

Any Ideas?
 
Now I get this error

I excluded the res folder from the eclipse project.

I also used the AdditionalRes Attribute in my b4a project, but i get the error below.

Any suggestions please?

Walter
 

Attachments

  • error.jpg
    error.jpg
    206.4 KB · Views: 573
Hi Guys again, i got the library working, but i want to expand and expose all of the functionalities, right now i can only display the basic circular progressbar but in the original project, I see that there are various styles declared in the activity_main.xml file, i need to know how to load those different layouts from code. Can anyone please help me with this. I tries this but i get a null exception error when i run my b4a project.

Code: Copy
String resourceName="circularprogressbar2";
        int resourceId = BA.applicationContext.getResources().getIdentifier(resourceName, "id", BA.packageName);
        BA.Log("ResourceID " + resourceId);
final CircularProgressBar c2 = (CircularProgressBar) new CircularProgressBar(ba.context).findViewById(R.id.circularprogressbar2);

on the original project they call it like this
Code: Copy
final CircularProgressBar c2 = (CircularProgressBar) findViewById(R.id.circularprogressbar2);

This is the error I get now

Installing file.
PackageAdded: package:com.genesis.circular
** Activity (main) Create, isFirst = true **
ResourceID 2131296257
rogressbar.B4ACircularProgressBarAnimatedProgressBar (B4A line: 32)
progress1.AnimatedProgressBar(0, 80, "animated")
java.lang.NullPointerException
at com.genesis.circularprogressbar.B4ACircularProgressBar.AnimatedProgressBar(B4ACircularProgressBar.java:62)
at com.genesis.circular.main._activity_create(main.java:319)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
at com.genesis.circular.main.afterFirstLayout(main.java:98)
at com.genesis.circular.main.access$100(main.java:16)
at com.genesis.circular.main$WaitForLayout.run(main.java:76)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)

Hope I make sense, thanks all.

Any ideas?

Cheers,
Walter
 
Last edited:
Never Mind again, i also figured it out, haha.

I will post the library once i'm done.

this is how i did it.

Code: Copy
final CircularProgressBar c2 = (CircularProgressBar) new CircularProgressBar(ba.context, null, BA.applicationContext.getResources().getIdentifier(resourceName, "layout", BA.packageName));

Thanks,
walter
 
Back
Top