Adds vibrate notification action.

cusax-fix
paweldomas 13 years ago
parent b88978488c
commit 6ae5d6b90f

@ -39,9 +39,10 @@ public abstract class NotificationAction
public static final String ACTION_COMMAND = "CommandAction";
/**
* Defines the number of actions.
* The vibrate action type indicates that the device will vibrate,
* when a notification is fired.
*/
public static final int NUM_ACTIONS = 4;
public static final String ACTION_VIBRATE = "VibrateAction";
/**
* Indicates if this handler is enabled.
@ -97,4 +98,4 @@ public void setEnabled(boolean isEnabled)
{
this.isEnabled = isEnabled;
}
}
}

@ -6,11 +6,7 @@
*/
package net.java.sip.communicator.service.notification;
import static net.java.sip.communicator.service.notification.NotificationAction.ACTION_COMMAND;
import static net.java.sip.communicator.service.notification.NotificationAction.ACTION_LOG_MESSAGE;
import static net.java.sip.communicator.service.notification.NotificationAction.ACTION_POPUP_MESSAGE;
import static net.java.sip.communicator.service.notification.NotificationAction.ACTION_SOUND;
import static net.java.sip.communicator.service.notification.NotificationAction.NUM_ACTIONS;
import static net.java.sip.communicator.service.notification.NotificationAction.*;
import static net.java.sip.communicator.service.notification.event.NotificationActionTypeEvent.ACTION_ADDED;
import static net.java.sip.communicator.service.notification.event.NotificationActionTypeEvent.ACTION_CHANGED;
import static net.java.sip.communicator.service.notification.event.NotificationActionTypeEvent.ACTION_REMOVED;
@ -36,6 +32,14 @@ class NotificationServiceImpl
private static final String NOTIFICATIONS_PREFIX
= "net.java.sip.communicator.impl.notifications";
/**
* Defines the number of actions that have to be registered before cached
* notifications are fired.
*
* Current value = 4 (vibrate action excluded).
*/
public static final int NUM_ACTIONS = 4;
/**
* A list of all registered <tt>NotificationChangeListener</tt>s.
*/
@ -272,6 +276,11 @@ else if (actionType.equals(ACTION_COMMAND))
(CommandNotificationAction) action,
cmdargs);
}
else if(actionType.equals(ACTION_VIBRATE))
{
((VibrateNotificationHandler) handler).vibrate(
(VibrateNotificationAction) action );
}
}
}
@ -708,6 +717,42 @@ else if(actionType.equals(ACTION_COMMAND))
action = new CommandNotificationAction(commandDescriptor);
}
else if(actionType.equals(ACTION_VIBRATE))
{
String descriptor
= configService.getString(
actionPropName + ".descriptor");
int patternLen
= configService.getInt(
actionPropName + ".patternLength", -1);
if(patternLen == -1)
{
logger.error("Invalid pattern length: "+patternLen);
continue;
}
long[] pattern = new long[patternLen];
for(int pIdx=0; pIdx<patternLen; pIdx++)
{
pattern[pIdx]
= configService.getLong(
actionPropName+".patternItem"+pIdx, -1);
if(pattern[pIdx] == -1)
{
logger.error("Invalid pattern interval: "+pattern);
continue;
}
}
int repeat = configService.getInt(
actionPropName + ".repeat", -1);
action
= new VibrateNotificationAction(
descriptor, pattern, repeat);
}
action.setEnabled(isEnabled(actionPropName + ".enabled"));
@ -1242,6 +1287,30 @@ else if(action instanceof CommandNotificationAction)
actionTypeNodeName + ".commandDescriptor",
commandAction.getDescriptor());
}
else if(action instanceof VibrateNotificationAction)
{
VibrateNotificationAction vibrateAction
= (VibrateNotificationAction) action;
configProperties.put(actionTypeNodeName + ".descriptor",
vibrateAction.getDescriptor());
long[] pattern = vibrateAction.getPattern();
configProperties.put(
actionTypeNodeName + ".patternLength",
pattern.length);
for(int pIdx = 0; pIdx < pattern.length; pIdx++)
{
configProperties.put(
actionTypeNodeName + ".patternItem" + pIdx,
pattern[pIdx]);
}
configProperties.put(actionTypeNodeName + ".repeat",
vibrateAction.getRepeat());
}
configProperties.put(
actionTypeNodeName + ".enabled",
@ -1295,6 +1364,17 @@ public void stopNotification(NotificationData data)
((SoundNotificationHandler) handler).stop(data);
}
}
Iterable<NotificationHandler> vibrateHandlers
= getActionHandlers(NotificationAction.ACTION_VIBRATE);
if(vibrateHandlers != null)
{
for(NotificationHandler handler : vibrateHandlers)
{
((VibrateNotificationHandler)handler).cancel();
}
}
}
/**

@ -0,0 +1,111 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.notification;
/**
* <tt>VibrateNotificationAction</tt> is meant to define haptic feedback
* notification using device's vibrator.<br/><br/>
*
* Given array of <tt>long</tt> are
* the duration for which to turn on or off the vibrator in miliseconds.
* The first value indicates the number of miliseconds to wait before turning
* the vibrator on. The next value indicates the number of miliseconds for which
* to keep the vibrator on before turning it off and so on.<br/><br/>
*
* The <tt>repeat</tt> parameter is an index into the pattern at which it will
* be looped until the {@link VibrateNotificationHandler#cancel()} method is
* called.
*
* @author Pawel Domas
*/
public class VibrateNotificationAction
extends NotificationAction
{
/**
* The patter of off/on intervals in milis that will be played.
*/
private final long[] pattern;
/**
* Repeat index into the pattern(-1 to disable repeat).
*/
private final int repeat;
/**
* Descriptor that can be used to identify action.
*/
private final String descriptor;
/**
* Vibrate constantly for the specified period of time.
*
* @param descriptor string identifier of this action.
* @param milis the number of miliseconds to vibrate.
*/
public VibrateNotificationAction(String descriptor, long milis)
{
super(NotificationAction.ACTION_VIBRATE);
this.pattern = new long[2];
pattern[0] = 0;
pattern[1] = milis;
repeat = -1;
this.descriptor = descriptor;
}
/**
* Vibrate using given <tt>patter</tt> and optionally loop if the
* <tt>repeat</tt> index is not <tt>-1</tt>.
*
* @param descriptor the string identifier of this action.
* @param patter the array containing vibrate pattern intervals.
* @param repeat the index into the patter at which it will be looped
* (-1 to disable repeat).
*
* @see VibrateNotificationAction
*/
public VibrateNotificationAction( String descriptor,
long[] patter,
int repeat )
{
super(NotificationAction.ACTION_VIBRATE);
this.pattern = patter;
this.repeat = repeat;
this.descriptor = descriptor;
}
/**
* The string identifier of this action.
*
* @return string identifier of this action which can be used to distinguish
* different actions.
*/
public String getDescriptor()
{
return descriptor;
}
/**
* Returns vibrate pattern array.
* @return vibrate pattern array.
*/
public long[] getPattern()
{
return pattern;
}
/**
* The index at which the pattern shall be looped during playback
* or <tt>-1</tt> to play it once.
*
* @return the index at which the pattern will be looped or <tt>-1</tt> to
* play it once.
*/
public int getRepeat()
{
return repeat;
}
}

@ -0,0 +1,33 @@
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.service.notification;
/**
* The <tt>VibrateNotificationHandler</tt> interface is meant to be
* implemented by the notification bundle in order to provide handling of
* vibrate actions.
*
* @author Pawel Domas
*/
public interface VibrateNotificationHandler
extends NotificationHandler
{
/**
* Perform vibration patter defined in given <tt>vibrateAction</tt>.
*
* @param vibrateAction the <tt>VibrateNotificationAction</tt> containing
* vibration pattern details.
*/
public void vibrate(VibrateNotificationAction vibrateAction);
/**
* Turn the vibrator off.
*/
public void cancel();
}
Loading…
Cancel
Save