Created
March 19, 2025 20:49
TouchAwareBehaviorDelegate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Toybox.Lang; | |
import Toybox.WatchUi; | |
class TouchAwareBehaviorDelegate extends WatchUi.BehaviorDelegate { | |
private var isTouchDisabled as Boolean = false; | |
enum Action {Select, Back, Menu} | |
private var action as Action?; | |
public function initialize() { | |
BehaviorDelegate.initialize(); | |
} | |
public function setTouchEnabled(isEnabled as Boolean) as Void { | |
isTouchDisabled = !isEnabled; | |
} | |
private function doAction(isTouchEvent as Boolean) as Boolean { | |
var action = self.action; | |
if (action == null) { | |
return false; | |
} | |
self.action = null; | |
if (isTouchEvent && isTouchDisabled) { | |
return true; | |
} | |
switch (action) { | |
case Select: return doSelect(); break; | |
case Back: return doBack(); break; | |
case self.Menu: return doMenu(); break; | |
default: return false; | |
} | |
} | |
protected function doSelect() as Boolean { | |
return false; | |
} | |
(:behavior_select) | |
public function onSelect() as Boolean { | |
action = Select; | |
return false; | |
} | |
protected function doBack() as Boolean { | |
return false; | |
} | |
(:behavior_back) | |
public function onBack() as Boolean { | |
action = Back; | |
return false; | |
} | |
protected function doMenu() as Boolean { | |
return false; | |
} | |
(:behavior_menu) | |
public function onMenu() as Boolean { | |
action = self.Menu; | |
return false; | |
} | |
public function onKey(keyEvent as KeyEvent) as Boolean { | |
return doAction(false); | |
} | |
public function onTap(clickEvent as ClickEvent) as Boolean { | |
return doAction(true); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment