Android Open Source - RadioRake Alarm Helper






From Project

Back to project page RadioRake.

License

The source code is released under:

GNU General Public License

If you think the Android project RadioRake 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

package com.asp.radiorake;
/*from  w w  w . jav a  2s  .  c o  m*/
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.asp.radiorake.recording.RecordingBroadcastReceiver;
import com.aspillai.R;

import java.io.IOException;

public class AlarmHelper {
    private static final String TAG = "com.asp.radiorake.AlarmHelper";


    // Table not zero indexed, so starts at 1
    public static final int ONE_OFF_SCHEDULED_RECORDING = 1;
    public static final int DAILY_SCHEDULED_RECORDING = 2;
    public static final int WEEKLY_SCHEDULED_RECORDING = 3;


    public static void setAlarm(Context context, long databaseId, long stationId, long typeId, long startDateTime, long endDateTime) {

        DatabaseHelper databaseHelper = prepareDatabaseHelper(context);
        RadioDetails radioDetails = databaseHelper.getRadioDetail(stationId);
        databaseHelper.close();

        radioDetails.setRecordingType(typeId);
        radioDetails.setDuration(endDateTime - startDateTime);


        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, RecordingBroadcastReceiver.class);
        intent.setType(String.valueOf(databaseId));

        intent.putExtra(context.getString(R.string.timed_recorder_service_database_id_key), databaseId);
        intent.putExtra(context.getString(R.string.radio_details_name_key), radioDetails.getStationName());
        intent.putExtra(context.getString(R.string.radio_details_stream_url_key), radioDetails.getStreamUrl());
        intent.putExtra(context.getString(R.string.radio_details_playlist_url_key), radioDetails.getPlaylistUrl());
        intent.putExtra(context.getString(R.string.timed_recorder_service_recording_duration), (endDateTime - startDateTime));
        intent.putExtra(context.getString(R.string.timed_recorder_service_operation_key), typeId);

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        switch ((int) typeId) {

            case ONE_OFF_SCHEDULED_RECORDING:
                alarmManager.set(AlarmManager.RTC_WAKEUP, startDateTime, pendingIntent);
                break;

            case DAILY_SCHEDULED_RECORDING:
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startDateTime, AlarmManager.INTERVAL_DAY, pendingIntent);
                break;

            case WEEKLY_SCHEDULED_RECORDING:
                alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, startDateTime, AlarmManager.INTERVAL_DAY * 7, pendingIntent);
                break;

        }
    }

    public static void cancelAlarm(Context context, long databaseId) {
        AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

        Intent intent = new Intent(context, RecordingBroadcastReceiver.class);
        intent.setType(String.valueOf(databaseId));

        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        alarmManager.cancel(pendingIntent);

        Log.d(TAG, "Cancelled alarm id " + databaseId);
    }

    private static DatabaseHelper prepareDatabaseHelper(Context context) {

        DatabaseHelper dbHelper = new DatabaseHelper(context);

        try {
            dbHelper.openDataBase();
        } catch (IOException e) {
            Log.e(TAG, "IOException thrown when trying to access DB", e);
        }

        return dbHelper;
    }
}




Java Source Code List

com.asp.radiorake.AddNewScheduledRecordingActivity.java
com.asp.radiorake.AlarmHelper.java
com.asp.radiorake.CallReceiver.java
com.asp.radiorake.ConfirmDetailsActivity.java
com.asp.radiorake.DatabaseHelper.java
com.asp.radiorake.DatePickerFragment.java
com.asp.radiorake.LastPlayedFile.java
com.asp.radiorake.ListScheduledRecordingsActivity.java
com.asp.radiorake.NotificationHelper.java
com.asp.radiorake.PlayerService.java
com.asp.radiorake.PlayingFile.java
com.asp.radiorake.RadioActivity.java
com.asp.radiorake.RadioApplication.java
com.asp.radiorake.RadioDetails.java
com.asp.radiorake.RebootBroadcastReceiver.java
com.asp.radiorake.RecordingsActivity.java
com.asp.radiorake.RecordioBaseActivity.java
com.asp.radiorake.RemoteControlReceiver.java
com.asp.radiorake.ScheduledRecordingsCursorAdaptor.java
com.asp.radiorake.TimePickerFragment.java
com.asp.radiorake.filehandling.FileHandler.java
com.asp.radiorake.filehandling.M3uHandler.java
com.asp.radiorake.filehandling.PlsHandler.java
com.asp.radiorake.recording.RecorderService.java
com.asp.radiorake.recording.RecordingBroadcastReceiver.java
com.asp.radiorake.utils.DateUtils.java
com.asp.radiorake.utils.StringUtils.java