Merge pull request #3516 from egsavage/reset-sleep-timer-on-play
Issue #2381 - restart sleep timer on play
This commit is contained in:
commit
54eeeb4355
|
@ -827,6 +827,9 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPlaybackStart(@NonNull Playable playable, int position) {
|
public void onPlaybackStart(@NonNull Playable playable, int position) {
|
||||||
|
if (taskManager.isSleepTimerActive()) {
|
||||||
|
taskManager.restartSleepTimer();
|
||||||
|
}
|
||||||
taskManager.startWidgetUpdater();
|
taskManager.startWidgetUpdater();
|
||||||
if (position != PlaybackServiceMediaPlayer.INVALID_TIME) {
|
if (position != PlaybackServiceMediaPlayer.INVALID_TIME) {
|
||||||
playable.setPosition(position);
|
playable.setPosition(position);
|
||||||
|
|
|
@ -248,6 +248,16 @@ public class PlaybackServiceTaskManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restarts the sleep timer. If the sleep timer is not active, nothing will happen.
|
||||||
|
*/
|
||||||
|
public synchronized void restartSleepTimer() {
|
||||||
|
if (isSleepTimerActive()) {
|
||||||
|
Log.d(TAG, "Restarting sleep timer");
|
||||||
|
sleepTimer.restart();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the current sleep timer time or 0 if the sleep timer is not active.
|
* Returns the current sleep timer time or 0 if the sleep timer is not active.
|
||||||
*/
|
*/
|
||||||
|
@ -428,14 +438,16 @@ public class PlaybackServiceTaskManager {
|
||||||
return timeLeft;
|
return timeLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onShake() {
|
public void restart() {
|
||||||
postCallback(() -> {
|
postCallback(() -> {
|
||||||
setSleepTimer(waitingTime, shakeToReset, vibrate);
|
setSleepTimer(waitingTime, shakeToReset, vibrate);
|
||||||
callback.onSleepTimerReset();
|
callback.onSleepTimerReset();
|
||||||
});
|
});
|
||||||
|
if (shakeListener != null) {
|
||||||
shakeListener.pause();
|
shakeListener.pause();
|
||||||
shakeListener = null;
|
shakeListener = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ class ShakeListener implements SensorEventListener
|
||||||
double gForce = Math.sqrt(gX*gX + gY*gY + gZ*gZ);
|
double gForce = Math.sqrt(gX*gX + gY*gY + gZ*gZ);
|
||||||
if (gForce > 2.25) {
|
if (gForce > 2.25) {
|
||||||
Log.d(TAG, "Detected shake " + gForce);
|
Log.d(TAG, "Detected shake " + gForce);
|
||||||
mSleepTimer.onShake();
|
mSleepTimer.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue