shake event too speed

stefanoa

Active Member
Licensed User
Longtime User
i'm trying to use shake event in my app with code from your example http://www.b4x.com/forum/basic4android-getting-started-tutorials/9857-android-shake-event-phonesensors.html#post54631
but the event "Shaked" is released too speed and not wait for 1.5 seconds configured in TimeThreshold on shake module:
B4X:
Sub Process_Globals
   Dim tw As TextWriter
   Dim recording As Boolean
   Type AxisData (flipCount As Int, lastPeak As Float,lastValue As Float, timeStamp As Long)
   Dim AxisX As AxisData
   Dim MagnitudeThreshold As Float
   Dim TimeThreshold As Int
   MagnitudeThreshold = 11
   TimeThreshold = 1500 'milliseconds <<<<<<<<<<<<<<<<<<<<
   Dim CallBackActivity As String
End Sub
B4X:
Sub Shaked
   PlayRandom
End Sub

how can i wait for "n" seconds between a "shaked" event and another?
thanks
 
Last edited:

mc73

Well-Known Member
Licensed User
Longtime User
I think that you can set a timer running inside the Shaked sub. Then, when this sub is recalled, you can check whether this timer is running and exit. Set the timer to stop its action when 'n' seconds passed by checking the system time.

PS: I know nothing about this module, so forgive me if it already includes this type of things.
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
ok.. i try..
although, it should work the parameter TimeThreshold for this purpose...
thanks for now..
 
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
in log not appear "Shake.CalcAxis - still waiting"...

the shake event is released repeatedly and not every 1.5 sec...

i have in activity_create:
B4X:
sensor.Initialize(sensor.TYPE_ACCELEROMETER)
Shake.CallBackActivity = "BrowseAudioVideo"  '<< form name

in chechbox to activate shaking:
B4X:
Sub ShakeCheckBox_CheckedChange(Checked As Boolean)
   Activated=Checked
   If Activated=True Then
      sensor.StartListening("sensor") 
      Accelorometer.StartListening("Accelorometer")
      LastUpdate=DateTime.Now
   Else
      Accelorometer.StopListening
      sensor.StopListening
   End If

End Sub

in shake event:
B4X:
Sub Shaked
   Msgbox("SHAKED!!!!!","")
   '---PlayRandom
End Sub

and then i have the code module "shake.bas" (as your example) with TimeThreshold = 1500 'milliseconds
 
Last edited:
Upvote 0

stefanoa

Active Member
Licensed User
Longtime User
yes!
also if i remove msgbox and put:
B4X:
Sub ShakeEvent
    Activity.Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
    sounds.Play(bounceId, 1, 1, 1, 0, 1)
End Sub

is too speed and not wait for 1.5 seconds..
 
Upvote 0
Top