This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
sample_code:get_device_specs [2015/01/17 20:39] stevegarman created |
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 osObj = allBuilds[app.GetOSVersion()] |
- | function OnStart() | + | try |
{ | { | ||
- | //Create a layout with objects vertically centered. | + | var osInfo = " |
- | lay = app.CreateLayout( " | + | osObj.codename + " |
+ | osObj.level | ||
+ | } | ||
+ | catch(err) | ||
+ | { | ||
+ | var osInfo = app.GetOSVersion(); | ||
+ | } | ||
+ | var txt; | ||
+ | //Called when application is started. | ||
+ | function OnStart() | ||
+ | { | ||
+ | //Lock orientation | ||
+ | app.SetOrientation( app.GetOrientation() ); | ||
+ | //Create a layout with objects vertically centered. | ||
+ | var lay = app.CreateLayout(" | ||
+ | lay.SetBackColor("# | ||
+ | |||
+ | // create viewr for specs | ||
+ | scroll = app.CreateScroller(1, | ||
+ | var specs = getDeviceSpecs(); | ||
+ | txt = app.CreateText(specs, | ||
+ | txt.SetPadding(0.1); | ||
+ | txt.SetTextColor("# | ||
+ | scroll.AddChild(txt); | ||
+ | lay.AddChild(scroll); | ||
+ | |||
+ | //Create a button and add it to layout. | ||
+ | var btn = app.CreateButton(" | ||
+ | btn.SetTextColor("# | ||
+ | btn.SetStyle("# | ||
+ | |||
+ | btn.SetOnTouch(btn_OnTouch); | ||
+ | lay.AddChild(btn); | ||
- | //Create a button and add it to layout. | + | |
- | btn = app.CreateButton( " | + | app.AddLayout(lay); |
- | btn.SetOnTouch(btn_OnTouch); | + | |
- | lay.AddChild( btn ); | + | |
- | + | ||
- | // | + | |
- | 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 |
- | //Get screen dimensions. | + | var fromapk = (app.GetAppPath() == "/ |
- | var sw = app.GetScreenWidth(); | + | var dsversion = app.GetDSVersion() |
- | var sh = app.GetScreenHeight(); | + | |
- | var dens = app.GetScreenDensity(); | + | var sw = app.GetScreenWidth(); |
- | //Get display dimensions. | + | var sh = app.GetScreenHeight(); |
- | var dw = app.GetDisplayWidth(); | + | var dens = app.GetScreenDensity(); |
- | var dh = app.GetDisplayHeight(); | + | //Get display dimensions. |
+ | var dw = app.GetDisplayWidth(); | ||
+ | var dh = app.GetDisplayHeight(); | ||
+ | //Get drive details | ||
+ | var intfld = app.GetInternalFolder(); | ||
+ | var extfld = app.GetExternalFolder(); | ||
+ | var intspace = app.GetFreeSpace(" | ||
+ | var extspace = app.GetFreeSpace(" | ||
+ | var mem = app.GetMemoryInfo().total.toLocaleString(" | ||
- | //specs are formatted as a comment so we can paste | + | |
- | //them somewhere convenient | + | //them somewhere convenient |
- | var s = "/ | + | try |
- | " | + | { |
- | " | + | os = osInfo; |
- | "screen width="+ sw + " | + | } |
- | "screen height="+ sh + " | + | catch(err) |
- | "screen density="+ dens + " | + | {} |
- | "display width="+ dw + " | + | var s = "/*\n" + |
- | "display height="+ dh +" | + | "os=" + os + " |
- | return(s); | + | " |
+ | " | ||
+ | "DroidScript=" + dsversion | ||
+ | "screen width=" + sw + " | ||
+ | "screen height=" + sh + " | ||
+ | "screen density=" + dens + " | ||
+ | "display width=" + dw + "\n" + | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "int free space=" | ||
+ | "ext free space=" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "*/"; | ||
+ | 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. |