class ActionPlayer(object): def __init__(self, device_id: str): self.device_id = device_id self.mnt = MNTDevice(device_id) def stop(self): self.mnt.stop() def tap(self, point: (list, tuple), duration=100): x, y = map(int, point) logger.info('Tap point: ({}, {})'.format(x, y)) self.mnt.tap([(x, y)], duration=duration) # add 50ms for syncing status time.sleep((duration + 50) / 1000) def long_tap(self, point: (list, tuple), duration: int = 1000): self.tap(point, duration) def swipe(self, point1: (list, tuple), point2: (list, tuple), duration: int = 1, part: int = 10): self.mnt.ext_smooth_swipe([point1, point2], duration=duration, part=part) time.sleep((duration + 50) / 1000)
class ActionPlayer(object): """ base, low level API here """ def __init__(self, device_id: str): self.device_id = device_id self.mnt = MNTDevice(device_id) self.cmd_builder = CommandBuilder() def stop(self): self.mnt.stop() def tap(self, point: (list, tuple), duration: int = 100, no_up: bool = None): self.mnt.tap([point], duration=duration, no_up=no_up) def short_tap(self, point: (list, tuple), *args, **kwargs): self.tap(point, duration=100, *args, **kwargs) def long_tap(self, point: (list, tuple), *args, **kwargs): self.tap(point, duration=1000, *args, **kwargs) def swipe(self, point1: (list, tuple), point2: (list, tuple), duration: int = None, part: int = None, no_down: bool=None, no_up: bool=None): if not duration: duration = 5 if not part: part = 50 self.mnt.ext_smooth_swipe( [point1, point2], duration=duration, part=part, no_down=no_down, no_up=no_up, ) def fast_swipe(self, point1: (list, tuple), point2: (list, tuple), *args, **kwargs): self.swipe(point1, point2, duration=5, part=100, *args, **kwargs) def slow_swipe(self, point1: (list, tuple), point2: (list, tuple), *args, **kwargs): self.swipe(point1, point2, duration=50, part=100, *args, **kwargs)
# long-time-tap # for long-click, you should control time delay by yourself # because minitouch return nothing when actions done # we will never know the time when it finished device.tap([(400, 600)], duration=1000) time.sleep(1) # swipe device.swipe([(100, 100), (500, 500)]) # of course, with duration and pressure device.swipe([(100, 100), (400, 400), (200, 400)], duration=500, pressure=59) # stop minitouch # when it was stopped, minitouch can do nothing for device, including release. device.stop() # In another way, you needn't consider about device's life-cycle. # context manager will handle it with safe_device(_DEVICE_ID) as device: # single-tap device.tap([(400, 600)]) # multi-tap device.tap([(400, 400), (600, 600)]) # set the pressure, default == 100 device.tap([(400, 600)], pressure=50) # What's more, you can also access low level API for further usage. # send raw text to it