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:drawing

Drawing demo

drawing.js
//drawing.js
var lastev = [];
lastev.action = "Up";
lastev.x = 0;
lastev.y = 0;
var img
  //Called when application is started. 
function OnStart()
{
  //Create a layout with objects vertically centered. 
  var lay = app.CreateLayout("Linear", "FillXY");
 
  //Create a blank image. 
  img = app.CreateImage(null, 0.8, 0.8);
  lay.AddChild(img);
  var btn = app.CreateButton("Save");
  btn.SetOnTouch(btn_OnTouch);
  lay.AddChild(btn);
  //Add layout to app.	 
  app.AddLayout(lay);
  //Draw blank picture. 
  DrawPicture();
}
 
function DrawPicture()
{
  //Fill image with solid white. 
  img.SetColor("#ffffffff");
  img.SetLineWidth(10);
  img.SetPaintStyle("Line");
  img.SetPaintColor("#ff8888ff");
  img.SetOnTouch(img_OnTouch);
}
 
function img_OnTouch(ev)
{
  app.Debug("=>" + ev.action + "<=");
  if (ev.action == "Up")
  {
 
  }
  else if (ev.action == "Down")
  {
    img.DrawPoint(ev.x[0], ev.y[0]);
  }
  else if (ev.action == "Move")
  {
    if (lastev.action != "Up")
    {
      img.DrawLine(lastev.x, lastev.y, ev.x[0], ev.y[0]);
    }
  }
  if (ev.action != "")
  {
    lastev.action = ev.action
    lastev.x = ev.x[0];
    lastev.y = ev.y[0]
  }
}
 
function btn_OnTouch()
{
  img.Save("/sdcard/temptest.jpg");
}
sample_code/drawing.txt · Last modified: 2014/12/06 21:07 by stevegarman