Advertisement
Guest User

garminforumsrgreat

a guest
Dec 27th, 2024
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.28 KB | None | 0 0
  1. import Toybox.Lang;
  2. import Toybox.WatchUi;
  3. import Toybox.Application;
  4. import Toybox.Lang;
  5. import Toybox.Timer;
  6. import Toybox.System;
  7.  
  8. class MetronomeApp ... {
  9.  
  10.     function getInitialView() ... {
  11.         var view = new MetronomeView();
  12.         return [view, new MetronomeDelegate(view)]
  13.     }
  14.  
  15. }
  16.  
  17. class MetronomeView extends WatchUi.View {
  18.     private var timer as Timer;
  19.     private const updateInterval = 1000; // 1000 ms = 1 second
  20.     private var vibrating as Boolean;
  21.  
  22.     private const vibeData = [
  23.         new Attention.VibeProfile(75, 50),
  24.         new Attention.VibeProfile(0, 950),
  25.         new Attention.VibeProfile(50, 50),
  26.         new Attention.VibeProfile(0, 950),
  27.         new Attention.VibeProfile(50, 50),
  28.         new Attention.VibeProfile(0, 950),
  29.         new Attention.VibeProfile(50, 50),
  30.         new Attention.VibeProfile(0, 950),
  31.     ];
  32.  
  33.     function initialize() {
  34.         timer = new Timer.Timer();
  35.         myTimer.start(method(:timerCallback), updateInterval, true);
  36.     }
  37.  
  38.     function timerCallback() as Void {
  39.         WatchUi.requestUpdate(); // triggers a call to onUpdate()
  40.     }
  41.  
  42.     function onUpdate() {
  43.         if (vibrating) {
  44.             Attention.vibrate(vibeData);
  45.         }
  46.  
  47.         // render UI
  48.         // ...
  49.     }
  50.  
  51.     function startVibes() {
  52.         vibrating = true;
  53.     }
  54.  
  55.     function stopVibes() {
  56.         vibrating = false;
  57.     }
  58. }
  59.  
  60. class MetronomeDelegate extends WatchUi.BehaviorDelegate {
  61.     var metronomeView as MetronomeView;
  62.     function initialize(view) {
  63.         BehaviorDelegate.initialize();
  64.         metronomeView = view;
  65.     }
  66.  
  67.     function onSwipe(swipeEvent) {
  68.         var direction = swipeEvent.getDirection();
  69.         System.println(direction);
  70.         if (direction == 0) {
  71.             WatchUi.pushView(new Rez.Menus.MainMenu(), new MetronomeMenuDelegate(), WatchUi.SLIDE_UP);
  72.         } else if (direction == 2) {
  73.             metronomeView.startVibes();
  74.         }
  75.         return true;
  76.     }
  77.  
  78.     function onKey(keyEvent) {
  79.         var key = keyEvent.getKey();
  80.         System.println(key);
  81.         if (key == 4) {
  82.             metronomeView.stopVibes();
  83.             return true;
  84.         }
  85.         else {
  86.             metronomeView.startVibes();
  87.             return false;
  88.         }
  89.     }
  90. }
  91.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement