Android Open Source - TasksReminder Alarm Manager Helper






From Project

Back to project page TasksReminder.

License

The source code is released under:

MIT License

If you think the Android project TasksReminder 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.sampa.tasksreminder;
/*from   w  w w.ja  va2 s.co m*/
import org.joda.time.LocalDateTime;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;

public class AlarmManagerHelper extends BroadcastReceiver {

  public static void cancelAlarm(PendingIntent intent, Context context) {
    AlarmManager am = (AlarmManager) context
        .getSystemService(Context.ALARM_SERVICE);
    am.cancel(intent);
  }

  public static void setAlarm(long id, Task task, PendingIntent intent,
      Context context) {
    AlarmManager am = (AlarmManager) context
        .getSystemService(Context.ALARM_SERVICE);
    am.cancel(intent);
    if (task.isDateReminderSet()) {
      am.set(AlarmManager.RTC_WAKEUP, task.getCompleteReminderDate()
          .toDate().getTime(), intent);
      TaskSQLiteHelper taskHelper = new TaskSQLiteHelper(context,
          "DBTasks", null, 1);
      LocalDateTime nextAlarm = task.setNextAlarm();
      SQLiteDatabase db = taskHelper.getWritableDatabase();
      if (nextAlarm != null) {
        db.execSQL("UPDATE DBTasks " + "SET reminderDate='"
            + task.getCompleteReminderDate().toString() + "'"
            + "WHERE _id='" + task.getID() + "'");
      } else {
        db.execSQL("UPDATE DBTasks " + "SET useReminder='false'"
            + "WHERE _id='" + task.getID() + "'");
      }
    } else {
      am.set(AlarmManager.RTC_WAKEUP, task.getCompleteDate().toDate()
          .getTime(), intent);
    }
  }

  public static void setAlarms(Context context) {
    TaskSQLiteHelper taskHelper = new TaskSQLiteHelper(context, "DBTasks",
        null, 1);
    Task[] tasks = taskHelper.getAllTasks();
    if (tasks != null) {
      Task task;
      for (int i = 0; i < tasks.length; i++) {
        task = tasks[i];
        PendingIntent pIntent = taskHelper.createPendingIntent(context,
            task);
        setAlarm(task.getID(), task, pIntent, context);

      }
    }

  }

  @Override
  public void onReceive(Context context, Intent intent) {
    setAlarms(context);
  }
}




Java Source Code List

com.sampa.tasksreminder.AlarmManagerHelper.java
com.sampa.tasksreminder.AlarmReceiver.java
com.sampa.tasksreminder.AlarmService.java
com.sampa.tasksreminder.DatePickerActivity.java
com.sampa.tasksreminder.DatePickerActivity_.java
com.sampa.tasksreminder.MainActivity.java
com.sampa.tasksreminder.MainActivity_.java
com.sampa.tasksreminder.NewTaskActivity.java
com.sampa.tasksreminder.NewTaskActivity_.java
com.sampa.tasksreminder.ShowTaskActivity.java
com.sampa.tasksreminder.ShowTaskActivity_.java
com.sampa.tasksreminder.TaskCursorAdapter.java
com.sampa.tasksreminder.TaskSQLiteHelper.java
com.sampa.tasksreminder.Task.java
com.sampa.tasksreminder.TimePickerFragment.java
com.sampa.tasksreminder.TimePickerFragment_.java
com.squareup.timessquare.CalendarCellView.java
com.squareup.timessquare.CalendarGridView.java
com.squareup.timessquare.CalendarPickerView.java
com.squareup.timessquare.CalendarRowView.java
com.squareup.timessquare.Logr.java
com.squareup.timessquare.MonthCellDescriptor.java
com.squareup.timessquare.MonthDescriptor.java
com.squareup.timessquare.MonthView.java