Advertisement
Guest User

Untitled

a guest
Nov 15th, 2023
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. class RandomWatchFaceViewClass {
  2. // ...
  3. function initialize() {
  4. //...
  5. if (hasComps) {
  6. stepId = new Id(Complications.COMPLICATION_TYPE_STEPS);
  7. batId = new Id(Complications.COMPLICATION_TYPE_BATTERY);
  8. calId = new Id(Complications.COMPLICATION_TYPE_CALENDAR_EVENTS);
  9. }
  10. stepComp = Complications.getComplication(stepId);
  11. if (stepComp != null) {
  12. Complications.subscribeToUpdates(stepId);
  13. }
  14. batComp = Complications.getComplication(batId);
  15. if (batComp != null) {
  16. Complications.subscribeToUpdates(batId);
  17. }
  18. calComp = Complications.getComplication(calId);
  19. if (calComp != null) {
  20. Complications.subscribeToUpdates(calId);
  21. }
  22.  
  23. Complications.registerComplicationChangeCallBack(method(:onComplicationChanged));
  24. }
  25.  
  26. // Callback method which will be called by the system whenever
  27. // any of the subscribed complications is changes
  28. function onComplicationChanged(id as Complication.id) as Void {
  29. if (id == stepId) {
  30. updateStepsValue();
  31. } else if (id == batId) {
  32. updateBatValue();
  33. } else if (id == calComp) {
  34. updateCalendarValue();
  35. }
  36. }
  37.  
  38. var batLoad;
  39. function updateBatValue() {
  40. if (hasComps) {
  41. batLoad = Complications.getComplication(batId).value;
  42. } else {
  43. batLoad = ((System.getSystemStats().battery) + 0.5).toNumber();
  44. }
  45. }
  46. function updateStepsValue() {
  47. // similar to above
  48. }
  49. function updateCalValue() {
  50. // similar to above
  51. }
  52.  
  53. function onUpdate(dc) {
  54. // If we have complications, thre's no point in calling these functions,
  55. // as they're already called when complications change
  56. if (!hasComps) {
  57. updateStepsValue();
  58. updateBatValue();
  59. updateCalValue();
  60. }
  61.  
  62. var batString = Lang.format("$1$", [batLoad])+"%";
  63. var stepsString = ... // similar to the above
  64. var calString = ... // similar to the above
  65.  
  66. // code which actually draws batString, stepsString, calString to the dc:
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement