This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
sample_code:get_device_specs [2015/01/17 20:39] stevegarman created |
sample_code:get_device_specs [2022/04/25 17:48] (current) stevegarman [Sample code] updated |
||
---|---|---|---|
Line 8: | Line 8: | ||
<code JavaScript getDeviceSpecs.js> | <code JavaScript getDeviceSpecs.js> | ||
+ | // https:// | ||
+ | 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 lay, txt, scroller | ||
+ | //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 button and add it to layout. | ||
+ | var btn = app.CreateButton(" | ||
+ | btn.SetTextSize( 32 ) | ||
+ | // | ||
+ | // | ||
+ | |||
+ | 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.Alert(tst); | + | app.ShowPopup(" |
- | app.SetClipboardText(tst); | + | |
} | } | ||
- | function getDeviceSpecs() | + | function getBuilderVersion() |
{ | { | ||
- | var os =app.GetOSVersion(); | + | var msg = "Apk Builder plugin not installed"; |
- | var model = app.GetModel(); | + | var path = app.GetPrivateFolder(" |
- | var tablet = app.IsTablet(); | + | "/ |
- | //Get screen dimensions. | + | |
- | var sw = app.GetScreenWidth(); | + | { |
- | var sh = app.GetScreenHeight(); | + | msg = "Apk Builder version " + app.ReadFile( path ) |
- | var dens = app.GetScreenDensity(); | + | } |
- | //Get display dimensions. | + | else if(app.IsAPK()) |
- | var dw = app.GetDisplayWidth(); | + | { |
- | var dh = app.GetDisplayHeight(); | + | msg = "APK built with " + app.GetDSVersion().toFixed(2); |
+ | } | ||
+ | | ||
+ | } | ||
+ | function getDeviceSpecs() | ||
+ | { | ||
+ | var os = app.GetOSVersion(); | ||
+ | var model = app.GetModel(); | ||
+ | var tablet | ||
+ | var fromapk = app.IsAPK(); | ||
+ | var isChrome = app.IsChrome(); | ||
+ | var isPrem = app.IsPremium() | ||
+ | var isTV = app.IsTV(); | ||
+ | var dsversion = app.GetDSVersion().toFixed(2); | ||
+ | | ||
+ | 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() { |
- | // | + | return app.IsScoped()? |
- | var s = "/*\nos=" + os+"\n"+ | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | " | + | |
- | return(s); | + | |
} | } | ||
+ | function OnConfig() | ||
+ | { | ||
+ | //called when screen rotates | ||
+ | //also called at startup to fix Chromebook display size anomaly | ||
+ | var fixwid=lay.GetAbsWidth()/ | ||
+ | var fixhigh=lay.GetAbsHeight()/ | ||
+ | var wid=1, high=0.8 | ||
+ | if(fixwid< | ||
+ | if(fixhigh< | ||
+ | scroller.SetSize( wid,high ) | ||
+ | txt.SetSize( wid, high ) | ||
+ | } | ||
</ | </ | ||
===== 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. |