DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


Sidebar

News

Version1.42 is out since December 2nd 2016


Frequently Asked Questions


Namespaces

Note for contributors

If you wish to create a new page in the DroidScript wiki, please click on the most appropriate namespace above and follow the notes for contributors there.

Because of spam, it has been necessary to add a CAPTCHA to the registration form and the save option for editing pages. You will not need to prove you are human if you are logged in, so please register.

Please feel free to improve any existing page, as well as adding new pages to increase the sum of public knowledge about DroidScript.

Formatting Syntax

sample_code:shake

Shake

This sample offers an OnShake function using the accelerometer.

OnShake.js
var lastx,lasty,lastz,lastms
function OnStart()
{
  var lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
  var txt = app.CreateText( "Shake test" );
  lay.AddChild( txt );
  app.AddLayout( lay );
 
  var sns = app.CreateSensor( "Accelerometer" );
  sns.SetOnChange( sns_OnChange );
  sns.Start();
}
 
function sns_OnChange( x, y, z, time )
{
  try
  {
     var diffms,speed;
     if(lastx!==undefined)
     {
       diffms=time-lastms;
       speed = Math.abs(x+y+z-lastx-lasty-lastz) / diffms * 10000; 
       if(speed>800) OnShake(speed/800);
     }
     lastx=x;
     lasty=y;
     lastz=z;
     lastms=time;
  }
  catch(e) {}
}
 
function OnShake(speed)
{
   var msg = "Shake\n"+speed.toFixed(2);
   app.ShowPopup(msg,"Short");
}
sample_code/shake.txt · Last modified: 2015/11/15 10:56 by stevegarman