User Tools

Site Tools


sample_code:get_device_specs

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels
 var allBuilds = JSON.parse('{' + var allBuilds = JSON.parse('{' +
   '"1":{"level":1,"codename":"(no code name)","version":"1.0"}, ' +   '"1":{"level":1,"codename":"(no code name)","version":"1.0"}, ' +
Line 34: Line 35:
   ' "24":{"level":24,"codename":"Nougat","version":"7.0"}, ' +   ' "24":{"level":24,"codename":"Nougat","version":"7.0"}, ' +
   ' "25":{"level":25,"codename":"Nougat","version":"7.1"}, ' +   ' "25":{"level":25,"codename":"Nougat","version":"7.1"}, ' +
-  ' "26":{"level":26,"codename":"Oreo","version":"8.0.0"} ' ++  ' "26":{"level":26,"codename":"Oreo","version":"8.0"}, ' + 
 +  ' "27":{"level":27,"codename":"Oreo","version":"8.1"}, ' + 
 +  ' "28":{"level":28,"codename":"Pie","version":"9"}, ' + 
 +  ' "29":{"level":29,"codename":"Q","version":"10"}, ' + 
 +  ' "30":{"level":30,"codename":"R","version":"11"}, ' + 
 +  ' "31":{"level":31,"codename":"S","version":"12"}, ' + 
 +  ' "32":{"level":32,"codename":"S_V2","version":"12"} ' +
   ' }');   ' }');
  
Line 44: Line 51:
     osObj.level     osObj.level
 } }
-catch(err) +catch(err){var osInfo = app.GetOSVersion();} 
-{ + 
-  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() );+  if(! app.GetNotifyId()) 
 +  { 
 +    var notify = app.CreateNotification )
 +    notify.SetSmallImage( "Img/getDeviceSpecs.png" ); 
 +    notify.SetLargeImage( "Img/getDeviceSpecs.png" ); 
 +    notify.SetMessage( "",app.GetAppName(),"" ); 
 +    notify.Notify( app.GetAppName() ); 
 +  } 
 +  */
   //Create a layout with objects vertically centered.   //Create a layout with objects vertically centered.
-  var lay = app.CreateLayout("linear", "VCenter,FillXY"); +  lay = app.CreateLayout("linear", "VCenter,FillXY"); 
-  lay.SetBackColor("#ffddffff"); +  
   // create viewr for specs   // create viewr for specs
-  scroll = app.CreateScroller(1, 0.9);+  scroller = app.CreateScroller(1, 0.8);
   var specs = getDeviceSpecs();   var specs = getDeviceSpecs();
-  txt = app.CreateText(specs, 1, 0.9, "left,multiLine"); +  txt = app.CreateText(specs, 1, 0.8, "left,multiLine"); 
-  txt.SetPadding(0.1); +  txt.SetPadding(0.02, 0.01, 0.02, 0.01); 
-  txt.SetTextColor("#ff446666"); +  //txt.SetTextColor("#ff446666"); 
-  scroll.AddChild(txt); +  scroller.AddChild(txt); 
-  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("[fa-copy]", -1, -1, "fontAwesome,custom"); +  var btn = app.CreateButton("[fa-copy]", -1, -1, "fontAwesome"); 
-  btn.SetTextColor("#ffddffff"); +  btn.SetTextSize( 32 ) 
-  btn.SetStyle("#4285F4", "#2265d4", 2, "#999999", 0, 1, "#ff9000");+  //btn.SetTextColor("#ffddffff"); 
 +  //btn.SetStyle("#4285F4", "#2265d4", 2, "#999999", 0, 1, "#ff9000");
  
   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( ) );
-  // flash +  app.ShowPopup("Copied to clipboard")
-  txt.SetBackColor( "#44000000" )+
-  setTimeout( function(){ +
-    txt.SetBackColor( "#00000000" );} +
-    ,100);+
 } }
  
 +function getBuilderVersion()
 +{
 +   var msg = "Apk Builder plugin not installed";
 +   var path = app.GetPrivateFolder("Plugins") +
 +      "/apkbuilder/Version.txt"
 +   if(app.FileExists(path))
 +   {
 +      msg = "Apk Builder version " + app.ReadFile( path )
 +   }
 +   else if(app.IsAPK())
 +   {
 +      msg = "APK built with " + app.GetDSVersion().toFixed(2);
 +   }
 +   return msg
 +}
 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() == "/Assets"+  var fromapk = app.IsAPK(); 
-  var dsversion = app.GetDSVersion()+  var isChrome = app.IsChrome()
 +  var isPrem app.IsPremium() 
 +  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("external");   var extspace = app.GetFreeSpace("external");
   var mem = app.GetMemoryInfo().total.toLocaleString("en-US");   var mem = app.GetMemoryInfo().total.toLocaleString("en-US");
 +  
   //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 = "/*\n" +   var s = "/*\n" +
     "os=" + os + "\n" +     "os=" + os + "\n" +
 +    getBuilderVersion() + "\n" +
     "tablet=" + tablet + "\n" +     "tablet=" + tablet + "\n" +
     "model=" + model + "\n" +     "model=" + model + "\n" +
 +    "isChrome=" + isChrome + "\n" +
 +    "isTV=" + isTV +"\n" +
     "DroidScript=" + dsversion + "\n" +     "DroidScript=" + dsversion + "\n" +
 +    "Storage access=" + storageScoped() + "\n" +
     "screen width=" + sw + "\n" +     "screen width=" + sw + "\n" +
     "screen height=" + sh + "\n" +     "screen height=" + sh + "\n" +
Line 133: Line 165:
     "ext free space=" + extspace + "\n" +     "ext free space=" + extspace + "\n" +
     "memory=" + mem +"\n" +     "memory=" + mem +"\n" +
 +    "premium=" + isPrem +"\n" +
     "country code=" + app.GetCountryCode() + "\n" +     "country code=" + app.GetCountryCode() + "\n" +
     "country=" + app.GetCountry() + "\n" +     "country=" + app.GetCountry() + "\n" +
Line 138: Line 171:
     "language=" + app.GetLanguage() + "\n" +     "language=" + app.GetLanguage() + "\n" +
     "wifi=" + app.GetIPAddress() + "\n" +     "wifi=" + app.GetIPAddress() + "\n" +
 +    "userAgent='" + navigator.userAgent + "'\n" +
     "*/";     "*/";
   return(s);   return(s);
 +}
 +
 +function storageScoped() {
 +   return app.IsScoped()?"Scoped":"Traditional"
 +}
 +
 +function OnConfig()
 +{
 +//called when screen rotates
 +//also called at startup to fix Chromebook display size anomaly
 + var fixwid=lay.GetAbsWidth()/app.GetDisplayWidth()
 + var fixhigh=lay.GetAbsHeight()/app.GetDisplayHeight()
 + var wid=1, high=0.8
 + if(fixwid<1) wid *= fixwid // chromebook not using full width
 + if(fixhigh<1) high *= fixhigh // or height
 + scroller.SetSize( wid,high )
 + txt.SetSize( wid, high  )
 } }
 </code> </code>
 ===== 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.
sample_code/get_device_specs.txt · Last modified: 2022/04/25 17:48 by stevegarman