This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Last revision Both sides next revision | ||
sample_code:get_device_specs [2015/04/06 07:33] stevegarman [Sample code] fix standalone |
sample_code:get_device_specs [2017/11/26 03:46] 127.0.0.1 external edit |
||
---|---|---|---|
Line 8: | Line 8: | ||
<code JavaScript getDeviceSpecs.js> | <code JavaScript getDeviceSpecs.js> | ||
+ | var allBuilds = JSON.parse(' | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | '" | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' }'); | ||
- | var allBuilds = JSON.parse(' | + | var osObj = allBuilds[app.GetOSVersion()] |
- | '" | + | |
- | '" | + | |
- | '" | + | |
- | '" | + | |
- | '" | + | |
- | '" | + | |
- | '" | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | ' | + | |
- | + | ||
- | var osObj = allBuilds[app.GetOSVersion()] | + | |
try | try | ||
{ | { | ||
- | var osInfo = "Android " | + | var osInfo |
- | osObj.codename + " | + | osObj.codename |
- | osObj.level | + | osObj.level |
} | } | ||
catch(err) | catch(err) | ||
{ | { | ||
- | var osInfo = app.GetOSVersion(); | + | var osInfo |
} | } | ||
- | + | var txt; | |
- | //Called when application is started. | + | //Called when application is started. |
- | function OnStart() | + | function OnStart() |
{ | { | ||
+ | //Lock orientation | ||
+ | app.SetOrientation( app.GetOrientation() ); | ||
+ | //Create a layout with objects vertically centered. | ||
+ | var lay = app.CreateLayout(" | ||
+ | lay.SetBackColor("# | ||
- | //Create a layout with objects vertically centered. | + | |
- | lay = app.CreateLayout( " | + | scroll = app.CreateScroller(1, |
+ | var specs = getDeviceSpecs(); | ||
+ | txt = app.CreateText(specs, 1, 0.9, "left,multiLine"); | ||
+ | txt.SetPadding(0.1); | ||
+ | txt.SetTextColor("# | ||
+ | scroll.AddChild(txt); | ||
+ | lay.AddChild(scroll); | ||
- | //Create a button and add it to layout. | + | |
- | btn = app.CreateButton( " | + | var btn = app.CreateButton(" |
- | btn.SetOnTouch(btn_OnTouch); | + | |
- | lay.AddChild( btn ); | + | btn.SetStyle("# |
- | + | ||
- | //Add layout to app. | + | |
- | app.AddLayout( lay ); | + | lay.AddChild(btn); |
+ | |||
+ | //Add layout to app. | ||
+ | app.AddLayout(lay); | ||
} | } | ||
- | function btn_OnTouch() | + | function btn_OnTouch() |
{ | { | ||
- | var tst = getDeviceSpecs(); | + | app.SetClipboardText(txt.GetText( ) ); |
- | app.Alert(tst); | + | // flash |
- | app.SetClipboardText(tst); | + | txt.SetBackColor( "# |
+ | | ||
+ | txt.SetBackColor( "# | ||
+ | ,100); | ||
} | } | ||
- | function getDeviceSpecs() | + | function getDeviceSpecs() |
{ | { | ||
- | var os =app.GetOSVersion(); | + | var os = app.GetOSVersion(); |
- | var model = app.GetModel(); | + | var model = app.GetModel(); |
- | var tablet = app.IsTablet(); | + | var tablet |
- | var fromapk = ( app.GetAppPath() == "/ | + | var fromapk |
- | var dsversion = (fromapk?" | + | var dsversion |
- | //Get screen dimensions. | + | //Get screen dimensions. |
- | var sw = app.GetScreenWidth(); | + | var sw = app.GetScreenWidth(); |
- | var sh = app.GetScreenHeight(); | + | var sh = app.GetScreenHeight(); |
- | var dens = app.GetScreenDensity(); | + | var dens = app.GetScreenDensity(); |
- | //Get display dimensions. | + | //Get display dimensions. |
- | var dw = app.GetDisplayWidth(); | + | var dw = app.GetDisplayWidth(); |
- | var dh = app.GetDisplayHeight(); | + | var dh = app.GetDisplayHeight(); |
- | //Get drive details | + | //Get drive details |
- | var intfld = app.GetInternalFolder(); | + | var intfld |
- | var extfld = app.GetExternalFolder(); | + | var extfld |
- | var intspace = app.GetFreeSpace(" | + | var intspace |
- | var extspace = app.GetFreeSpace(" | + | var extspace |
- | + | var mem = app.GetMemoryInfo().total.toLocaleString(" | |
- | //specs are formatted as a comment so we can paste | + | |
- | //them somewhere convenient | + | //them somewhere convenient |
- | try {os=osInfo; | + | try |
- | catch(err){} | + | |
- | var s = "/ | + | |
- | " | + | |
- | " | + | catch(err) |
- | " | + | |
- | " | + | var s = "/ |
- | "screen width="+ sw + " | + | " |
- | "screen height="+ sh + " | + | " |
- | "screen density="+ dens + " | + | " |
- | "display width="+ dw + " | + | " |
- | "display height="+ dh +" | + | "screen width=" + sw + " |
- | "internal folder=" | + | "screen height=" + sh + " |
- | "external folder=" | + | "screen density=" + dens + " |
- | "int free space=" | + | "display width=" + dw + " |
- | "ext free space=" | + | "display height=" + dh + " |
- | "country code=" | + | "internal folder=" + intfld |
- | " | + | "external folder=" + extfld |
- | "language code=" | + | "int free space=" + intspace |
- | " | + | "ext free space=" + extspace |
- | " | + | "memory=" |
- | return(s); | + | " |
+ | " | ||
+ | "language code=" + app.GetLanguageCode() + " | ||
+ | " | ||
+ | " | ||
+ | | ||
+ | return(s); | ||
} | } | ||
- | |||
</ | </ | ||
===== Notes ===== | ===== Notes ===== | ||
The function getDeviceSpecs at the end of the code, can be pasted independently into a project an the string returned can be used however you see fit. | The function getDeviceSpecs at the end of the code, can be pasted independently into a project an the string returned can be used however you see fit. |