예제 #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);
  }
 public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
   // onTimeSet is called when the user clicks "Set"
   mTimePickerCancelled = false;
   mHour = hourOfDay;
   mMinutes = minute;
   updateTime();
   // If the time has been changed, enable the alarm.
   mEnabledPref.setChecked(true);
   // Save the alarm and pop a toast.
   popAlarmSetToast(this, saveAlarmAndEnableRevert());
 }
예제 #3
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);
   }
 }
 /**
  * Display a toast that tells the user how long until the alarm goes off. This helps prevent
  * "am/pm" mistakes.
  */
 static void popAlarmSetToast(Context context, int hour, int minute, Alarm.DaysOfWeek daysOfWeek) {
   popAlarmSetToast(context, Alarms.calculateAlarm(hour, minute, daysOfWeek).getTimeInMillis());
 }