B4A Library CalibratorSensor

A wrap for this Github project.

Keep your phone in a "portrait vertical position" and move it around in a figure 8 motion. The returned values are radians. Convert them to degrees if you want to display the values in degrees.

1.png


Sample code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: b4aCalibratorSensor
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private cs As CalibratorSensor
    Private Label1 As Label
    Private Label2 As Label
    Private Label3 As Label
    Private Label4 As Label

End Sub

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


End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

    cs.stopOrientation

End Sub


Sub cs_percentage_completed(percentage As Int)

   Label4.Text = "% Calibration completed = " & percentage

End Sub

Sub cs_apr_values(azimuth As Float, pitch As Float, roll As Float)

    Label1.Text = "Azimuth = " & azimuth
    Label2.Text = "Pitch = " & pitch
    Label3.Text = "Roll = " & roll

End Sub

The B4A manifest file:
B4X:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="5" android:targetSdkVersion="19"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
AddManifestText(<uses-feature android:name="android.hardware.sensor.accelerometer"
        android:required="true" />)

AddManifestText(<uses-feature android:name="android.hardware.sensor.magnetic"
        android:required="true" />)

Attached the B4A sample project and the B4A library files. Extract and copy the B4A library files to your additional library folder.

Library:
CalibratorSensor
Version:
1
  • CalibratorSensor
    Events:
    • apr_values (azimuth As Float, pitch As Float, roll As Float)
    • percentage_completed (percentage As Int)
    Fields:
    • ba As BA
    Methods:
    • BringToFront
    • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
    • Initialize (EventName As String)
    • Invalidate
    • Invalidate2 (arg0 As Rect)
    • Invalidate3 (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • IsInitialized As Boolean
    • RemoveView
    • RequestFocus As Boolean
    • SendToBack
    • SetBackgroundImage (arg0 As Bitmap)
    • SetColorAnimated (arg0 As Int, arg1 As Int, arg2 As Int)
    • SetLayout (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int)
    • SetLayoutAnimated (arg0 As Int, arg1 As Int, arg2 As Int, arg3 As Int, arg4 As Int)
    • SetVisibleAnimated (arg0 As Int, arg1 As Boolean)
    • stopOrientation
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Padding()() As Int
    • Parent As Object [read only]
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • b4aCalibratorSensor.zip
    8.4 KB · Views: 237
  • b4aLibFiles.zip
    42.3 KB · Views: 240
Last edited:

Andris

Active Member
Licensed User
Longtime User
As soon as I add CalibratorSensor (1.00) to my project, I get the following compiler errors:

B4X:
B4A Version: 7.30
Parsing code.    (0.34s)
Compiling code.    (0.33s)
Compiling layouts code.    (0.06s)
Organizing libraries.    (0.00s)
Generating R file.    (0.25s)
Compiling generated Java code.    (4.49s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimatorRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/ArrayRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AttrRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BinderThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BoolRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/CallSuper;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:689)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:313)
    at com.android.dx.command.dexer.Main.run(Main.java:279)
    at com.android.dx.command.dexer.Main.main(Main.java:247)
    at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:681)
    ... 4 more

All I've done is add the library to my project by checking it in the Libraries tab and add the view in Designer. Any ideas?
 

Johan Schoeman

Expert
Licensed User
Longtime User
As soon as I add CalibratorSensor (1.00) to my project, I get the following compiler errors:

B4X:
B4A Version: 7.30
Parsing code.    (0.34s)
Compiling code.    (0.33s)
Compiling layouts code.    (0.06s)
Organizing libraries.    (0.00s)
Generating R file.    (0.25s)
Compiling generated Java code.    (4.49s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimatorRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/ArrayRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AttrRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BinderThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BoolRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/CallSuper;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:689)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:313)
    at com.android.dx.command.dexer.Main.run(Main.java:279)
    at com.android.dx.command.dexer.Main.main(Main.java:247)
    at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:681)
    ... 4 more

All I've done is add the library to my project by checking it in the Libraries tab and add the view in Designer. Any ideas?
Will look at it later today. Seems that some library that you are using already adds support annotations.
 

Johan Schoeman

Expert
Licensed User
Longtime User
As soon as I add CalibratorSensor (1.00) to my project, I get the following compiler errors:

B4X:
B4A Version: 7.30
Parsing code.    (0.34s)
Compiling code.    (0.33s)
Compiling layouts code.    (0.06s)
Organizing libraries.    (0.00s)
Generating R file.    (0.25s)
Compiling generated Java code.    (4.49s)
Convert byte code - optimized dex.    Error
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnimatorRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AnyThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/ArrayRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/AttrRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BinderThread;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/BoolRes;
Uncaught translation error: java.lang.IllegalArgumentException: already added: Landroid/support/annotation/CallSuper;
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Translation has been interrupted
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:689)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:313)
    at com.android.dx.command.dexer.Main.run(Main.java:279)
    at com.android.dx.command.dexer.Main.main(Main.java:247)
    at com.android.dx.command.Main.main(Main.java:106)
Caused by: java.lang.InterruptedException: Too many errors
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:681)
    ... 4 more

All I've done is add the library to my project by checking it in the Libraries tab and add the view in Designer. Any ideas?

See if the attached library files sort out the problem. It should show in the IDE as V1.01
 

Attachments

  • CalibratorSensor.xml
    9.1 KB · Views: 190
  • CalibratorSensor.jar
    32 KB · Views: 193
Top