コード例 #1
0
  @Override
  public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    // Inflate the menu from xml.
    getMenuInflater().inflate(R.menu.context_menu, menu);

    // Use the current item to create a custom view for the header.
    final AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
    final Cursor c = (Cursor) mAlarmsList.getAdapter().getItem(info.position);
    final Alarm alarm = new Alarm(c);

    // Construct the Calendar to compute the time.
    final Calendar cal = Calendar.getInstance();
    cal.set(Calendar.HOUR_OF_DAY, alarm.hour);
    cal.set(Calendar.MINUTE, alarm.minutes);
    final String time = Alarms.formatTime(this, cal);

    // Inflate the custom view and set each TextView's text.
    final View v = mFactory.inflate(R.layout.context_menu_header, null);
    TextView textView = (TextView) v.findViewById(R.id.header_time);
    textView.setText(time);
    textView = (TextView) v.findViewById(R.id.header_label);
    textView.setText(alarm.label);

    // Set the custom view on the menu.
    menu.setHeaderView(v);
    // Change the text based on the state of the alarm.
    if (alarm.enabled) {
      menu.findItem(R.id.enable_alarm).setTitle(R.string.disable_alarm);
    }
  }
コード例 #2
0
ファイル: Alarms.java プロジェクト: hoyouly/DeskClock
  /** @} */
  static void snooze(Context context, Alarm alarm) {
    final String snooze =
        PreferenceManager.getDefaultSharedPreferences(context)
            .getString(SettingsActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE);
    int snoozeMinutes = Integer.parseInt(snooze);

    final long snoozeTime = System.currentTimeMillis() + ((long) 1000 * 60 * snoozeMinutes);
    saveSnoozeAlert(context, alarm.id, snoozeTime);

    // Get the display time for the snooze and update the notification.
    final Calendar c = Calendar.getInstance();
    c.setTimeInMillis(snoozeTime);
    String snoozeTimeStr = Alarms.formatTime(context, c);
    String label = alarm.getLabelOrDefault(context);

    // Notify the user that the alarm has been snoozed.
    Intent dismissIntent = new Intent(context, AlarmReceiver.class);
    dismissIntent.setAction(Alarms.CANCEL_SNOOZE);
    dismissIntent.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);

    Intent openAlarm = new Intent(context, DeskClock.class);
    openAlarm.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    openAlarm.putExtra(Alarms.ALARM_INTENT_EXTRA, alarm);
    openAlarm.putExtra(DeskClock.SELECT_TAB_INTENT_EXTRA, DeskClock.CLOCK_TAB_INDEX);

    NotificationManager nm = getNotificationManager(context);
    Notification notif =
        new Notification.Builder(context.getApplicationContext())
            .setContentTitle(label)
            .setContentText(
                context.getResources().getString(R.string.alarm_alert_snooze_until, snoozeTimeStr))
            .setSmallIcon(R.drawable.stat_notify_alarm)
            .setOngoing(true)
            .setAutoCancel(false)
            .setPriority(Notification.PRIORITY_MAX)
            .setWhen(0)
            .addAction(
                android.R.drawable.ic_menu_close_clear_cancel,
                context.getResources().getString(R.string.alarm_alert_dismiss_text),
                PendingIntent.getBroadcast(context, alarm.id, dismissIntent, 0))
            .build();
    notif.contentIntent = PendingIntent.getActivity(context, alarm.id, openAlarm, 0);
    nm.notify(alarm.id, notif);
    /// M: @}
    String displayTime = context.getString(R.string.alarm_alert_snooze_set, snoozeMinutes);
    // Intentionally log the snooze time for debugging.
    Log.v(displayTime);

    // Display the snooze minutes in a toast.
    Toast.makeText(context, displayTime, Toast.LENGTH_LONG).show();
    context.stopService(new Intent(Alarms.ALARM_ALERT_ACTION));
    context.stopService(new Intent("com.android.deskclock.ALARM_PHONE_LISTENER"));
  }
 private void updateTime() {
   if (Log.LOGV) {
     Log.v("updateTime " + mId);
   }
   mTimePref.setSummary(Alarms.formatTime(this, mHour, mMinutes, mRepeatPref.getDaysOfWeek()));
 }