DroidScript : Timer02

Timer01 had the orientation fixed to landscape. And for a reason: the screen layout needed a lot of horizontal space. So I created another app that favours any orientation. Timer02 can be used in both landscape and in portrait orientation. And this resulted in an observation I hadn't expected, but is not too strange, considering smartphones are mere toys and Android a toy operating system.

Below are some screenshots of the new Timer02 script.

This is the by now familiar DroidScript screen where the apps live happily among eachother. Short touch to launch, long touch to copy, move or create a shortcut so it shows on the desktop.

I started the app while holding the Droidscript main screen upright, in portrait mode. All fields are spaced as specified in the script.

Now I turn the screen from portrait mode to landscape mode. The screen contents move in a corresponding way. But the fields are not resized... In the middle of the screen the app takes up the portraitmode space. In the bottom, only barely enough space is around to harbour the full screen.
Yes, this is a toy with a toy operating system.

When a specific timer starts, the timers name, legend, caption, whatever you name it, gets a green background. So it is easy to spot the active channel. When the timer is running with seconds delays, you can see the digits change but in minutes mode, the timer changes only once per minute. Too long an attention focus for most smartphone users.

When you press the "Reset" button with running timers, this popup appears to inform you about it. First stop the timers before resetting.

Now I have started the app with the main DroidScript screen in landscape mode. Nicely spaced buttons and text fields.

And on the right a crowded view is the result when rotating the screen from landscape into portrait mode. Each line is filled in from the left. The right most button is shrunk to the available space. The text is still readable (run) or broken (reset).

Another observation:

  1. I start the counter
  2. The counters run at the normal pace
  3. I switch the counter to the background (press the middle 'home' button
  4. After some time I get the counter to the foreground again and it has been running as expected.
  5. I switch it to the background again
  6. I put the device to sleep
  7. After half an hour I wake up the phone and check the counters
  8. The counters have not advanced since step 6
Android is a toy operating system to power toys. It is based on Linux but that's just about it. It's a phrase by Google to earn respect among professionals, but Android is more a graphical shell around DOS than an equivalent of Gnome, KDE or XFCE. If you need a series of smartphones to build your company upon, thinks again. It's money thrown out the window.

Timer02 : the source

The User Interface part is very different from Timer01, but the programming section is very similar to the previous version. There are just so many means of getting a job done in a scientific way. Below is the source:

var timers = [0,0,0,0,0];
var running = 0;
var delay = 60000;
var ts = 18;                // textsize  
var bw = 0.25, bh = 0.1;    // Button width, height
var Cact = "#003300", 
    Cpas = "#000000";       // Colours

function OnStart ()
    Screen = app.CreateLayout ("Linear", "Vertical, fillx");
    // Create top menu bar
    layTop = app.CreateLayout ("Linear", "Horizontal");
    tex1 = app.CreateText ("Loop", bw, bh);
    tex1.SetTextSize (ts);
    tex2 = app.CreateText ("Start", bw, bh);
    tex2.SetTextSize (ts);
    tex3 = app.CreateText ("Time", bw, bh);
    tex3.SetTextSize (ts);
    layTop.AddChild (tex1);
    layTop.AddChild (tex3);
    layTop.AddChild (tex2);
    // Create timer1 bar
    layT1 = app.CreateLayout ("Linear", "Horizontal");
    loop1 = app.CreateTextEdit ("", bw, bh);
    loop1.SetTextSize (ts);
    loop1.SetHint ("Loop 1");
    start1 = app.CreateButton("Run", bw, bh);
    start1.SetTextSize (ts);
    start1.SetOnTouch (run1);
    time1 = app.CreateText ("0:00", bw, bh);
    time1.SetTextSize (ts);
    // Create timer2 bar
    layT2 = app.CreateLayout ("Linear", "Horizontal");
    loop2 = app.CreateTextEdit ("", bw, bh);
    loop2.SetTextSize (ts);
    loop2.SetHint ("Loop 2");
    start2 = app.CreateButton("Run", bw, bh);
    start2.SetTextSize (ts);
    start2.SetOnTouch (run2);
    time2 = app.CreateText ("0:00", bw, bh);
    time2.SetTextSize (ts);
    layT2.AddChild (loop2);
    layT2.AddChild (time2);
    layT2.AddChild (start2);

    // Create timer3 bar
    layT3 = app.CreateLayout ("Linear", "Horizontal");
    loop3 = app.CreateTextEdit ("", bw, bh);
    loop3.SetTextSize (ts);
    loop3.SetHint ("Loop 3");
    start3 = app.CreateButton("Run", bw, bh);
    start3.SetTextSize (ts);
    start3.SetOnTouch (run3);
    time3 = app.CreateText ("0:00", bw, bh);
    time3.SetTextSize (ts);
    layT3.AddChild (loop3);
    layT3.AddChild (time3);
    layT3.AddChild (start3);
    // Create timer4 bar
    layT4 = app.CreateLayout ("Linear", "Horizontal");
    loop4 = app.CreateTextEdit ("", bw, bh);
    loop4.SetTextSize (ts);
    loop4.SetHint ("Loop 4");
    start4 = app.CreateButton("Run", bw, bh);
    start4.SetTextSize (ts);
    start4.SetOnTouch (run4);
    time4 = app.CreateText ("0:00", bw, bh);
    time4.SetTextSize (ts);
    layT4.AddChild (loop4);
    layT4.AddChild (time4);
    layT4.AddChild (start4);
    //Create control bar
    layCtrl = app.CreateLayout ("Linear", "Horizontal");
    Stop = app.CreateButton ("Stop", bw, bh);
    Stop.SetTextSize (ts);
    Stop.SetOnTouch (stopTimer);
    Stop.SetBackColor ("#00FFFF");
    Stop.SetTextColor ("#000000");
    Total = app.CreateText ("0:00", bw, bh);
    Total.SetTextSize (ts);
    Reset = app.CreateButton ("Reset", bw, bh);
    Reset.SetTextSize (ts);
    Reset.SetOnTouch (resetTimer);
    Reset.SetBackColor ("#FF0000");
    Reset.SetTextColor ("#FFFF00");
    layCtrl.AddChild (Stop);
    layCtrl.AddChild (Total);
    layCtrl.AddChild (Reset);
    // Create screen
    Screen.AddChild (layTop);
    Screen.AddChild (layT1);
    Screen.AddChild (layT2);
    Screen.AddChild (layT3);
    Screen.AddChild (layT4);
    Screen.AddChild (layCtrl);
    app.AddLayout (Screen);

function Tshow (obj, t0)
    var u, m, str;
    str = " ";				// make sure 'str' is a string
    u = Math.floor (t0 / 60);		// u = t0 DIV 60
    m = t0 % 60;		        // m = t0 MOD 60
    str += u;			    	// print data to the string
    str += ":";
    if (m < 10) str += "0";
    str += m;
    obj.SetText (str);			// print the string in the object

function display (arr)
    Tshow (time1, arr [1]);
    Tshow (time2, arr [2]);
    Tshow (time3, arr [3]);
    Tshow (time4, arr [4]);
    Tshow (Total, arr [0]);

function resetTimer ()
    var i;
    if (running > 0) 
        app.ShowPopup ("Timer loopt, reset kan niet");
    for (i=0; i<5; i++) timers [i] = 0;
    running = 0;
    display (timers);

function stopTimer ()
    running = 0;
    ResetBgC ();

function startTimer (n)
    if (running == 0) setTimeout (tick, delay);
    running = n;

function tick ()
    var n;
    if (running > 0) 
        timers [running]++; 		// increment current timer
        timers [0]++;		    	// increment total timer
        setTimeout (tick, delay);	// reset the downcounter
    display (timers);

function ResetBgC ()

function run1 ()
    ResetBgC ();
    startTimer (1);

function run2 ()
    ResetBgC ();
    startTimer (2);

function run3 ()
    ResetBgC ();
    startTimer (3);

function run4 ()
    ResetBgC ();
    startTimer (4);
Main differences: You can download the SPK file here: Timer02.spk but it needs the DroidScript runtime. Just get it from the Google playstore. It is free of charge and it is reliable.

Page created September 15, 2016 and