Java Question Ambitious first library

bravotango

Member
Licensed User
Longtime User
I am just starting with B4A and it may be a bit early but I am interested in creating a Library.

I have followed the video tutorial and successfully created the javadoc for a useless little simple multiply app but that still leaves me at a loss of what next.

As an example in Eclipse when I begin to type entries in the layout main.xml file under AnalogClock I get a drop down list containing hundreds of options, the three topmost entries are android:dial, android:hand_hour, and android:hand:minute.

In B4A I have the AnalogClock addon selected and I have dim Clock As AnalogClock but when I type Clock.... I only get half a dozen options which hardly scratch the surface of what is available in the SDK.

So it looks like I first need to create an addon Library for R.Styleable but I have looked at the tutorial and it hardly helps at all. In fact it is almost impossible to understand what it is about. The references in the turorial seem to be referring to other information that one is supposed to understand from some other unknown source, for example "Raising event is done by calling to BA.raiseEvent. This is its signature" and I say to self "Oh, the old Raise Event trick", like as if I already know what is being discussed here (which I don't of course). Obviously I am missing something.

What I'm getting at is where is the additional information necessary to understand how to create an addon Library? I really don't have any idea of what code to put in the main java class for this. Should I just copy the R.Styleable class and paste that in or should I pretend to make a running android application in raw java with all the features I want or what?

Please excuse my ignorance and lack of understanding but any suggestions are welcome.
 

bravotango

Member
Licensed User
Longtime User
You will pretend to write a class in raw java and then plug that in to b4a.
You need to expose the required functionality in b4a. The tutorials just show you how to plug it in.
I think you need to read some Android dev in java tutorials.

Sent from my GT-I9000 using Tapatalk

Thanks for your comment. I guessed that might have been the way to do this. I will give it a try and see what happens.

Bazza
 

bravotango

Member
Licensed User
Longtime User
Finally I think I have made a Library but not by making an android app in eclipse in raw java. I tried that and it was just full of errors because it should be an android project and not a java project. So my next guess was to use JD-GUI (from JD | Java Decompiler) and extract a class from an android platform in the SDK. This little desktop program is a standalone graphical utility that displays Java source codes of ".class" files. I copied the analogclockfrom the android.jar under android.widget and it compiled perfectly in eclipse and created javadoc and jar file OK. When I open this with B4AHelp there are literally hundreds of methods fields and properties available. Only thing is I still don't know how to get 'Initialize' into the xml and I have no idea what a wrapper is supposed to be or how it is created.

The method I have used may seem strange but how to get to this is not covered in the tutorial.

All the best from Bazza
 

warwound

Expert
Licensed User
Longtime User
Finally I think I have made a Library but not by making an android app in eclipse in raw java. I tried that and it was just full of errors because it should be an android project and not a java project.

A library should be a Java project NOT an Android project.

So my next guess was to use JD-GUI (from JD | Java Decompiler) and extract a class from an android platform in the SDK. This little desktop program is a standalone graphical utility that displays Java source codes of ".class" files.

Open some of the user created libraries with JD-GUI and look at how others have created their libraries.

Only thing is I still don't know how to get 'Initialize' into the xml and I have no idea what a wrapper is supposed to be or how it is created.

Search the forum for "ViewWrapper", this is a B4A Class that handles much of the background tasks needed to turn a native Android View into a B4A View.

B4X:
package my.package.name;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.ActivityObject;
import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.Hide;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;
import anywheresoftware.b4a.objects.ViewWrapper;

@ActivityObject
@Author("My Name")
@ShortName("MyAndroidView")
@Version(1.0f)

public class AndroidViewWrapper extends ViewWrapper<AndroidView> {

   // you will need an Initialize method if you need to pass extra parameters over the default ViewWrapper Initialise method otherwise you don't need it
   
   /**
    * Comment your Initialize method here.
    */
   @Override
   public void Initialize(BA ba, String EventName, int ExtraParameter) {
      super.Initialize(ba, EventName);
      // do the extra bits here
   }

   // you need an innerInitialize to create and set your AndroidView object
   @Hide
   public void innerInitialize(BA ba, String eventName, boolean keepOldObject) {
      if (!keepOldObject){
         setObject(new AndroidView(ba.context));
      }
      super.innerInitialize(ba, eventName, true);
   }

   // the rest of your code goes here you access your underlying object with getObject()
   // e.g
   // something = ((AndroidView)getObject()).whatever;

   /**
    * Your method comments here.
    * B4AMethod1 calls the invalidate() method of the native AndroidView
    */
   public void B4AMethod1(){
      ((AndroidView)getObject()).invalidate();
   }
   
}

As long as you have Eclipse and your Java project properly set up, building the JAR and XML files is all automatic.

Martin.
 

Attachments

  • AndroidViewWrapper.zip
    746 bytes · Views: 310
Top