Exemplo n.º 1
0
  @Override
  protected void onHandleIntent(Intent intent) {
    int serviceMode = intent.getIntExtra(SERVICE_MODE, MODE_ALL_REMINDS);
    switch (serviceMode) {
      case MODE_ALL_REMINDS:
        Log.i(TAG, "NotificationService called to update alarm");

        List<Remind> waitingReminds =
            RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS);
        for (Remind remind : waitingReminds) {
          if (remind.getNotificationMillis() >= System.currentTimeMillis()) {
            setAlarm(remind.getId(), remind.getNotificationMillis(), remind.getTitle());
          }
        }
        break;

      case MODE_ONE_REMIND:
        Log.i(TAG, "NotificationService called to set one alarm");

        int setAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        long alarmMillis = intent.getLongExtra(DatabaseHelper.COLUMN_MILLIS, 0);
        String alarmMessage = intent.getStringExtra(DatabaseHelper.COLUMN_TITLE);
        setAlarm(setAlarmId, alarmMillis, alarmMessage);
        break;

      case MODE_UPDATE_ALARM:
        Log.i(TAG, "NotificationService called to update alarm");

        int updateAlarmId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
        updateAlarm(updateAlarmId);
        break;
    }
  }
Exemplo n.º 2
0
  public void add(List<Remind> listItem) {
    try {
      for (Remind remind : listItem) {
        remindDao.create(remind);

        Log.i(TAG, String.format("%s: %d", "add to base, id", remind.getId()));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
0
  public void remove(Remind item) {
    try {
      remindDao.delete(item);

      Log.i(TAG, String.format("%s: %d", "remove at base, id", item.getId()));
    } catch (SQLException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
    @Override
    public void onReceive(Context context, Intent intent) {
      switch (intent.getAction()) {
        case NotificationUtil.BROADCAST_ACTION_NEW_REMIND:
          int id = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
          Remind remind = RemindDatabase.getInstance().get(id);
          switch (mFragmentType) {
            case FRAGMENT_TYPE_CURRENT:
              if (remind.getStatus() == RemindUtil.STATUS_WAIT) {
                mAdapter.add(id);
              } else {
                mAdapter.remove(id);
              }
              break;

            case FRAGMENT_TYPE_DONE:
              if (remind.getStatus() == RemindUtil.STATUS_DONE) {
                mAdapter.add(id);
              } else {
                mAdapter.remove(id);
              }
              break;
          }

        case NotificationUtil.BROADCAST_ACTION_REMIND_GONE:
          if (mFragmentType == FRAGMENT_TYPE_CURRENT) {
            int goneItemId = intent.getIntExtra(DatabaseHelper.COLUMN_ID, 0);
            mAdapter.updateItem(goneItemId);
          }
          break;

        case NotificationUtil.BROADCAST_ACTION_SORT_MODE:
          if (mFragmentType == FRAGMENT_TYPE_CURRENT) {
            mAdapter.updateData(
                RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_WAITING_REMINDS));
          } else {
            mAdapter.updateData(
                RemindDatabase.getInstance().getStoredData(DatabaseHelper.FILTER_DONE_REMINDS));
          }
          break;
      }
    }
Exemplo n.º 5
0
  private void updateAlarm(int id) {
    Remind remind = RemindDatabase.getInstance().get(id);
    Intent pendingOperationContent = new Intent(mContext, AlarmService.class);
    PendingIntent pendingOperation =
        PendingIntent.getService(mContext, id, pendingOperationContent, 0);

    mAlarmManager.cancel(pendingOperation);
    pendingOperation.cancel();

    switch (remind.getStatus()) {
      case RemindUtil.STATUS_DONE:
        Log.i(TAG, "Dismiss alarm, id: " + id);
        break;

      case RemindUtil.STATUS_WAIT:
        if (remind.getNotificationMillis() > System.currentTimeMillis()) {
          setAlarm(id, remind.getNotificationMillis(), remind.getTitle());
          Log.i(TAG, "Set removed alarm back, id: " + id);
        }
        break;
    }
  }