An app with a Time Picker can be as simple as this
app.LoadPlugin( "UIExtras" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
uix = app.CreateUIExtras();
picker = uix.CreateTimePicker();
picker.SetOnTimeChanged( OnTimeChanged );
lay.AddChild (picker );
app.AddLayout( lay );
}
function OnTimeChanged( hour, minute )
{
app.ShowPopup( hour + ":" + minute);
}
This is how to call a Date Picker Dialog
app.LoadPlugin( "UIExtras" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
btn = app.CreateButton( "Pick Date", 0.3, 0.1 );
btn.SetOnTouch( btn_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );
uix = app.CreateUIExtras();
}
function btn_OnTouch()
{
picker = uix.CreateDatePickerDialog( "Pick a Date" );
picker.SetOnOk( picker_OnOk );
picker.Show();
}
function picker_OnOk( year, month, day )
{
var date = new Date();
date.setFullYear( year, month, day);
app.ShowPopup( date.toDateString() );
}
And this builds a whole floating action menu.
app.LoadPlugin( "UIExtras" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "FillXY" );
lay.SetBackground( "/Sys/Img/GreenBack.png" );
app.AddLayout( lay );
uix = app.CreateUIExtras();
layFam = app.CreateLayout( "Linear", "FillXY, Bottom, Right, TouchThrough" );
fam = uix.CreateFAMenu( "[fa-envelope-o]", "Up,LabelsLeft" );
fam.SetMargins( 0.02, 0.01, 0.02, 0.01 );
fam.SetLabelBackColor( "#FFFFFF" );
fam.SetLabelTextColor( "#646464" );
fam.SetOnOpened( fam_OnOpened );
fam.SetOnClosed( fam_OnClosed );
layFam.AddChild( fam );
fabReply = uix.CreateFAButton( "[fa-reply]", "Mini" );
fabReply.SetButtonColors( "#db4437", "#c33d32" );
fabReply.SetOnTouch( fab_OnMailReply );
fabReply.SetLabel( "Reply" );
fam.AddFAButton( fabReply );
fabReplyAll = uix.CreateFAButton( "[fa-reply-all]", "Mini" );
fabReplyAll.SetButtonColors( "#db4437", "#c33d32" );
fabReplyAll.SetOnTouch( fab_OnMailReplyAll );
fabReplyAll.SetLabel( "Reply All" );
fam.AddFAButton( fabReplyAll );
fabForward = uix.CreateFAButton( "[fa-share]", "Mini" );
fabForward.SetButtonColors( "#fbbc05", "#efb306" );
fabForward.SetOnTouch( fab_OnMailForward );
fabForward.SetLabel( "Forward" );
fam.AddFAButton( fabForward );
app.AddLayout( layFam );
}
function fam_OnOpened()
{
layFam.SetBackColor( "#99FFFFFF" );
}
function fam_OnClosed()
{
layFam.SetBackColor( "#00FFFFFF" );
}
function fab_OnMailReply()
{
app.ShowPopup( "Reply" );
}
function fab_OnMailReplyAll()
{
app.ShowPopup( "Reply All" );
}
function fab_OnMailForward()
{
app.ShowPopup( "Forward" );
}
app.LoadPlugin( "BarcodeReader" );
function OnStart()
{
app.SetOrientation( "Landscape" );
lay = app.CreateLayout( "Linear", "FillXY" );
reader = app.CreateObject( "BarcodeReader" );
cam = app.CreateCameraView( 0.8, 1, "VGA, UseYUV" );
cam.SetOnReady( cam_OnReady );
lay.AddChild( cam );
app.AddLayout( lay );
}
function cam_OnReady()
{
cam.StartPreview();
cam.SetFocusMode( "macro" );
DecodeFromCamera();
}
function DecodeFromCamera()
{
var result = reader.Decode( cam );
if( result != null )
{
app.ShowPopup( result.barcodeType + ": " + result.content );
}
setTimeout( DecodeFromCamera, 200 );
}
app.LoadPlugin( "BarcodeReader" );
//Called when application is started.
function OnStart()
{
//Fix orientation to landscape.
app.SetOrientation( "Landscape" );
//Stop screen turning off.
app.PreventScreenLock( true );
//Create a layout to fill the screen.
lay = app.CreateLayout( "Absolute", "FillXY" );
//Create the barcode reader.
reader = app.CreateObject( "BarcodeReader" );
//Create camera view control
//(UseYUV is required for use with BarcodeReader)
cam = app.CreateCameraView( 0.8, 1.0, "VGA, UseYUV" );
cam.SetPosition( 0.1, 0 );
cam.SetOnReady( cam_OnReady );
lay.AddChild( cam );
//Add main layout to app.
app.AddLayout( lay );
}
//Called when camera is ready.
function cam_OnReady()
{
//Create an image control over the top of the
//camera view with transparency (alpha) so
//we can show a framed area.
img = app.CreateImage( null, 1.0, 1.0 );
img.SetAlpha( 0.5 );
lay.AddChild( img );
img.SetPaintColor( "#ff0000" );
img.SetPaintStyle( "Line" );
img.SetLineWidth( 2.5 );
img.DrawRectangle( 0.2, 0.2, 0.8, 0.8 );
//Create a layout for instruction text
//and flash checkbox.
overlay = app.CreateLayout( "Linear", "FillXY" );
lay.AddChild(overlay);
//Create the instruction text.
txt = app.CreateText( "Position a barcode in the frame to read it" );
txt.SetMargins( 0,0.05,0,0 );
txt.SetPadding( 0.01,0,0.01,0 );
txt.SetTextColor( "#ffffff" );
txt.SetBackColor( "#44000000" );
txt.SetTextSize( 18 );
overlay.AddChild( txt );
//Create Use Flash check box.
chkFlash = app.CreateCheckBox( "Use Flash" );
chkFlash.SetMargins( 0,0.75,0,0 );
chkFlash.SetPadding( 0.01,0,0.01,0 );
chkFlash.SetTextColor( "#ffffff" );
chkFlash.SetBackColor( "#44000000" );
chkFlash.SetTextSize( 18 );
chkFlash.SetOnTouch( chkFlash_OnTouch );
overlay.AddChild( chkFlash );
//Start preview.
cam.StartPreview();
//Macro focus mode works best for
//reading barcodes.
cam.SetFocusMode( "macro" );
//Start decoding the camera preview.
DecodeFromCamera();
}
//Handle Use Flash checkbox touch
function chkFlash_OnTouch( value )
{
cam.SetFlash( value );
}
function DecodeFromCamera()
{
//Attempt to detect a barcode in the
//camera preview.
var result = reader.Decode( cam );
//If result is not null, a barcode
//was detected.
if( result != null )
{
//Vibrate and show result dialog.
app.Vibrate( "0,100,30,100,50,300" );
ShowResult( result );
}
else
{
//Decode again in 200 milliseconds.
setTimeout( DecodeFromCamera, 200 );
}
}
function ShowResult( result )
{
//Create dialog window.
resultDlg = app.CreateDialog( result.barcodeType, "NoCancel" );
//Create a layout for dialog.
layDlg = app.CreateLayout( "Linear", "Vertical, FillXY" );
layDlg.SetPadding( 0.02, 0, 0.02, 0.02 );
resultDlg.AddLayout( layDlg );
//Create text for the content type name.
txtDlg = app.CreateText( result.contentType );
txtDlg.SetTextSize( 22 );
txtDlg.SetTextColor( "#0099CC" );
layDlg.AddChild( txtDlg );
//Create a scroller for the content.
scrDlg = app.CreateScroller( 0.4, 0.45 );
scrDlg.SetMargins( 0, 0.01, 0, 0 );
layDlg.AddChild( scrDlg );
//Create text for the content.
txtDlg = app.CreateText( result.content, 0.4, -1, "Multiline" );
txtDlg.SetTextSize( 18 );
scrDlg.AddChild( txtDlg );
//Create an Ok button to dismiss the dialog.
btnDlg = app.CreateButton( "Ok" );
btnDlg.SetOnTouch( resultDlg_OnOk );
layDlg.AddChild( btnDlg );
//Show dialog.
resultDlg.Show();
}
//Called when the result dialog Ok button is pressed
function resultDlg_OnOk()
{
resultDlg.Dismiss();
//Start decoding again.
DecodeFromCamera();
}
app.LoadPlugin( "OcrScanner" );
var scanRect = {
left: 0.25,
top: 0.35,
right: 0.75,
bottom: 0.65
};
var ocr = null;
var cam = null;
var overlayImg = null;
var lightOn = false;
function OnStart()
{
app.SetOrientation( "Landscape" );
var lay = app.CreateLayout( "linear", "VCenter,FillXY" );
cam = app.CreateCameraView( 1.0, 1.0, "UseYUV,XGA" );
cam.SetOnReady( cam_OnReady );
lay.AddChild( cam );
app.AddLayout( lay );
var overlay = app.CreateLayout( "Absolute", "FillXY" );
overlayImg = app.CreateImage(null, 1, 1);
overlay.AddChild(overlayImg);
var msg = "Position text in the frame and press [fa-camera] to scan";
var txt = app.CreateText( msg, 1.0, -1, "FontAwesome");
txt.SetTextSize( 18 );
txt.SetPosition( 0, 0.2 );
overlay.AddChild(txt);
var lightBtn = app.CreateButton( "[fa-bolt]", 0.1, -1, "FontAwesome" );
lightBtn.SetTextSize(28);
lightBtn.SetOnTouch( lightBtn_OnTouch );
overlay.AddChild( lightBtn );
var scanBtn = app.CreateButton( "[fa-camera]", 0.1, -1, "FontAwesome" );
scanBtn.SetTextSize(28);
scanBtn.SetOnTouch( scanBtn_OnTouch );
scanBtn.SetPosition(0.9, 0);
overlay.AddChild( scanBtn );
app.AddLayout( overlay );
ocr = app.CreateOCR();
ocr.SetOnResult(ocr_OnResult);
ocr.SetOnProgress(ocr_OnProgress);
ocr.SetScanRect(scanRect.left, scanRect.top,
scanRect.right, scanRect.bottom);
DrawScanRect();
}
function cam_OnReady()
{
cam.StartPreview();
}
function DrawScanRect()
{
overlayImg.SetPaintColor( "#FFFF0000" );
overlayImg.SetLineWidth( 2.0 );
overlayImg.SetPaintStyle( "Line" );
overlayImg.DrawRectangle(scanRect.left, scanRect.top,
scanRect.right, scanRect.bottom);
}
function ocr_OnResult( ocrResult )
{
app.HideProgressBar();
if( ocrResult.text != "" )
{
app.ShowPopup( ocrResult.text );
}
else
{
app.ShowPopup( "OCR Failed" );
}
}
function ocr_OnProgress( progress )
{
app.UpdateProgressBar( progress );
}
function scanBtn_OnTouch()
{
app.ShowProgressBar( "Scanning...", 0 );
ocr.Scan( cam );
}
function lightBtn_OnTouch()
{
lightOn = !lightOn;
cam.SetFlash( lightOn );
}
app.LoadPlugin( "ImageGrid";
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
var files = app.ListFolder( "/sdcard/DCIM/Camera", ".jpg", 1000, "FullPath" );
grid = app.CreateImageGrid( files, 1,1, 3,5 );
grid.SetOnTouch( grid_OnTouch );
grid.SetOnLongTouch( grid_OnLongTouch );
lay.AddChild( grid );
app.AddLayout( lay );
}
function grid_OnTouch( fileName )
{
alert( fileName );
}
function grid_OnLongTouch( fileName )
{
alert( fileName );
}
app.LoadPlugin( "ImageGrid" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
var files = app.ListFolder( "/sdcard/DCIM/Camera", ".jpg", 1000, "FullPath" );
grid = app.CreateImageGrid( files, 1,0.7, 3,5 );
lay.AddChild( grid );
btn = app.CreateButton( "Remove", 0.3 );
btn.SetOnTouch( btnRemove_OnTouch );
lay.AddChild( btn );
app.AddLayout( lay );
}
function btnRemove_OnTouch()
{
grid.RemoveItemByIndex( 0 );
}
app.LoadPlugin( "ImageGrid" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
grid = app.CreateImageGrid( "", 0.9,0.9, 1,2 );
lay.AddChild( grid );
app.AddLayout( lay );
media = app.CreateMediaStore();
media.SetOnAlbumsResult( media_OnAlbumsResult );
media.QueryAlbums( "", "", "external" );
}
function media_OnAlbumsResult( result )
{
s = "";
for( var i=0; i<result.length; i++ )
{
if( result[i].albumArt!="null" )
s += (i>0?",":"") + result[i].albumArt;
}
grid.SetList( s, "," );
}
app.LoadPlugin( "ImageGrid" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
var files = app.ListFolder( "/Assets/Img", ".png", 0, "FullPath" );
grid = app.CreateImageGrid( files, 1,1, 5,7 );
lay.AddChild( grid );
app.AddLayout( lay );
}
app.LoadPlugin( "ImageGrid" );
function OnStart()
{
lay = app.CreateLayout( "Linear", "VCenter,FillXY" );
var files =
[
"http://androidscript.org/Plugins/img/BarcodeReader.png",
"http://androidscript.org/Plugins/img/GoProController.png",
"http://androidscript.org/Plugins/img/Moga.png",
"http://androidscript.org/Plugins/img/NXT.png",
"http://androidscript.org/Plugins/img/PluginApk.png",
"http://androidscript.org/Plugins/img/SpheroBall.png",
];
grid = app.CreateImageGrid( files, 1,1, 3,6, -1, "fit" );
lay.AddChild( grid );
app.AddLayout( lay );
}