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: 806
  • b4aCompassView.zip
    31.1 KB · Views: 807

Johan Schoeman

Expert
Licensed User
Longtime User

Johan Schoeman

Expert
Licensed User
Longtime User
I would be very happy to use some of your libraries in my app. Where can I donate ?
Hey guys i think it's right to make a small donation to colleagues as @Johan Schoeman ,@DonManfred, etc. It is very fair because they give us many beautiful libraries.
I wait your notice Johan.
Thank you again for your great work
I am doing this purely for the fun of it @MarcoRome. You can use whatever you want (of what I have posted) in your apps. No need to donate anything. My "payment" is the satisfaction of seeing it "work"....;)
 

Harris

Expert
Licensed User
Longtime User
Just a note:

You do not need a device that supports phone sensors (PhoneOrientation - as my tablets do not).

I use it with GPS.
compass1.CompassDegrees = Location1.Bearing

This works perfectly well - setting the compass to show your current heading.

Thanks for this wrap.
 

DonManfred

Expert
Licensed User
Longtime User
Hello @Johan Schoeman
a customer of mine is using this Compassview and also this one https://www.b4x.com/android/forum/threads/compassview-another-compassview.93977/#content

On a new Device of my Customer with android 14 both libraries does not update the view when rotating the device.

With this lib here the Compass-bar (if i can name it like this) doesn´t scrolle left or right when rotating the Device.

On the other lib the compass does not rotate when rotating the device.

The Device is on its way to me and will arrive next week.

Do you have an idea what i can check on this Device what the problem may be? Any hint would be higly welcome.

Bes regards, Manfred
 

Johan Schoeman

Expert
Licensed User
Longtime User
Hello @Johan Schoeman
a customer of mine is using this Compassview and also this one https://www.b4x.com/android/forum/threads/compassview-another-compassview.93977/#content

On a new Device of my Customer with android 14 both libraries does not update the view when rotating the device.

With this lib here the Compass-bar (if i can name it like this) doesn´t scrolle left or right when rotating the Device.

On the other lib the compass does not rotate when rotating the device.

The Device is on its way to me and will arrive next week.

Do you have an idea what i can check on this Device what the problem may be? Any hint would be higly welcome.

Bes regards, Manfred
Wow @DonManfred - a very old lib indeed and will have to try it on my Android 15 device to see what is happening.....could it maybe be related to one of the numerous changes related to permissions? I should still have the original library code on my 2010 laptop and will have to dig it out if there are changes to be made if possible at all to make it work from where I left it in 2015.
 

DonManfred

Expert
Licensed User
Longtime User
.could it maybe be related to one of the numerous changes related to permissions?
What is it what the lib depends on? GPS? Phone sensors?

Would be great if you find some time.

I´ll start digging too if i have this device here to do some tests on it.
 

Johan Schoeman

Expert
Licensed User
Longtime User
What is it what the lib depends on? GPS? Phone sensors?

Would be great if you find some time.

I´ll start digging too if i have this device here to do some tests on it.
It does work om my Android 15 device !

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

    Private compass1, compass2, compass3 As CompassView
    Dim ps As PhoneOrientation
   
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")
   
    compass1.Initialize("")
    compass2.Initialize("")
    compass3.Initialize("")  
   
    Activity.AddView(compass1, 10%x, 10%y, 50%x, 20%y)
    Activity.AddView(compass2, 25%x, 40%y, 50%x, 20%y)
    Activity.AddView(compass3, 40%x, 70%y, 50%x, 20%y)
   
    compass1.CompassLineColor = Colors.Green
    compass1.CompassBackgroundColor = Colors.DarkGray
    compass1.CompassMarkerColor = Colors.Cyan
    compass1.CompassRangeDegrees = 360
    compass1.CompassShowMarker = True
    compass1.CompassTextColor = Colors.Yellow
    compass1.CompassTextSize = 15
   
    compass2.CompassLineColor = Colors.Cyan
    compass2.CompassBackgroundColor = Colors.LightGray
    compass2.CompassMarkerColor = Colors.Green
    compass2.CompassRangeDegrees = 360
    compass2.CompassShowMarker = True
    compass2.CompassTextColor = Colors.Blue
    compass2.CompassTextSize = 20
   
    compass3.CompassLineColor = Colors.Black
    compass3.CompassBackgroundColor = Colors.ARGB(100,255,255,255)
    compass3.CompassMarkerColor = Colors.Red
    compass3.CompassRangeDegrees = 360
    compass3.CompassShowMarker = True
    compass3.CompassTextColor = Colors.Yellow
    compass3.CompassTextSize = 25  

End Sub

Sub Activity_Resume

ps.StartListening("ps")

End Sub

Sub Activity_Pause (UserClosed As Boolean)

ps.StopListening

End Sub
Sub ps_OrientationChanged (Azimuth As Float, Pitch As Float, Roll As Float)

compass1.CompassDegrees = Azimuth
compass2.CompassDegrees = Azimuth
compass3.CompassDegrees = Azimuth

End Sub

Manifest:
'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: http://www.basic4ppc.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$")
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
'End of default text.

It uses the PhoneOrientation class of the default B4A Phone library.
 
Last edited:
Top