app show popup time help

247 views
Skip to first unread message

Manuel Lopes

unread,
Mar 6, 2016, 6:14:22 PM3/6/16
to DroidScript
i read i can make short time "short" in app.ShowPopup but is possible i put my time replace the word "short" and put my time in number example 1000,2000, .......or other?i mean my time in value (the time to show the popup?or not work?thanks

example short of droidscript i want replace this by my time:

function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );

img = app.CreateImage( "/Sys/Img/Droid1.png" );
img.SetOnTouch( img_OnTouch );
lay.AddChild( img );

app.AddLayout( lay );
}

function img_OnTouch( ev )
{
if( ev.action=="Down" )
app.ShowPopup( "Ouch!","short");


}

Steve Garman

unread,
Mar 6, 2016, 11:53:15 PM3/6/16
to DroidScript
DroidScript appears to use the Android toast for app.ShowPopup.
The toast is not very versatile when it comes to timing but it is very useful in other ways, especially that it can so easily be used in background services.

If I want something like app.ShowPopup in my conventional app, I sometimes use my own myPopup function.

A simplified version of it is pasted below. You will probably want to customise it to improve its appearance.

var popup;
function OnStart()
{
var lay = app.CreateLayout( "linear", "VCenter,FillXY" );
var btn = app.CreateButton( "Test" );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );

myPopup("Hello\nWorld",500)
}
function btn_OnTouch()
{
var msg = (new Date).toTimeString();
myPopup(msg,5000);
}
function myPopup(text,time)
{
if(!popup)
{
popup = app.CreateLayout( "Linear","top,center,touchThrough" );
popup.SetSize( 1,1 );
popup.SetBackColor( "#00000000" );
popup.SetPadding( 0,0.1,0,0 );
popup.txt = app.CreateText( "",-1,-1,"multiline" );
popup.txt.SetBackColor( "#888888" );
popup.txt.SetPadding( 0.01, 0.01, 0.01, 0.01 );
popup.tim = null;
popup.SetVisibility( "hide" );
popup.AddChild( popup.txt );
}
clearTimeout(popup.tim);
app.RemoveLayout( popup );
popup.txt.SetText( text );
popup.SetVisibility( "show" );
app.AddLayout( popup );
popup.tim=setTimeout('popup.SetVisibility( "hide" );', time)
}

Steve Garman

unread,
Mar 7, 2016, 1:39:07 AM3/7/16
to DroidScript
//Here's a version of the function I had lying around that can be made a bit prettier.

var popup;
function OnStart()
{
var lay = app.CreateLayout( "linear", "VCenter,FillXY" );

//lay.SetBackColor( "#226622" );
var btn = app.CreateButton( "Test",-1,-1,"custom" );


btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );

myPopup("Hello\nWorld",500)
}
function btn_OnTouch()
{
var msg = (new Date).toTimeString();
myPopup(msg,5000);
}
function myPopup(text,time)
{
if(!popup)
{
popup = app.CreateLayout( "Linear","top,center,touchThrough" );
popup.SetSize( 1,1 );
popup.SetBackColor( "#00000000" );
popup.SetPadding( 0,0.1,0,0 );

popup.txt = app.CreateButton( "",-1,-1,"custom" );
popup.txt.SetStyle( "#8888ff88","#8888ff88",null,null,null,0);


popup.tim = null;
popup.SetVisibility( "hide" );
popup.AddChild( popup.txt );
}
clearTimeout(popup.tim);
app.RemoveLayout( popup );
popup.txt.SetText( text );
popup.SetVisibility( "show" );
app.AddLayout( popup );

popup.tim=setTimeout('popup.Animate( "fadeOut",500 );', time)
}

Manuel Lopes

unread,
Mar 7, 2016, 7:32:39 AM3/7/16
to DroidScript
very thanks steve;this example is very cool good work

Manuel Lopes

unread,
Mar 7, 2016, 5:52:45 PM3/7/16
to DroidScript
where i get the popup.Animate?

Steve Garman

unread,
Mar 7, 2016, 10:10:02 PM3/7/16
to DroidScript
Manuel,
popup.Animate should just work although 'fadeOut' is new in the latest version of DroidScript.

If it does not work for you, what version of DroidScript are you using and what version of Android?


Message has been deleted

Steve Garman

unread,
Mar 8, 2016, 5:29:44 AM3/8/16
to DroidScript
Deleted post suggesting animation was not working on Jellybean.

This was a mistake on my part.

Manuel Lopes

unread,
Mar 8, 2016, 7:29:56 AM3/8/16
to DroidScript
but i not see in the documentation ;i have the last droidscript;thanks
Reply all
Reply to author
Forward
0 new messages