/** * Immediately stop the animation and flush the segment queue. */ public void stop() { if (future != null) { future.cancel(true); future = null; if (onStop != null) { onStop.action(); } } }
protected void valueChanged(float value) { MotorEvent event = new MotorEvent(System.currentTimeMillis(), System.nanoTime(), value); listeners.forEach((listener) -> listener.valueChanged(event)); if (value > 0) { if (forwardAction != null) { forwardAction.action(); } } else if (value < 0) { if (backwardAction != null) { backwardAction.action(); } } else { if (stopAction != null) { stopAction.action(); } } } }
/** * Play the animation. Animation's are set to play by default and this only * needs to be called if the animation has been paused or a segment's speed * property was set to 0. * * @return Future instance for the background animation thread */ public Future<?> play() { currentAnimationInstance = animationInstances.removeFirst(); runSegment = 0; runStep = 0; future = DioZeroScheduler.getNonDaemonInstance().scheduleAtFixedRate(this, 0, periodMs, TimeUnit.MILLISECONDS); if (onStart != null) { onStart.action(); } return future; }
private void onOffLoop(float onTime, float offTime, int n, Action stopAction) throws RuntimeIOException { running = true; if (n > 0) { for (int i = 0; i < n && running; i++) { onOff(onTime, offTime); } } else if (n == INFINITE_ITERATIONS) { while (running) { onOff(onTime, offTime); } } if (stopAction != null) { stopAction.action(); } }