Methods Summary |
---|
public void | addProximityListener(ProximityListener listener, Coordinates coordinates, float proximityRadius)
synchronized (proximityListeners) {
proximityListeners.addElement(
new ProximityListenerDecorator(listener, coordinates,
proximityRadius));
}
synchronized (this) {
if (proximityProvider == null) {
try {
proximityProvider =
LocationProviderImpl.getInstanceImpl(null);
} catch (LocationException e) {
}
}
if (proximityThread == null) {
proximityThread = new ProximityThread();
proximityThread.start();
}
if (stateThread == null) {
stateThread = new StateMonitorThread();
stateThread.start();
}
}
|
void | fireMonitoringStateChanged(boolean isMonitoringActive)Dispatches a monitor stat changed event.
// prevents concurent modification in which the event code modifies
// the vector by invoking remove/add during event execution
ProximityListenerDecorator[] listeners;
synchronized (proximityListeners) {
listeners =
new ProximityListenerDecorator[proximityListeners.size()];
proximityListeners.copyInto(listeners);
}
for (int i = 0; i < listeners.length; i++) {
listeners[i].monitoringStateChanged(isMonitoringActive);
}
|
void | fireProximityEvent(Location location)Dispatches a proximity event.
// prevents concurent modification in which the event code modifies
// the vector by invoking remove/add during event execution
ProximityListenerDecorator[] listeners;
synchronized (proximityListeners) {
listeners =
new ProximityListenerDecorator[proximityListeners.size()];
proximityListeners.copyInto(listeners);
}
for (int i = 0; i < listeners.length; i++) {
listeners[i].proximityEvent(location);
}
|
public static com.sun.j2me.location.ProximityNotifier | getInstance()Gets a handle to proximity notifier.
if (Instance == null) {
Instance = new ProximityNotifier();
}
return Instance;
|
java.util.Vector | getListeners()Returns a vector of proximity listeners.
return proximityListeners;
|
Location | getLocation()Retrieves location from the dedicated provider.
Location location = null;
try {
if (proximityProvider == null) {
proximityProvider =
LocationProviderImpl.getInstanceImpl(null);
}
location = proximityProvider.getLocationImpl(-1);
} catch (LocationException e) {
} catch (InterruptedException e) {
}
return location;
|
boolean | getMonitoringState()Checks if the monitoring is active.
return proximityProvider != null &&
proximityProvider.getState() == LocationProvider.AVAILABLE;
|
int | getProximityInterval()The recommended time interval for proximity update events.
if (proximityProvider != null) {
return proximityProvider.getDefaultInterval();
}
return 10;
|
int | getStateInterval()The recommended time interval for querying monitoring state.
if (proximityProvider != null) {
return proximityProvider.getStateInterval();
}
return 10;
|
public void | removeProximityListener(ProximityListener listener)
ProximityListenerDecorator[] listeners;
synchronized (proximityListeners) {
listeners =
new ProximityListenerDecorator[proximityListeners.size()];
proximityListeners.copyInto(listeners);
}
for (int i = 0; i < listeners.length; i++) {
if (listeners[i].listener == listener) {
synchronized (proximityListeners) {
proximityListeners.removeElement(listeners[i]);
}
}
}
// check if it was the last listener
if (proximityListeners.isEmpty()) {
synchronized (this) {
if (proximityThread != null) {
proximityThread.terminate();
if (Thread.currentThread() != proximityThread) {
try { // wait for thread to die
proximityThread.join();
} catch (InterruptedException e) { // do nothing
if (Logging.TRACE_ENABLED) {
Logging.trace(e, "Wrong thread exception.");
}
}
}
proximityThread = null;
}
if (stateThread != null) {
stateThread.terminate();
try { // wait for thread to die
stateThread.join();
} catch (InterruptedException e) { // do nothing
if (Logging.TRACE_ENABLED) {
Logging.trace(e, "Wrong thread exception.");
}
}
stateThread = null;
}
// dedicated provider is no longer needed
proximityProvider = null;
}
}
|