DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:extra_keys

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

sample_code:extra_keys [2014/09/21 10:19]
81.174.242.106 created
sample_code:extra_keys [2014/12/06 20:56]
stevegarman change curly brace style
Line 8: Line 8:
 var gEdt; var gEdt;
 //Called when application is started. //Called when application is started.
-function OnStart(){ +function OnStart() 
-    //Create a layout with objects vertically centered. +
-    lay = app.CreateLayout( "​linear",​ "​Vcenter,​FillXY"​ );    +  //Create a layout with objects vertically centered. 
 +  lay = app.CreateLayout("​linear",​ "​Vcenter,​FillXY"​);​
  
-    ​//Create a text edit and add it to layout. +  ​//Create a text edit and add it to layout. 
-    edt = app.CreateTextEdit( "​Hello"​ ); +  edt = app.CreateTextEdit("​Hello"​);​ 
-    edt.SetTextSize( 32 ); +  edt.SetTextSize(32);​ 
-    lay.AddChild( edt ); +  lay.AddChild(edt);​ 
-    //Create a checkbox for overstrike mode +  //Create a checkbox for overstrike mode 
-    chkOvertype = app.CreateCheckBox("​Overtype"​);​ +  chkOvertype = app.CreateCheckBox("​Overtype"​);​ 
-    lay.AddChild(chkOvertype);​ +  lay.AddChild(chkOvertype);​ 
-    //create a horizontal layout for special characters +  //create a horizontal layout for special characters 
-    lay_keys = app.CreateLayout("​linear","​Horizontal,​FillY"​);​ +  lay_keys = app.CreateLayout("​linear",​ "​Horizontal,​FillY"​);​ 
-    btns = [] +  btns = [] 
-    var ks = '​{}[]();#"'​ + "'"​ +  var ks = '​{}[]();#"'​ + "'"​ 
-    for(i=0; i<​ks.length;​ i++){ +  for (i = 0; i < ks.length; i++) 
-      var ch = ks.charAt(i);​ +  ​
-      btn = app.CreateButton(ch);​ +    var ch = ks.charAt(i);​ 
-      btn.SetOnTouch(btn_OnTouch);​ +    btn = app.CreateButton(ch);​ 
-      lay_keys.AddChild(btn);​ +    btn.SetOnTouch(btn_OnTouch);​ 
-      btns.push(btn);​ +    lay_keys.AddChild(btn);​ 
-    +    btns.push(btn);​ 
-    lay.AddChild(lay_keys);​ +  
-     +  lay.AddChild(lay_keys);​ 
-    //Add layout to app.     + 
-    app.AddLayout( lay ); +  //Add layout to app.     
-    gEdt = edt;+  app.AddLayout(lay);​ 
 +  gEdt = edt;
 } }
  
-function btn_OnTouch(){ +function btn_OnTouch() 
-    var s = this.GetText();​ +
-    var pos = gEdt.GetCursorPos();​ +  var s = this.GetText();​ 
-    var theEnd = gEdt.GetText().length;​ +  var pos = gEdt.GetCursorPos();​ 
-    if(! chkOvertype.GetChecked()){ +  var theEnd = gEdt.GetText().length;​ 
-      gEdt.InsertText(s,​ pos); +  if (!chkOvertype.GetChecked()) 
-    } else{ +  ​
-      gEdt.ReplaceText(s,​ pos, Math.min(pos+s.length,​ theEnd)); +    gEdt.InsertText(s,​ pos); 
-      gEdt.SetCursorPos(pos + s.length);​ +  } 
-    }+  ​else 
 +  ​
 +    gEdt.ReplaceText(s,​ pos, Math.min(pos + s.length, theEnd)); 
 +    gEdt.SetCursorPos(pos + s.length);​ 
 +  }
 } }
 </​code>​ </​code>​
sample_code/extra_keys.txt · Last modified: 2014/12/06 20:56 by stevegarman