Guest User

Untitled

a guest
Dec 18th, 2017
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using Toybox.Application as App;
  2. using Toybox.Background;
  3. using Toybox.Time;
  4. using Toybox.System as Sys;
  5. using Toybox.WatchUi as Ui;
  6. using Toybox.Communications as Comm;
  7. using Toybox.FitContributor as fit;
  8.  
  9.  
  10. //Keys to the object store data:
  11. var OSDATA = "osdata";
  12. var FLAG = "bgFlag";
  13.  
  14.  
  15.  
  16. (:background)
  17. class glucose_datafieldApp extends App.AppBase {
  18. private const TAG = "datafieldApp";
  19.  
  20. //We must check if the system can do backgrounding:
  21. var canDoBG = false;
  22.  
  23. function initialize() {
  24. Sys.println(TAG + "->initialize");
  25.  
  26. AppBase.initialize();
  27. }
  28.  
  29. // onStart() is called on application start up
  30. function onStart(state) {
  31. Sys.println(TAG + "->onStart");
  32. }
  33.  
  34. // onStop() is called when your application is exiting
  35. function onStop(state) {
  36. Sys.println(TAG + "->onStop");
  37. //Delete temporal event:
  38. Background.deleteTemporalEvent();
  39. return false;
  40. }
  41.  
  42. // Return the initial view of your application here
  43. function getInitialView() {
  44. Sys.println(TAG + "->getInitialView");
  45. //Register for temporal events if they are supported:
  46. if(Toybox.System has :ServiceDelegate) {
  47. canDoBG=true;
  48. Background.registerForTemporalEvent(new Time.Duration(5*60));
  49. Sys.println(TAG + "->getInitialView System has bgs support.");
  50. } else {
  51. Sys.println("****background not available on this device****");
  52. }
  53. return [ new glucose_datafieldView() ];
  54. }
  55.  
  56. //Receive the data from the temporal event:
  57. function onBackgroundData(data){
  58. Sys.println(TAG + "-> onBackgroundData: Background data received: " + data);
  59. //Store in object store for main thread:
  60. App.getApp().setProperty(OSDATA,data);
  61. //Set flag to indicate that temporal event has occured and sgv is updated:
  62. App.getApp().setProperty(FLAG, true);
  63. Ui.requestUpdate();
  64. }
  65.  
  66.  
  67. //Delegate what happens when the temporal event occurs:
  68. function getServiceDelegate(){
  69. Sys.println(TAG + "-> getServiceDelegate");
  70. return [new BgbgServiceDelegate()];
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment