Java Question DropBox Library attempt

thedesolatesoul

Expert
Licensed User
Longtime User
Hello people,
I made a feeble attempt at making a dropbox library but i guess i failed!!!

Anyways this is what I did.
I got the Dropbox Java source from: Dropbox - Developers - Simplify your life
I followed XverhelstX's tutorial. I fired up eclipse, added the source from the download.
But alas, it was using some kind of maven repositories. So after banging my head on the wall for a few hours I found Maven Central Search Engine . From here I could download the JAR files for all of the dependencies.

The only modification I made to the source was I added the imports for b4a.
Apart from that, nothing.

I managed to generate an xml file and a jar file. It loads up in b4a fine.
but from there on I am lost.
I cannot Dim anything from the library. I dont even know it exists.

So here is my jar and xml. Surely its all wrong, but what do i do now!
 

Attachments

  • DropboxLibrary.zip
    37.8 KB · Views: 354

thedesolatesoul

Expert
Licensed User
Longtime User
Oh hold on...
I forgot to add the imports...
I think it has worked!

Someone give it a go..i dont think i have time to test it right now
Edited:
Have now got authenticator too...

Just wondering what do I do with all these Java Types (like Map, HttpResponse etc)

Edited again to add new file with API exposed.
 

Attachments

  • DropboxLibrary.zip
    37.6 KB · Views: 366
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
This is what I am getting now:

B4X:
src\com\maximus\dropboxexample\main.java:259: inconvertible types
found   : anywheresoftware.b4a.objects.collections.Map.MyMap
required: com.dropbox.client.DropboxAPI.Config
_m2.setObject((anywheresoftware.b4a.objects.collections.Map.MyMap)(_api.authenticate((com.dropbox.client.DropboxAPI.Config)(_m.getObject()),"h@y.com","abcdef")));
                                                                                                                           ^
1 error

How do I expose another public class from the same .java file?
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
And after exposing the Config class with a @Shortname, I get

B4A line: 20
Dim cfg As DropboxReturnConfig
javac 1.6.0_21
src\com\maximus\dropboxexample\main.java:227: an enclosing instance that contains com.dropbox.client.DropboxAPI.Config is required
_cfg = new com.dropbox.client.DropboxAPI.Config();Debug.locals.put("cfg", _cfg);
^
1 error

dont understand this one now
 

thedesolatesoul

Expert
Licensed User
Longtime User
Declare the class in your file static to make it visible without needing an instance of the containing class.

Thanks. I will try this today.
I havent really done much Java, so how do you expose/unexpose classes/types/variables for libraries?

EDIT: Dont bother. I found it in Erel's tutorial. (Just @Shortname and @Hide)
 
Last edited:

agraham

Expert
Licensed User
Longtime User
Classes need to be annotated @Shortname to be visible.

Nested classes need to be annotated @Shortname to be visible and static to be accessible.

Public fields within exposed classes are visible.

Public methods within exposed classes are visible. If they need to be public but you don't want them visible to Basic4android annotate them @Hide.

Public methods named getSomething() without parameters and a non-void return are treated as readable properties. The "get" must be lowercase.

Public methods named setSomething() with one parameter and a void return are treated as writeable properties. The "set" must be lowercase.
 

agraham

Expert
Licensed User
Longtime User
Don't bother exporting that "bin" folder in your project to the jar. I assume it is the DropBox API jar but it will not be seen by Basic4android and so won't be included in the final jar.

To make Basic4android include an external jar copy and rename the AdMob xml file to match the name of the external jar and put it and the jar in your additional libraries folder and select it in the Libs tab. This will make Basic4android include the jar in your apk.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Thanks a lot for all this info. Very useful.
There was no reason for me to add the bin directory. I guess all the external jar files from the eclipse project will be added to libs or something like that?

What is the reason you would want to add the jar to the apk? I can see Admob want their api to be secret, but how can that work? Can we create libraries from just jar files?
 

agraham

Expert
Licensed User
Longtime User
What is the reason you would want to add the jar to the apk?
Because it is needed by your library at runtime. It is compiled against it by Eclipse, not included in the compiled code. Just like B4AShared.jar and Android.jar are needed at runtime. Android.jar is available on the device and B4AShared.jar is included by the IDE in your apk.
 

agraham

Expert
Licensed User
Longtime User
I was generating the XML file using javadocs.
That's is the xml required for your library code which you need. The xml file I am referring to is an almost empty one named the same as the API jar and used to inform the IDE that the API jar is needed by the library by selecting it in the IDE Libs tab.
 

thedesolatesoul

Expert
Licensed User
Longtime User
Note that I'm also giving a shot in providing support for DropBox.

What method are you using? I am sure you will finish it a lot quicker than I will (gonna take me weeks!)...so dont depend on me... ;)


That's is the xml required for your library code which you need. The xml file I am referring to is an almost empty one named the same as the API jar and used to inform the IDE that the API jar is needed by the library by selecting it in the IDE Libs tab.

Finally I understand! :) Am I slow or what!
which also answers the next question i was going to ask
I was going to ask that if you have just the JAR file (not the source), can you create a library with that.
And the answer seems that if your write a class that exposes the JAR APIs functionality then you can. But you need this almost empty xml file so that it is included by B4A IDE.
 

agraham

Expert
Licensed User
Longtime User
if you have just the JAR file (not the source), can you create a library with that.
Yes. Maybe I misunderstood! I assumed that the Dropbox API came as a jar like AdMob and others I have seen. If you do have the source then you can of course compile it in to your library and do not need an external jar.
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Yes. Maybe I misunderstood! I ssumed that the Dropbox API came as a jar like AdMob and others I have seen. If you do have the source then you can of course compile it in to your library and do not need an external jar.

Well I have both the JAR and the source, but I didnt know it could be done with the JAR.
Libraries are really going to be useful for me now that I dont have to code everything!
 

thedesolatesoul

Expert
Licensed User
Longtime User
Okay, just got home. Converted the class to static.
Next error:
Dim cfg1 As DropboxReturnConfig
javac 1.6.0_21
src\com\maximus\dropboxexample\main.java:226: cannot find symbol
symbol : constructor Config()
location: class com.dropbox.client.DropboxAPI.Config
_cfg1 = new com.dropbox.client.DropboxAPI.Config();Debug.locals.put("cfg1", _cfg1);

Looks like it cannot find the constructor for config but its still there!

Hold on! the contructor has other arguments : public Config(Map map)
I remmeber reading somewhere B4A constructors should not have this.
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
Yes, I have done that.
But this class is an extension of another class (which uses arguments in the constructor)!
Will that make any difference?
Is it okay for b4a not to have a constructor?
[I guess not. Eclipse needs a constructor]

EDIT:
I created an empty constructor that was also calling the super constructor. But I didnt know the type so I created a new constructor in the super class. I dont even know WTF I am doing!!!

Anyways 1 step ahead.
cfg1 = api.authenticate(m,\
javac 1.6.0_21
src\com\maximus\dropboxexample\main.java:262: inconvertible types
found : anywheresoftware.b4a.objects.collections.Map.MyMap
required: com.dropbox.client.DropboxAPI.Config
_cfg1 = _api.authenticate((com.dropbox.client.DropboxAPI.Config)(_m.getObject()),"h@y.com","abcdef");Debug.locals.put("cfg1", _cfg1);

This looks like a mismatch of b4a's MAP class and Java's MAP class.

EDIT:
I have got it to compile in b4a!!! Just using 1 method though!

EDIT:
Amazing...and all that happens is a force close!!!

EDIT:
Looking at unfiltered logs. This is probably happening due to what agraham told me a while ago. I have some more jar files in the project. I thought they would be added automatically to this jar file. I need to do what agraham told me to!
 
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
agraham,
when you say Admob xml, do u mean i should get the xml file from the Admob library here?
http://www.b4x.com/forum/additional...7301-new-admob-library-v1-00-a.html#post41711

EDIT: Nevermind. That GoogleAdMobAds.xml did the job!

EDIT: Now I am getting a network error i.e. authentication fails due to network error. Eventhough I have set android.permissions.INTERNET.

EDIT: Authentication is now working.

EDIT: And now AccountInfo is working:sign0136:
 
Last edited:
Top