예제 #1
0
  @Override
  public boolean onContextItemSelected(final MenuItem item) {
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
    final int id = (int) info.id;
    // Error check just in case.
    if (id == -1) {
      return super.onContextItemSelected(item);
    }
    switch (item.getItemId()) {
      case R.id.delete_alarm:
        {
          // Confirm that the alarm will be deleted.
          new AlertDialog.Builder(this)
              .setTitle(getString(R.string.delete_alarm))
              .setMessage(getString(R.string.delete_alarm_confirm))
              .setPositiveButton(
                  android.R.string.ok,
                  new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface d, int w) {
                      Alarms.deleteAlarm(AlarmClock.this, id);
                    }
                  })
              .setNegativeButton(android.R.string.cancel, null)
              .show();
          return true;
        }

      case R.id.enable_alarm:
        {
          final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(info.position);
          final Alarm alarm = new Alarm(c);
          Alarms.enableAlarm(this, alarm.id, !alarm.enabled);
          if (!alarm.enabled) {
            SetAlarm.popAlarmSetToast(
                this, alarm.hour, alarm.minutes, alarm.daysOfWeek, alarm.weekType);
          }
          return true;
        }

      case R.id.edit_alarm:
        {
          final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(info.position);
          final Alarm alarm = new Alarm(c);
          Intent intent = new Intent(this, SetAlarm.class);
          intent.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
          startActivity(intent);
          return true;
        }

      default:
        break;
    }
    return super.onContextItemSelected(item);
  }
예제 #2
0
 private void updateAlarm(boolean enabled, Alarm alarm) {
   Alarms.enableAlarm(this, alarm.id, enabled);
   if (enabled) {
     SetAlarm.popAlarmSetToast(this, alarm.hour, alarm.minutes, alarm.daysOfWeek, alarm.weekType);
   }
 }