Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RandomWatchFaceViewClass {
- // ...
- function initialize() {
- //...
- if (hasComps) {
- stepId = new Id(Complications.COMPLICATION_TYPE_STEPS);
- batId = new Id(Complications.COMPLICATION_TYPE_BATTERY);
- calId = new Id(Complications.COMPLICATION_TYPE_CALENDAR_EVENTS);
- }
- stepComp = Complications.getComplication(stepId);
- if (stepComp != null) {
- Complications.subscribeToUpdates(stepId);
- }
- batComp = Complications.getComplication(batId);
- if (batComp != null) {
- Complications.subscribeToUpdates(batId);
- }
- calComp = Complications.getComplication(calId);
- if (calComp != null) {
- Complications.subscribeToUpdates(calId);
- }
- Complications.registerComplicationChangeCallBack(method(:onComplicationChanged));
- }
- // Callback method which will be called by the system whenever
- // any of the subscribed complications is changes
- function onComplicationChanged(id as Complication.id) as Void {
- if (id == stepId) {
- updateStepsValue();
- } else if (id == batId) {
- updateBatValue();
- } else if (id == calComp) {
- updateCalendarValue();
- }
- }
- var batLoad;
- function updateBatValue() {
- if (hasComps) {
- batLoad = Complications.getComplication(batId).value;
- } else {
- batLoad = ((System.getSystemStats().battery) + 0.5).toNumber();
- }
- }
- function updateStepsValue() {
- // similar to above
- }
- function updateCalValue() {
- // similar to above
- }
- function onUpdate(dc) {
- // If we have complications, thre's no point in calling these functions,
- // as they're already called when complications change
- if (!hasComps) {
- updateStepsValue();
- updateBatValue();
- updateCalValue();
- }
- var batString = Lang.format("$1$", [batLoad])+"%";
- var stepsString = ... // similar to the above
- var calString = ... // similar to the above
- // code which actually draws batString, stepsString, calString to the dc:
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement