/**
* SnoozeAction.java
*
* Copyright (c) 2009 codeswimmer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* Created on Dec 2, 2009
*/
package com.codeswimmer.android.apps.alarm.action;
import com.codeswimmer.android.apps.alarm.engine.AndromedaAlarmManager;
import net.sf.microlog.core.Logger;
import net.sf.microlog.core.LoggerFactory;
/**
* This class is used for scheduling a special case countdown timer to notify us when the snooze duration has expired.
*
* @author codeswimmer
*/
public class SnoozeAction extends CountdownTimerAction {
/**
* Add this to <code>microlog.properties</code> for enabling output to console.
* microlog.logger.com.codeswimmer.android.apps.alarm.action.SnoozeAction=DEBUG
*/
private static Logger LOG = LoggerFactory.getLogger(SnoozeAction.class);
/**
* Use {@link #SnoozeAction(long)} to create a new {@link SnoozeAction}.
*/
private SnoozeAction() {
super(0);
}
/**
* Creates a new instance
* @param durationMillis
*/
SnoozeAction(long durationMillis) {
super(durationMillis);
if (LOG.isDebugEnabled()) LOG.debug(String.format("constructing with duration: %d", getDuration())); //$NON-NLS-1$
}
/** {@inheritDoc} */
@Override
public void run() {
super.run();
LOG.debug(String.format(">>> snooze triggered %s", toString())); //$NON-NLS-1$
AlarmAction origAlarm = AndromedaAlarmManager.getLastTriggeredAlarm();
if (origAlarm != null) {
LOG.debug(String.format("snooze - origAlarm: %s", origAlarm.toString())); //$NON-NLS-1$
} else {
// Dec 2, 2009
// TODO: Not sure what to do if the last triggered alarm is null; probably shouldn't just ignore it
LOG.warn("Snooze error: origAlarm is null"); //$NON-NLS-1$
}
}
/** {@inheritDoc} */
@Override
public String toString() {
StringBuilder sb = new StringBuilder("\nSnoozeAction\n"); //$NON-NLS-1$
sb.append(String.format(" duration: %s\n", getDuration())); //$NON-NLS-1$
return sb.toString();
}
}
|