Android Example Various Utilities created with Inline Java Code

The attached project (VariousUtilities.zip) has a large number of Bitmap and String Utilities. There is also a utility that lists the sensors of your device in the Log. Three B4A classes are defined:
1. StringUtilities
2. BitmapUtilities
3. SensorUtilities

All the methods in the classes are based on inline java code with B4A code inside the classes serving as the interface to the java code.

Results of all methods in classes StringUtilities and SensorUtilities are reported in the Log of the project. For BitmapUtilities - click on the left imageview to cycle through the various Bitmap methods. You can pass different parameters to most of the methods in class BitmapUtilities to change the appearance of an image that is generated with a specific method.

You can add to the project (complimenting/adding to the existing classes or adding new classes with their own methods supporting the new class - eg DateUtilities, TimeUtilities, etc) and compile it to a library. The project as it is at present was compiled to a library (VariousUtils.zip) and the library files (jar and xml) are included in the /files folder of the project.

Please note that when you open the B4A project and go to the Bitmap class you might find an error on line 1893. For some reason the "return" statement keeps on reverting to "Return" when the project is opened. Can't figure out why it does so. Just change the "Return" to "return" and the project will compile.

All of the Java code were found somewhere on the Web - mostly from StackOverflow
 

Attachments

  • VariousUtilities.zip
    214.9 KB · Views: 953
  • VariousUtils.zip
    24.6 KB · Views: 817

Johan Schoeman

Expert
Licensed User
Longtime User
I have added method ReadCPUinfo to class InfoUtilities. It reports a super long string of memory info to the log (returned as one looooonnnng string)
 

Attachments

  • VariousUtilities.zip
    213.1 KB · Views: 489

Johan Schoeman

Expert
Licensed User
Longtime User
Have added Class AESCryptUtilities that comes from here.

".......Simple API to perform AES encryption on Android. This is the Android counterpart to the AESCrypt library Ruby and Obj-C (with the same defaults) created by Gurpartap Singh. https://github.com/Gurpartap/aescrypt......"
 

Attachments

  • VariousUtilities.zip
    215.5 KB · Views: 733

incendio

Well-Known Member
Licensed User
Longtime User
Thanks for sharing.

Should i downloaded all variousutilities.zip files to get all utilities, or there is a latest single file that included all utilities?
 

Johan Schoeman

Expert
Licensed User
Longtime User
Thanks for sharing.

Should i downloaded all variousutilities.zip files to get all utilities, or there is a latest single file that included all utilities?
The last one that I have posted have all the utilities included in different B4A classes.
 

cimperia

Active Member
Licensed User
Longtime User
@Johan Schoeman , I was having a look at your libraries and more specifically to the Date library as I needed to do some work on dates myself.

I have noticed that whenever no parameter is required for a method, you have actually added one : dummy.
Example:
B4X:
Public Sub now() As Int()
  Dim dateAndTime(11) As Int
  Dim dummy As Int = 1
  dateAndTime = nativeMe.RunMethod("now",Array(dummy))
  Return dateAndTime
End Sub

#If Java
  public int[] now(int dummy) {
    values = new int[11];
    Calendar calendar = new GregorianCalendar();
    '.....
  }
#End If
I understand that you did that because the RunMethod requires a second argument which is an array for the java method parameters. However it's not necessary and it "pollutes" both BA and java methods:

B4X:
Public Sub now() As Int()
  Dim dateAndTime(11) As Int
  Dim dummy As Int = 1
  dateAndTime = nativeMe.RunMethod("now", Null)
  Return dateAndTime
End Sub

#If Java
  public int[] now() {
    values = new int[11];
    Calendar calendar = new GregorianCalendar();
    '.....
  }
#End If

It should be easy to fix as a global search/replace would do the trick.
Thanks again for sharing your work.
 

MikeSW17

Active Member
Licensed User
Longtime User
Hi. Just looking at your Utilities, I expect they will be highly useful, Thanks.

There is a bug, when I tried to compile, I got the error:

B4X:
Error compiling program.
Error description: Current declaration does not match previous one.
Make sure to declare the variable before it is used in a For loop.
Error occurred on line: 258
    Dim i As Int

It looks like 'i' needs to be Dim'd before the first use of 'i' earlier in VariousUtilities.b4a.
I'm guessing it should be Dim'd as an Int near the start (which clears the error), but I haven't studied the code in any detail (yet) to see if that's too simple!
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hi. Just looking at your Utilities, I expect they will be highly useful, Thanks.

There is a bug, when I tried to compile, I got the error:

B4X:
Error compiling program.
Error description: Current declaration does not match previous one.
Make sure to declare the variable before it is used in a For loop.
Error occurred on line: 258
    Dim i As Int

It looks like 'i' needs to be Dim'd before the first use of 'i' earlier in VariousUtilities.b4a.
I'm guessing it should be Dim'd as an Int near the start (which clears the error), but I haven't studied the code in any detail (yet) to see if that's too simple!
Yes, replace code with something like this:
B4X:
    Dim inputString As String = "1001"
    Dim ii As Int
    ii = msu.stringToInt(inputString)
    Log(ii)

Might also have to change "250" to some bigger number (eg 500) in class module InfoUtilities...
B4X:
public String[] deviceInfo(int dummy) {
  String[] mInfo = new String[500]         // was 250 before;
 
Top