@keirS the "abs" is totally different from Math.abs. So, I created a java libraray just for Math.abs

and imported it. But there is another way too, I think, the java.lang.math can be imported directly through objects.
Anyways, I found solution for my program.
Actually, I wanted to create an App that makes some bell sounds when the phone shakes. When the phone stops shaking, the bell sound stops. We are humans and we cannot provide exact shakings. So, I added some shaking corrections in the code. It means the code confirms the "non shake" mode when it received a minimum of two 0 values.
The basic algorithm I have written is here, I hope it is useful to somebody. Please enhance or fix any bugs if any one sees it,
Code:
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 myMaths As FirstLib
Dim MIN_FORCE As Int
Dim totalMovement As Int
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( 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
In the code, the MIN_FORCE stands for the distance you move the phone. 2 is minimum and sensitive. But If you add 5 or 10, it means the phone has to be shaken more distance.
Also, note that the myMaths.Myabs is my function written in library. There may be some other better ways to do it, But I am using it to get value,
Code:
totalMovement = myMaths.Myabs( X + Y + Z - lastX - lastY - lastZ )
Thank you,