'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim GPS1 As GPS
Dim cntRotate As Int
Dim TSloc As Location
Dim OldLoc As Location
Dim NPloc As Location
Dim GPSbearing As Float
Dim Compassbearing As Float
Dim Compass As PhoneSensors
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.
Dim imgView As ImageView
Dim bmpDirectionArrow As Bitmap
Dim bmpExtended As BitmapExtended
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
NPloc.Initialize2( "90:00:00", "00:00:00") 'North Pole
TSloc = NPloc
OldLoc.Initialize
bmpExtended.Initialize("BitmapExtended")
GPS1.Initialize("GPS")
Compass.Initialize(Compass.TYPE_ORIENTATION)
End If
Activity.LoadLayout("Main")
bmpDirectionArrow.Initialize(File.DirAssets,"direction_arrow.png") '300 x 172 pix
imgView.Bitmap=bmpDirectionArrow
End Sub
Sub Activity_Resume
If GPS1.GPSEnabled = False Then
ToastMessageShow("Please enable the GPS device.", True)
StartActivity(GPS1.LocationSettingsIntent)
Else
GPS1.Start(0,0)
End If
Compass.StartListening("Orientation")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
'GPS1.Stop
Compass.StopListening
End Sub
Sub GPS_LocationChanged (Loc As Location)
Dim degrees As Float
OldLoc = Loc
If GPSbearing <> Loc.BearingTo(TSloc) Then
GPSbearing = Loc.BearingTo(TSloc)
degrees = (GPSbearing - Compassbearing)
'Canvas1.DrawBitmap(Bitmap1, Null, Rect1)
'Canvas1.DrawBitmapRotated(imgArrow, Null, Rect1, degrees)
imgView.Bitmap = bmpExtended.rotateBitmap(bmpDirectionArrow, degrees)
Activity.Invalidate()
End If
End Sub
Sub Orientation_SensorChanged(Values() As Float)
Dim degrees As Float, x As Int
x = ((2880 + Values(0) * 4) Mod 2880) - 1440
If Compassbearing <> x/4.0 Then
Compassbearing = x/4.0
degrees = GPSbearing + Compassbearing
imgView.Bitmap = bmpExtended.rotateBitmap(bmpDirectionArrow, degrees)
Activity.Invalidate()
End If
End Sub
Sub GPS_UserEnabled (Enabled As Boolean)
ToastMessageShow("GPS device enabled = " & Enabled, True)
End Sub
Sub imgView_Click
Dim dgrs As Int
cntRotate = cntRotate + 1
If cntRotate = 37 Then
cntRotate = 1
End If
dgrs = cntRotate * 10
imgView.Bitmap = bmpExtended.rotateBitmap(bmpDirectionArrow, dgrs)
End Sub