// Attempt to snooze this alert. // 当闹铃响时,用户按下贪睡按钮时,调用此方法 private void snooze() { // Do not snooze if the snooze button is disabled. // 打盹按钮被禁用,则直接返回 if (!findViewById(R.id.snooze).isEnabled()) { dismiss(false); return; } // 获取打盹时长:默认为10分钟 final String snooze = PreferenceManager.getDefaultSharedPreferences(this) .getString(ConfigurationActivity.KEY_ALARM_SNOOZE, DEFAULT_SNOOZE); int snoozeMinutes = Integer.parseInt(snooze); // 下一次闹铃时间 final long snoozeTime = System.currentTimeMillis() + (1000 * 60 * snoozeMinutes); TimerMgr.saveSnoozeTimer(AlarmAlertFullScreen.this, mTimer, snoozeMinutes); // Get the display time for the snooze and update the notification. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(snoozeTime); // Append (snoozed) to the label. // 在label后面增加:(snoozed) String label = mTimer.getName(); label = getString(R.string.alarm_notify_snooze_label, label); // Notify the user that the alarm has been snoozed. // 用于下面的通知栏,当用户点击通知栏通知时,则取消打盹 Intent cancelSnooze = new Intent(this, AlarmReceiver.class); cancelSnooze.setAction(TimerMgr.CANCEL_SNOOZE); cancelSnooze.putExtra(TimerMgr.ALARM_ID, mTimer.getID()); // 获取一个PendingIntent,即将mAlarm.id广播给cancelSnooze PendingIntent broadcast = PendingIntent.getBroadcast(this, mTimer.getID(), cancelSnooze, 0); NotificationManager nm = getNotificationManager(); Notification n = new Notification(R.drawable.stat_notify_alarm, label, 0); // 在此处设置在nority列表里的该norifycation得显示情况。点击后则执行broadcast取消打盹 n.setLatestEventInfo( this, label, getString( R.string.alarm_notify_snooze_text, // Alarm set for %s. Select to cancel. Util.formatTime(c)), broadcast); // FLAG_AUTO_CANCEL 用户点击后自动取消 // FLAG_ONGOING_EVENT 将此通知放到通知栏的"Ongoing"即"正在运行"组中 n.flags |= Notification.FLAG_AUTO_CANCEL | Notification.FLAG_ONGOING_EVENT; nm.notify(mTimer.getTimerDef().getID(), n); // Snoozing for %d minutes. String displayTime = getString(R.string.alarm_alert_snooze_set, snoozeMinutes); // Intentionally log the snooze time for debugging. // Display the snooze minutes in a toast. Toast.makeText(AlarmAlertFullScreen.this, displayTime, Toast.LENGTH_LONG).show(); // 停止AlarmAlert服务 stopService(new Intent(TimerMgr.ALARM_ALERT_ACTION)); finish(); }