B4A Library CompassView

The attached project wraps this Github project. The library files are in the /files folder of the attached B4A project. Copy them to your additional library folder. Also posting the Java code. You will also need to enable the Phone library in the B4A project. Move your device in different directions and see the compasses changing accordingly.


1.png




compassview
Author:
Johan Schoeman
Version: 1
  • CompassView
    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)
    Properties:
    • Background As Drawable
    • Color As Int [write only]
    • CompassBackgroundColor As Int [write only]
    • CompassDegrees As Float [write only]
    • CompassLineColor As Int [write only]
    • CompassMarkerColor As Int [write only]
    • CompassRangeDegrees As Float [write only]
    • CompassShowMarker As Boolean [write only]
    • CompassTextColor As Int [write only]
    • CompassTextSize As Int [write only]
    • Enabled As Boolean
    • Height As Int
    • Left As Int
    • Tag As Object
    • Top As Int
    • Visible As Boolean
    • Width As Int
 

Attachments

  • JavaCode.zip
    27.8 KB · Views: 811
  • b4aCompassView.zip
    31.1 KB · Views: 815

Johan Schoeman

Expert
Licensed User
Longtime User
Thank you very much. I´m still at work but as soon i´m at home i´ll try it out.

https://github.com/Kr0oked/Compass this is a App from the devicemanufacturer. As far i know it uses
Sensor.TYPE_ROTATION_VECTOR and Sensor.TYPE_MAGNETIC_FIELD (looks like GPS?)

In the meantime i can say more about the other Compassview above, https://www.b4x.com/android/forum/threads/compassview-another-compassview.93977/#content,
i tried this and it does not update the view when rotating the Device.
Maybe this one requires location permission that was not required before....Will have to check

 

Johan Schoeman

Expert
Licensed User
Longtime User
I´ll test with GPS Permissions later today too ;-)

This one runs on my Android 16 device as is when downloading it from the B4A posting (allowing an OLD version of Android to be installed) and also when I change the Manifest to 34. Needles are working perfectly in both cases.

Manifest changed to 34:
'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="34"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

It uses:
Java Imports:
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
 
Last edited:
Top