Sub Process_Globals
Dim LastX, LastY, LastZ As Float
Dim Accelorometer1 As PhoneAccelerometer
Dim Notification1 As Notification
Dim T As Timer
Dim TotSec As Int
Dim Phone As PhoneWakeState
Dim LastX, LastY, LastZ As Float
End Sub
Sub Service_Create
Log("SERVICE CREATE")
Notification1.Initialize
Notification1.Icon = "icon"
Notification1.Vibrate = True
End Sub
Sub Service_Start (StartingIntent As Intent)
LogColor ("Serv START",Colors.blue)
LastX = 0 : LastY = 0 : LastZ = 0
Accelorometer1.StartListening("Accelorometer1")
Notification1.SetInfo("StartActivityWithShake", "Shake the smartphone", Main)
Notification1.Sound = False
Service.StartForeground(1, Notification1)
If Not (T.IsInitialized) Then T.Initialize("T",1000)
T.Enabled=True
TotSec=0
Phone.PartialLock
'Phone.KeepAlive(True)
End Sub
Sub Service_TaskRemoved
End Sub
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
Return True
End Sub
Sub Service_Destroy
Log ("Serv DESTROY")
'Phone.ReleasePartialLock
'Phone.ReleaseKeepAlive
End Sub
Sub Accelorometer1_AccelerometerChanged(x As Float, y As Float, z As Float)
Dim deltaX, deltaY, deltaZ As Float
Dim Vector As Float
Dim Sensib As Float=20
deltaX = Abs(LastX - X)
deltaY = Abs(LastY - Y)
deltaZ = Abs(LastZ - Z)
If (deltaX < 0) Then deltaX = 0
If (deltaY < 0) Then deltaY = 0
If (deltaZ < 0) Then deltaZ = 0
LastX = X : LastY = Y : LastZ = Z
If (deltaX+deltaY+deltaX)> 0.5 Then
Vector=Sqrt(deltaX*deltaX+deltaY*deltaY+deltaZ*deltaZ)
If Vector>Sensib Then
Accelorometer1.StopListening
LastX=0 : LastY =0: LastZ=0
Log ("SHAKE " & NumberFormat(Vector,3,1) & " / " & Sensib)
StartActivity(Two)
Else
Log ("VECTOR=" & NumberFormat(Vector,3,1) & " < " & Sensib)
End If
End If
End Sub
Sub T_tick
TotSec=TotSec+1
End Sub