This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
plugins:stopwatch [2016/08/08 12:47] 202.8.246.29 created |
plugins:stopwatch [2016/08/08 21:18] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Stopwatch Plugin ====== | ====== Stopwatch Plugin ====== | ||
- | This is a my private plugin i used for checking code execution time between functions/ | + | This is a my private plugin i used for checking code execution time between functions/ |
//After DroidScript is executed, the plugin will appear in the plugin menu and it's documentation will be accessible.// | //After DroidScript is executed, the plugin will appear in the plugin menu and it's documentation will be accessible.// | ||
Line 9: | Line 9: | ||
Nelson Tengkiat (dated: Aug 8, 2016) | Nelson Tengkiat (dated: Aug 8, 2016) | ||
+ | =====Usage of the Example===== | ||
+ | ====First Step:==== | ||
+ | Since i don't have enough rights to post the ZIP file. You simply need to download all the files need to build this plugin yourself by zipping the file. | ||
+ | |||
+ | Download the following 4 Files: | ||
+ | |||
+ | * **File 1: The html-page for the Documentation** | ||
+ | |||
+ | <code html Stopwatch.html> | ||
+ | < | ||
+ | < | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <meta name=" | ||
+ | </ | ||
+ | <!-- /use   as tabs as space --> | ||
+ | |||
+ | < | ||
+ | |||
+ | <div data-role=" | ||
+ | |||
+ | <div data-role=" | ||
+ | <a href='#' | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | <div data-role=" | ||
+ | < | ||
+ | the plugin at the top of your script using the < | ||
+ | like this:</ | ||
+ | |||
+ | <div class=" | ||
+ | <div id=" | ||
+ | // Load the Stopwatch plugin< | ||
+ | app.LoadPlugin( " | ||
+ | | ||
+ | <div name=" | ||
+ | <a href="#" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | |||
+ | <div class=" | ||
+ | <div id=" | ||
+ | & | ||
+ | <div name=" | ||
+ | <a href="#" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | You can get the plugin version by calling < | ||
+ | toast display the version by calling < | ||
+ | < | ||
+ | < | ||
+ | < | ||
+ | <div data-role=" | ||
+ | < | ||
+ | < | ||
+ | & | ||
+ | </ | ||
+ | <div data-role=" | ||
+ | < | ||
+ | < | ||
+ | & | ||
+ | </ | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <div data-role=" | ||
+ | < | ||
+ | <div id=" | ||
+ | app.LoadPlugin(" | ||
+ | < | ||
+ | function OnStart( ) {<br> | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | function btnGetVer( ) {<br> | ||
+ | <b id=" | ||
+ | & | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | function btnShowVer( ) {<br> | ||
+ | & | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | function btnExit( ) { app.Exit( ); }<br> | ||
+ | </ | ||
+ | <div name=" | ||
+ | <a href="#" | ||
+ | <a href="#" | ||
+ | <a href="#" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | when an action is complete a < | ||
+ | < | ||
+ | To compare the time passed between two points of time. | ||
+ | The < | ||
+ | that provides time accuracy to the milliseconds.< | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | <div data-role=" | ||
+ | < | ||
+ | <div id=" | ||
+ | app.LoadPlugin(" | ||
+ | < | ||
+ | // | ||
+ | function OnStart( ) {<br> | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | // start the clock< | ||
+ | function StartClock( ) {<br> | ||
+ | & | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | // stop the clock< | ||
+ | function StopClock( ) {<br> | ||
+ | & | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | // exit the app< | ||
+ | function Exit( ) {<br> | ||
+ | & | ||
+ | }< | ||
+ | < | ||
+ | </ | ||
+ | <div name=" | ||
+ | <a href="#" | ||
+ | <a href="#" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | <div data-role=" | ||
+ | < | ||
+ | < | ||
+ | & | ||
+ | </ | ||
+ | <div data-role=" | ||
+ | < | ||
+ | < | ||
+ | & | ||
+ | </ | ||
+ | <div data-role=" | ||
+ | < | ||
+ | < | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | < | ||
+ | & | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | use in your projects. <b> A credit line if used would be nice : | ||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | |||
+ | </ | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | * **File 2: The inc-file with the Plugin-code (Javascript)** | ||
+ | |||
+ | <code Javascript Stopwatch.inc> | ||
+ | /* | ||
+ | |||
+ | Stopwatch Library | ||
+ | Code Author by: Nelson Tengkiat | ||
+ | |||
+ | Stopwatch version history | ||
+ | 1.00 dated: pre 2016 | ||
+ | - initial code not yet plugin | ||
+ | 1.10 dated: jan 25, 2016 | ||
+ | - initial creation of plugin | ||
+ | - not release to public | ||
+ | - added GetVersion(), | ||
+ | - added int addZero(i); | ||
+ | - added pub Help(), Start(), Stop(), Time(option) | ||
+ | 1.11 dated: jan 30, 2016 | ||
+ | - added help function | ||
+ | - edited stopwatch example program | ||
+ | 1.12 dated: jan 31, 2016 | ||
+ | - edited stopwatch example program | ||
+ | - initialize stopwatch value to 0 | ||
+ | |||
+ | todo: add laps | ||
+ | |||
+ | */ | ||
+ | |||
+ | |||
+ | // ****************************** | ||
+ | // * Library Creation | ||
+ | // ****************************** | ||
+ | // stopwatch script | ||
+ | app.CreateStopwatch = function() { return new sWatch();} | ||
+ | |||
+ | |||
+ | // ****************************** | ||
+ | // * Stopwatch functions | ||
+ | // ****************************** | ||
+ | // show time difference on the stopwatch | ||
+ | // option - milli (for accuracy) | ||
+ | function sWatch() { | ||
+ | // | ||
+ | |||
+ | // ****************************** | ||
+ | // * global vars | ||
+ | // ****************************** | ||
+ | // stopwatch global var | ||
+ | var o_sw = { | ||
+ | // code version | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | |||
+ | var shelp= | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | ' | ||
+ | |||
+ | |||
+ | // ****************************** | ||
+ | // * Get / Show version | ||
+ | // ****************************** | ||
+ | // return the version number | ||
+ | this.GetVersion = function () { return o_sw.ver } | ||
+ | |||
+ | // show version on screen | ||
+ | this.ShowVersion = function () { | ||
+ | ss=' | ||
+ | app.ShowPopup(ss,' | ||
+ | } | ||
+ | |||
+ | |||
+ | // ****************************** | ||
+ | // * Internal functions | ||
+ | // ****************************** | ||
+ | |||
+ | // pad zero in front if less than 2 char | ||
+ | addZero = function (i) { | ||
+ | if (i < 10) { i = " | ||
+ | return i | ||
+ | } // function addZero(i) | ||
+ | |||
+ | // ****************************** | ||
+ | // * Public functions | ||
+ | // ****************************** | ||
+ | | ||
+ | // give the help screen | ||
+ | this.Help = function () { alert(shelp); | ||
+ | |||
+ | // start the stopwatch. save ticks | ||
+ | this.Start = function () { | ||
+ | app.SetDebugEnabled(false); | ||
+ | o_sw.start=new Date().getTime(); | ||
+ | app.SetDebugEnabled(true); | ||
+ | } | ||
+ | |||
+ | // stop the stopwatch | ||
+ | this.Stop = function () { | ||
+ | app.SetDebugEnabled(false); | ||
+ | o_sw.stop=new Date().getTime(); | ||
+ | o_sw.time=o_sw.stop-o_sw.start; | ||
+ | app.SetDebugEnabled(true); | ||
+ | } | ||
+ | |||
+ | // show time difference on the stopwatch | ||
+ | // option - milli (for accuracy) | ||
+ | this.Time = function (option) { | ||
+ | app.SetDebugEnabled(false); | ||
+ | var days=hrs=mins=secs=milli=0; | ||
+ | var str=""; | ||
+ | var lap=o_sw.time; | ||
+ | |||
+ | // days | ||
+ | tmp=lap/ | ||
+ | days=Math.floor(tmp); | ||
+ | lap-=days*86400000; | ||
+ | if (days!=" | ||
+ | |||
+ | // hours | ||
+ | tmp=lap/ | ||
+ | hrs=addZero(Math.floor(tmp)); | ||
+ | lap-=hrs*3600000; | ||
+ | if (hrs!=" | ||
+ | |||
+ | // minutes | ||
+ | tmp=lap/ | ||
+ | mins=addZero(Math.floor(tmp)); | ||
+ | lap-=mins*60000; | ||
+ | if (mins!=" | ||
+ | |||
+ | // seconds | ||
+ | tmp=lap/ | ||
+ | secs=addZero(Math.floor(tmp)); | ||
+ | lap-=secs*1000; | ||
+ | if (secs!=" | ||
+ | |||
+ | // make sure millisecs is 3 digits | ||
+ | milli=lap.toString(); | ||
+ | while (milli.length< | ||
+ | // add string of units | ||
+ | switch (unt) { | ||
+ | case 0: str=milli+" | ||
+ | case 1: | ||
+ | if (option==" | ||
+ | else str=secs+" | ||
+ | break; | ||
+ | case 2: | ||
+ | if (option==" | ||
+ | else str=mins+":" | ||
+ | break; | ||
+ | case 3: | ||
+ | if (option==" | ||
+ | else str=hrs+" | ||
+ | break; | ||
+ | case 4: | ||
+ | if (option==" | ||
+ | else str=days+" | ||
+ | break; | ||
+ | } | ||
+ | // | ||
+ | return str; | ||
+ | } // Time (option) | ||
+ | // | ||
+ | } // sWatch() | ||
+ | </ | ||
+ | |||
+ | * **File 3: The text-file with the Version number** | ||
+ | |||
+ | <code text Version.txt> | ||
+ | 1.12 | ||
+ | </ | ||
+ | |||
+ | * **File 4: A blank jar-file without any text** | ||
+ | |||
+ | <code Java Stopwatch.jar> | ||
+ | |||
+ | </ | ||
+ | |||
+ | ====Second Step:==== | ||
+ | |||
+ | Create a Zip-folder called " | ||
+ | |||
+ | * Select the 4 Files and use a tool on a Windows Desktop-PC like [[http:// | ||
+ | * after this process you should have a file with the following structure: | ||
+ | |||
+ | Stopwatch.zip | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | * Now you go on your Android Device to the folder **/ | ||
+ | * Copy the zip-file in this folder and start Droidscript | ||
+ | * DroidScript imports the Plugin now in the Droidscript-Pluginfolder in the system path | ||
+ | * Now you can see your plugin if you press the left " | ||
+ | * The folder **/ | ||
+ | |||
+ | =====How can you uninstall your plugin? | ||
+ | |||
+ | This is a copy of the uninstall program from a different section of this wiki site. | ||
+ | |||
+ | <code javascript UninstallPlugin.js> | ||
+ | |||
+ | //Called when application is started. | ||
+ | function OnStart() | ||
+ | { | ||
+ | //Create a layout with objects vertically centered. | ||
+ | lay = app.CreateLayout( " | ||
+ | |||
+ | //Create a text label and add it to layout. | ||
+ | txt = app.CreateTextEdit( "" | ||
+ | txt.SetHint(" | ||
+ | lay.AddChild( txt ); | ||
+ | |||
+ | btn=app.CreateButton(" | ||
+ | btn.SetOnTouch(DeleteUserPlugin); | ||
+ | lay.AddChild(btn); | ||
+ | | ||
+ | privFldr = app.GetPrivateFolder( " | ||
+ | plgins = app.ListFolder(privFldr); | ||
+ | |||
+ | lvw = app.CreateListView( plgins, " | ||
+ | lvw.SetOnTouch( lvw_OnTouch ); | ||
+ | |||
+ | //Add layout to app. | ||
+ | app.AddLayout( lay ); | ||
+ | } | ||
+ | |||
+ | |||
+ | function lvw_OnTouch( item ) | ||
+ | { | ||
+ | txt.SetText( item ); | ||
+ | } | ||
+ | |||
+ | |||
+ | function DeleteUserPlugin() | ||
+ | { | ||
+ | var plg = "" | ||
+ | if (plg == "" | ||
+ | plugDir = privFldr + "/" | ||
+ | if (app.FolderExists(plugDir)) | ||
+ | { | ||
+ | var list = app.ListFolder(plugDir); | ||
+ | var yesNo = app.CreateYesNoDialog( "Do you really want to uninstall the plugin " + txt.GetText() + "? \nThe following files or folders will be all deleted: | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | |||
+ | function yesNo_OnTouch( yesNoresult ) | ||
+ | { | ||
+ | if( yesNoresult == " | ||
+ | { | ||
+ | app.DeleteFolder(plugDir); | ||
+ | | ||
+ | app.Alert(" | ||
+ | txt.SetText("" | ||
+ | } | ||
+ | else | ||
+ | { | ||
+ | app.ShowPopup(" | ||
+ | } | ||
+ | } | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ---- | ||