Android Open Source - sleep-timer Pause Music Receiver






From Project

Back to project page sleep-timer.

License

The source code is released under:

MIT License

If you think the Android project sleep-timer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
Copyright (c) 2013 Joel Andrews/*  ww w . j a va 2  s.c om*/
Distributed under the MIT License: http://opensource.org/licenses/MIT
 */

package com.oldsneerjaw.sleeptimer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

/**
 * Handles broadcast events intended to pause music playback indefinitely.
 *
 * @author Joel Andrews
 */
public class PauseMusicReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        pauseMusic(context, TimerManager.get(context), CountdownNotifier.get(context));
    }

    /**
     * Pauses all music playback on the device.
     *
     * @param context The context in which the receiver is running
     *
     * @param timerManager The pause music timer manager
     * @param countdownNotifier The countdown notifier
     */
    void pauseMusic(Context context, TimerManager timerManager, CountdownNotifier countdownNotifier) {
        timerManager.cancelTimer();
        countdownNotifier.cancelNotification();

        // The service will be responsible for actually pausing playback and ensuring it remains paused until explicitly
        // restarted
        Intent serviceIntent = new Intent(context, PauseMusicService.class);
        context.stopService(serviceIntent);
        context.startService(new Intent(context, PauseMusicService.class));
    }
}




Java Source Code List

com.oldsneerjaw.sleeptimer.CountdownActivity.java
com.oldsneerjaw.sleeptimer.CountdownNotifierTest.java
com.oldsneerjaw.sleeptimer.CountdownNotifier.java
com.oldsneerjaw.sleeptimer.MainActivityTest.java
com.oldsneerjaw.sleeptimer.MainActivity.java
com.oldsneerjaw.sleeptimer.PauseMusicNotifierTest.java
com.oldsneerjaw.sleeptimer.PauseMusicNotifier.java
com.oldsneerjaw.sleeptimer.PauseMusicReceiverTest.java
com.oldsneerjaw.sleeptimer.PauseMusicReceiver.java
com.oldsneerjaw.sleeptimer.PauseMusicServiceTest.java
com.oldsneerjaw.sleeptimer.PauseMusicService.java
com.oldsneerjaw.sleeptimer.SetTimerActivity.java
com.oldsneerjaw.sleeptimer.TimerManagerTest.java
com.oldsneerjaw.sleeptimer.TimerManager.java