Page 1 of 1

cordova-plugin-shake

Posted: Wed Mar 21, 2018 3:29 pm
by falsam
Practice with Cordova : Shake gesture detection.

■ Platform
Android
iOS ?

■ Documentation https://www.npmjs.com/package/cordova-plugin-shake

Code: Select all

EnableExplicit

Enumeration
  #mf
EndEnumeration

Declare Start()
Declare InitShake(SuccessCallback, Sensitivity = 30)
Declare onSuccess()

;Import Cordova Plugin
Import "cordova plugin add cordova-plugin-shake"
EndImport

Start()

Procedure Start()  
  OpenWindow(#mf, 0, 0, 0, 0, "Shake your phone", #PB_Window_Background)
  InitShake(@onSuccess(), 8)  
EndProcedure

Procedure InitShake(SuccessCallback, Sensitivity = 30)
  !shake.startWatch(v_successcallback, v_sensitivity)    
EndProcedure

Procedure onSuccess() 
  Debug "Shake : New dice " + Random(6,1)
EndProcedure

If you need to stop detection, use this procedure

Code: Select all

Procedure StopShake()
  !shake.stopWatch()
EndProcedure
I don't know if it works for iOS

Re: cordova-plugin-shake

Posted: Fri Mar 23, 2018 8:01 am
by Dirk Geppert
Good to know. I could use that soon. Thank you, Falsam.