// ************************************************** // *    Author: Nelson Tengkiat // * Code Date: Sun, Dec 13, 2015 // ************************************************** // Sample OnStart() code // global var to save. confirm. compare. var mypin=""; var verify_mypin=""; //Called when application is started. function OnStart() {     //Create a layout with objects vertically centered.     lay = app.CreateLayout( "linear", "VCenter,FillXY" );         //Create a text label and add it to layout.     txt = app.CreateText( "PIN CODE test" );     txt.SetTextSize( 32 );     lay.AddChild( txt );          //Add layout to app.         app.AddLayout( lay );     // call our function. confirm. compare both.     alert ("Enter Your 6 digit PIN Code");     EnableGetPincode();     PinCode(6,"Enter PIN Code");     // want to see this "notitle" option ?     // comment out the above PinCode function call //    PinCode(6,"6 digit PIN Code","notitle"); } // called if user completed entry on pin code. function pincodeComplete () {     if (mypin==""){         mypin=GetPincodeSecret(); //        alert("PIN Code entered was: "+mypin);         PinCode(6,"Confirm your 6 digit PIN Code");     }     if (mypin>"") {          verify_mypin=GetPincodeSecret();         if ((mypin>"") && (verify_mypin>"")){ //            alert("Confirm PIN Code entered was: "+verify_mypin);             if (mypin==verify_mypin)                 alert("PIN Code match\n"+"Code entered was: "+mypin);             else                 alert("No match. Different PIN Codes \n"+"1st Pincode: "+mypin+"\n2nd Pincode: "+verify_mypin);             app.Exit();         }     } } // ************************************************** // * Delete above or comment out to be able to be used // * as app.LoadScript("PincodeFuncs.js"); // ************************************************** /* Dated : Dec 13, 2015 Collection of  Make seperate test program code to test functions here to avoid accidental deletion of this code. // ************************************************** // *    Author: Nelson Tengkiat // * Code Date: Sun, Dec 13, 2015 // ************************************************** // Load my user defined functions app.LoadScript("PincodeFuncs.js");     // getting pin code or app.LoadScript("/sdcard/DroidScript/FuncsLibrary/PincodeFuncs.js");   // getting pin code List of functions in this collection  // pincode length size. dialog msg (ei. getting, resetting, confirming) function PinCode(size,diamsg,option) // button press. do something function btn_pincode () // output the secret code as string function GetPincodeSecret () // enable sound or silent pincode entry function pincodeSound (snd) // enable user to handle something after competion of pincode function EnableGetPincode () // user must create this function to handle pincode secret after completion function pincodeComplete () */ // ************************************************** // * Global vars // ************************************************** // pincode position, length, display, userget function, secret code, pin code in one object var obj_pincode = {"pos":1, "len":0, "disp":false, "sound": true, "userget":false, "secret":"", "pin":[]}; var button = app.CreateMediaPlayer();     button.SetFile("Snd/button_click.mp3"); // ************************************************** // * List of functions // ************************************************** // pincode length size. dialog msg (ei. getting, resetting, confirming) function PinCode(size,diamsg,option) {     var ar_pinBtn = [];          // minimum pincode length should be 4     // maximum pincode length can be 15     // larger than that it goes off the screen on a 5" phone     if ((size<4) || (size>15)) {         alert("Minimum PIN Code length should be 4, Maximum can be up to 15");         return;     }          // reset entries when this is called. dont reset the sound     obj_pincode.pos=0;        // reset to start pos     obj_pincode.len=size;   // size of secret code     obj_pincode.disp=false;   // dont display the secret     obj_pincode.secret="";  // reset the secret code     obj_pincode.pin=[];     // reset the pin code     //Create dialog window.     if (option=="notitle")          dlgTxt = app.CreateDialog( diamsg,"nocancel,notitle" );     else         dlgTxt = app.CreateDialog( diamsg,"nocancel" );          //Create a layout for dialog.     layV_pc = app.CreateLayout( "linear", "vertical,fillxy,left" );     dlgTxt.AddLayout( layV_pc );     // show the pincode entry     if (option=="notitle") {         txt0 = app.CreateText( " PIN CODE ",0.6,-1,"fillx,center");         txt0.SetTextSize(20);         txt0.SetTextColor("#FFFFFFFF");         txt0.SetBackColor("#FF3B85FF");         txt0.SetPadding(0.05,0,0.05,0);         layV_pc.AddChild(txt0);     }     // show the pincode entry     ss="";     for (i=0; i0)                 obj_pincode.pos--;             obj_pincode.pin[obj_pincode.pos]="-";             break;     }     // display the pin code or display secret     var ss="";     if (obj_pincode.disp) {         for (i=0; i