This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
sample_code:get_device_specs [2015/12/18 21:29] 176.146.90.10 [Sample code] |
sample_code:get_device_specs [2022/04/25 17:48] stevegarman [Sample code] updated |
||
---|---|---|---|
Line 8: | Line 8: | ||
<code JavaScript getDeviceSpecs.js> | <code JavaScript getDeviceSpecs.js> | ||
- | var allBuilds = JSON.parse(' | + | // https:// |
- | '" | + | var allBuilds |
- | '" | + | '" |
- | '" | + | '" |
- | '" | + | '" |
- | '" | + | '" |
- | '" | + | '" |
- | '" | + | '" |
- | ' | + | '" |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
- | ' | + | ' " |
+ | ' | ||
+ | | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' }'); | ||
- | 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) | + | |
- | { | + | |
- | var osInfo = app.GetOSVersion(); | + | |
} | } | ||
+ | catch(err){var osInfo = app.GetOSVersion(); | ||
- | //Called when application is started. | + | var lay, txt, scroller |
- | function OnStart() | + | //Called when application is started. |
+ | function OnStart() | ||
{ | { | ||
+ | /* | ||
+ | if(! app.GetNotifyId()) | ||
+ | { | ||
+ | var notify = app.CreateNotification( | ||
+ | notify.SetSmallImage( " | ||
+ | notify.SetLargeImage( " | ||
+ | notify.SetMessage( "", | ||
+ | notify.Notify( app.GetAppName() ); | ||
+ | } | ||
+ | */ | ||
+ | //Create a layout with objects vertically centered. | ||
+ | lay = app.CreateLayout(" | ||
+ | | ||
+ | // create viewr for specs | ||
+ | scroller = app.CreateScroller(1, | ||
+ | var specs = getDeviceSpecs(); | ||
+ | txt = app.CreateText(specs, | ||
+ | txt.SetPadding(0.02, | ||
+ | // | ||
+ | scroller.AddChild(txt); | ||
+ | lay.AddChild(scroller); | ||
- | //Create a layout with objects vertically centered. | + | |
- | var lay = app.CreateLayout( "linear", | + | var btn = app.CreateButton("[fa-copy]", -1, -1, "fontAwesome" |
+ | btn.SetTextSize( 32 ) | ||
+ | // | ||
+ | // | ||
- | // | + | |
- | var btn = app.CreateButton( " | + | lay.AddChild(btn); |
- | btn.SetOnTouch(btn_OnTouch); | + | |
- | lay.AddChild( btn ); | + | //Add layout to app. |
- | + | app.AddLayout(lay); | |
- | //Add layout to app. | + | OnConfig() |
- | app.AddLayout( lay ); | + | |
} | } | ||
- | function btn_OnTouch() | + | function btn_OnTouch() |
{ | { | ||
- | var tst = getDeviceSpecs(); | + | app.SetClipboardText(txt.GetText( ) ); |
- | app.Alert(tst); | + | app.ShowPopup(" |
- | app.SetClipboardText(tst); | + | } |
+ | |||
+ | function getBuilderVersion() | ||
+ | { | ||
+ | var msg = "Apk Builder plugin not installed"; | ||
+ | var path = app.GetPrivateFolder(" | ||
+ | "/ | ||
+ | | ||
+ | { | ||
+ | msg = "Apk Builder version " + app.ReadFile( path ) | ||
+ | } | ||
+ | else if(app.IsAPK()) | ||
+ | { | ||
+ | msg = "APK built with " + app.GetDSVersion().toFixed(2); | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | function | ||
+ | { | ||
+ | var os = app.GetOSVersion(); | ||
+ | var model = app.GetModel(); | ||
+ | var tablet = app.IsTablet(); | ||
+ | var fromapk = app.IsAPK(); | ||
+ | var isChrome = app.IsChrome(); | ||
+ | var isPrem = app.IsPremium() | ||
+ | var isTV = app.IsTV(); | ||
+ | var dsversion = app.GetDSVersion().toFixed(2); | ||
+ | //Get screen dimensions. | ||
+ | var sw = app.GetScreenWidth(); | ||
+ | var sh = app.GetScreenHeight(); | ||
+ | var dens = app.GetScreenDensity(); | ||
+ | //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 | ||
+ | try | ||
+ | { | ||
+ | os = osInfo; | ||
+ | } | ||
+ | catch(err) | ||
+ | {} | ||
+ | var s = "/ | ||
+ | " | ||
+ | getBuilderVersion() + " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | "int free space=" | ||
+ | "ext free space=" | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | return(s); | ||
+ | } | ||
+ | |||
+ | function storageScoped() { | ||
+ | | ||
} | } | ||
- | function getDeviceSpecs() | + | function OnConfig() |
{ | { | ||
- | var os =app.GetOSVersion(); | + | //called when screen rotates |
- | var model = app.GetModel(); | + | //also called at startup to fix Chromebook display size anomaly |
- | var tablet = app.IsTablet(); | + | var fixwid=lay.GetAbsWidth()/ |
- | var fromapk = ( app.GetAppPath() == " | + | var fixhigh=lay.GetAbsHeight()/app.GetDisplayHeight() |
- | var dsversion = app.GetDSVersion(); | + | var wid=1, high=0.8 |
- | //Get screen dimensions. | + | if(fixwid<1) wid *= fixwid |
- | var sw = app.GetScreenWidth(); | + | if(fixhigh< |
- | var sh = app.GetScreenHeight(); | + | |
- | var dens = app.GetScreenDensity(); | + | txt.SetSize( wid, high |
- | // | + | |
- | var dw = app.GetDisplayWidth(); | + | |
- | var dh = app.GetDisplayHeight(); | + | |
- | // | + | |
- | var intfld = app.GetInternalFolder(); | + | |
- | var extfld = app.GetExternalFolder(); | + | |
- | var intspace = app.GetFreeSpace(" | + | |
- | var extspace = app.GetFreeSpace(" | + | |
- | + | ||
- | //specs are formatted as a comment so we can paste | + | |
- | // | + | |
- | try {os=osInfo; | + | |
- | catch(err){} | + | |
- | var s = "/*\n"+ | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | 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. |