This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
sample_code:get_device_specs [2017/11/26 03:46] 127.0.0.1 external edit |
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 allBuilds = JSON.parse(' | ||
'" | '" | ||
Line 34: | Line 35: | ||
' " | ' " | ||
' " | ' " | ||
- | ' " | + | ' " |
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
+ | ' " | ||
' }'); | ' }'); | ||
Line 44: | Line 51: | ||
osObj.level | osObj.level | ||
} | } | ||
- | catch(err) | + | catch(err){var osInfo = app.GetOSVersion(); |
- | { | + | |
- | | + | var lay, txt, scroller |
- | } | + | |
- | var txt; | + | |
//Called when application is started. | //Called when application is started. | ||
function OnStart() | function OnStart() | ||
{ | { | ||
- | //Lock orientation | + | /* |
- | app.SetOrientation( app.GetOrientation() ); | + | |
+ | { | ||
+ | var notify = app.CreateNotification( ); | ||
+ | notify.SetSmallImage( " | ||
+ | notify.SetLargeImage( " | ||
+ | notify.SetMessage( "", | ||
+ | notify.Notify( app.GetAppName() ); | ||
+ | } | ||
+ | */ | ||
//Create a layout with objects vertically centered. | //Create a layout with objects vertically centered. | ||
- | | + | lay = app.CreateLayout(" |
- | | + | |
// create viewr for specs | // create viewr for specs | ||
- | | + | |
var specs = getDeviceSpecs(); | var specs = getDeviceSpecs(); | ||
- | txt = app.CreateText(specs, | + | txt = app.CreateText(specs, |
- | txt.SetPadding(0.1); | + | txt.SetPadding(0.02, 0.01, 0.02, 0.01); |
- | txt.SetTextColor("# | + | |
- | | + | |
- | lay.AddChild(scroll); | + | lay.AddChild(scroller); |
//Create a button and add it to layout. | //Create a button and add it to layout. | ||
- | var btn = app.CreateButton(" | + | var btn = app.CreateButton(" |
- | btn.SetTextColor("# | + | |
- | btn.SetStyle("# | + | //btn.SetTextColor("# |
+ | | ||
btn.SetOnTouch(btn_OnTouch); | btn.SetOnTouch(btn_OnTouch); | ||
Line 77: | Line 90: | ||
//Add layout to app. | //Add layout to app. | ||
app.AddLayout(lay); | app.AddLayout(lay); | ||
+ | OnConfig() | ||
} | } | ||
Line 82: | Line 96: | ||
{ | { | ||
app.SetClipboardText(txt.GetText( ) ); | app.SetClipboardText(txt.GetText( ) ); | ||
- | | + | |
- | txt.SetBackColor( "#44000000" ); | + | |
- | setTimeout( function(){ | + | |
- | txt.SetBackColor( "# | + | |
- | ,100); | + | |
} | } | ||
+ | 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 getDeviceSpecs() | function getDeviceSpecs() | ||
{ | { | ||
Line 94: | Line 119: | ||
var model = app.GetModel(); | var model = app.GetModel(); | ||
var tablet = app.IsTablet(); | var tablet = app.IsTablet(); | ||
- | var fromapk = (app.GetAppPath() == "/ | + | var fromapk = app.IsAPK(); |
- | var dsversion = app.GetDSVersion() | + | var isChrome = app.IsChrome(); |
+ | var isPrem | ||
+ | var isTV = app.IsTV(); | ||
+ | var dsversion = app.GetDSVersion().toFixed(2); | ||
//Get screen dimensions. | //Get screen dimensions. | ||
var sw = app.GetScreenWidth(); | var sw = app.GetScreenWidth(); | ||
Line 109: | Line 137: | ||
var extspace = app.GetFreeSpace(" | var extspace = app.GetFreeSpace(" | ||
var mem = app.GetMemoryInfo().total.toLocaleString(" | var mem = app.GetMemoryInfo().total.toLocaleString(" | ||
+ | | ||
//specs are formatted as a comment so we can paste | //specs are formatted as a comment so we can paste | ||
//them somewhere convenient | //them somewhere convenient | ||
Line 120: | Line 148: | ||
var s = "/ | var s = "/ | ||
" | " | ||
+ | getBuilderVersion() + " | ||
" | " | ||
" | " | ||
+ | " | ||
+ | " | ||
" | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 133: | Line 165: | ||
"ext free space=" | "ext free space=" | ||
" | " | ||
+ | " | ||
" | " | ||
" | " | ||
Line 138: | Line 171: | ||
" | " | ||
" | " | ||
+ | " | ||
" | " | ||
return(s); | return(s); | ||
+ | } | ||
+ | |||
+ | function storageScoped() { | ||
+ | | ||
+ | } | ||
+ | |||
+ | 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. |