Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Accelerometer As PhoneAccelerometer
Dim lastX As Float
Dim lastY As Float
Dim lastZ As Float
Dim MIN_FORCE As Int
Dim totalMovement As Int
Dim jo As JavaObject
jo.InitializeStatic("java.lang.Math")
Dim shakingCorrection As Int
End Sub
Sub Globals
MIN_FORCE = 2
End Sub
Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub Accelerometer_AccelerometerChanged (X As Float, Y As Float, Z As Float)
'totalMovement = myMaths.Myabs( )
totalMovement = jo.RunMethod("abs", Array As Object( X + Y + Z - lastX - lastY - lastZ))
If (totalMovement > MIN_FORCE) Then
Log("shaking")
'do all things here when you wanted the phone to shake
'reset shaking correction
shakingCorrection = 0
Else
shakingCorrection = shakingCorrection + 1
If shakingCorrection > 2 Then
Log("not shaking, do not do anything")
shakingCorrection = 0
End If
End If
'Assign new values
lastX = X
lastY = Y
lastZ = Z
End Sub
Sub Activity_Resume
Accelerometer.StartListening("Accelerometer")
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Accelerometer.StopListening
End Sub