Methods Summary |
---|
boolean | compareCriterias(Criteria c1, Criteria c2)
if (!c1.isAllowedToCost() && c2.isAllowedToCost()) {
return false;
}
if (c1.isSpeedAndCourseRequired() && !c2.isSpeedAndCourseRequired()) {
return false;
}
if (c1.isAltitudeRequired() && !c2.isAltitudeRequired()) {
return false;
}
if (c1.isAddressInfoRequired() && !c2.isAddressInfoRequired()) {
return false;
}
if (c1.getHorizontalAccuracy() != Criteria.NO_REQUIREMENT &&
c1.getHorizontalAccuracy() < c2.getHorizontalAccuracy()) {
return false;
}
if (c1.getVerticalAccuracy() != Criteria.NO_REQUIREMENT &&
c1.getVerticalAccuracy() < c2.getVerticalAccuracy()) {
return false;
}
if (c1.getPreferredResponseTime() != Criteria.NO_REQUIREMENT &&
c1.getPreferredResponseTime() < c2.getPreferredResponseTime()) {
return false;
}
if (c1.getPreferredPowerConsumption() != Criteria.NO_REQUIREMENT
&& c1.getPreferredPowerConsumption() <
c2.getPreferredPowerConsumption()) {
return false;
}
return true;
|
public abstract int | getDefaultInterval()
|
public abstract int | getDefaultMaxAge()
|
public abstract int | getDefaultTimeout()
|
public static com.sun.j2me.location.LocationProviderImpl | getInstanceImpl(Criteria criteria)
LocationProviderImpl[] found = new LocationProviderImpl[2];
int state;
if (criteria == null) {
criteria = new Criteria();
}
boolean allOutOfService = true;
LocationProviderImpl[] providers = getProviders();
// loop over all providers and set the ones that match the criteria
// in their proper state, to give the one available preference over
// the unavailable one
for (int i = 0; i < providers.length; i++) {
LocationProviderImpl provider = (LocationProviderImpl)providers[i];
state = provider.getState();
if ((state == AVAILABLE) || (state == TEMPORARILY_UNAVAILABLE)) {
allOutOfService = false;
if (provider.matchesCriteria(criteria)) {
found[state - 1] = provider;
}
}
}
if (allOutOfService) {
throw new LocationException("All providers are out of service");
}
// first try to get the available one
if (found[AVAILABLE - 1] != null) {
return found[AVAILABLE - 1];
}
if (found[TEMPORARILY_UNAVAILABLE - 1] != null) {
return found[TEMPORARILY_UNAVAILABLE - 1];
}
return null;
|
public static synchronized Location | getLastKnownLocation()
return PlatformLocationProvider.getLastKnownLocation();
|
abstract LocationImpl | getLastLocation()
|
public Location | getLocation(int timeout)
Util.checkForPermission(Permissions.LOCATION, false);
if (timeout == 0 || timeout < -1) {
throw new IllegalArgumentException("Illegal timeout value");
}
if (timeout == -1) {
timeout = getDefaultTimeout();
}
LocationImpl location = getLocationImpl(timeout);
return location;
|
protected LocationImpl | getLocationImpl(int timeout)
long startTime = System.currentTimeMillis();
long endTime = startTime + timeout * 1000;
LocationImpl newLocation = null;
if (getState() == OUT_OF_SERVICE) {
throw new LocationException("Provider is out of service");
}
try {
locationQueries++;
while (!resetRequested && System.currentTimeMillis() < endTime) {
if (getState() == AVAILABLE) {
newLocation = updateLocation(endTime -
System.currentTimeMillis());
if (resetRequested) {
break;
}
if (newLocation != null) {
return newLocation;
}
} else {
Thread.sleep(getStateInterval() * 1000);
}
long delay = Math.min(getResponseTime() * 1000,
endTime - System.currentTimeMillis());
if (delay <= 0) {
break;
}
while (!resetRequested && delay > 0) {
Thread.sleep(100);
delay -= 100;
}
}
if (!resetRequested) {
if (getState() == TEMPORARILY_UNAVAILABLE) {
throw new LocationException("Provider is temporarily unavailable");
}
// try one last time
newLocation = updateLocation(getResponseTime() * 1000);
if (!resetRequested) {
if (newLocation != null) {
return newLocation;
}
throw new LocationException("Could not acquire location");
}
}
} finally {
locationQueries--;
}
throw new InterruptedException("Location query was interrupted");
|
public LocationListener | getLocationListener()
return locationListener;
|
static com.sun.j2me.location.LocationProviderImpl[] | getProviders()
if (providers == null) {
Vector vectProviders = new Vector();
String listProviders = PlatformLocationProvider.
getListOfLocationProviders();
if (listProviders != null &&
(listProviders = listProviders.trim()) != "") {
/* parsing the list of providers */
while (listProviders.length() > 0) {
int posSpace = listProviders.indexOf(SEPARATOR);
String newProviderName;
if (posSpace == -1) { // last provider name
newProviderName = listProviders;
listProviders = "";
} else { // not last name
newProviderName = listProviders.substring(0, posSpace);
listProviders = listProviders.substring(posSpace + 1);
}
try {
LocationProviderImpl providerInstance = new
PlatformLocationProvider(newProviderName);
vectProviders.addElement(providerInstance);
} catch (IllegalAccessException e) {
if (Logging.TRACE_ENABLED) {
Logging.trace(e, "Illegal access to provider");
}
}
}
}
providers = new LocationProviderImpl[vectProviders.size()];
vectProviders.copyInto(providers);
}
return providers;
|
public abstract int | getResponseTime()
|
public abstract int | getStateInterval()
|
public boolean | matchesCriteria(Criteria criteria)
// JAVADOC COMMENT ELIDED
return compareCriterias(criteria, this.criteria);
|
public void | reset()
if (locationQueries > 0) {
resetRequested = true;
int attemptCount = Integer
.parseInt(Configuration
.getProperty("com.sun.j2me.location.ResetTimeout"))
* 10;
while (locationQueries > 0 && attemptCount-- > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
}
resetRequested = false;
}
|
public void | setLocationListener(LocationListener listener, int interval, int timeout, int maxAge)
Util.checkForPermission(Permissions.LOCATION, true);
if (interval < -1 ||
(interval != -1 && (timeout > interval || maxAge > interval ||
timeout < 1 && timeout != -1 ||
maxAge < 1 && maxAge != -1))) {
if (listener != null) {
throw new IllegalArgumentException("Timeout value is invalid");
}
}
// stop the current locationThread and stateThread
if (locationThread != null) {
locationThread.terminate();
try { // wait for thread to die
locationThread.join();
} catch (InterruptedException e) { // do nothing
if (Logging.TRACE_ENABLED) {
Logging.trace(e, "Wrong thread exception.");
}
}
locationThread = 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;
}
if (listener == null) {
locationListener = null;
return;
}
if (interval == -1) {
interval = getDefaultInterval();
maxAge = getDefaultMaxAge();
timeout = getDefaultTimeout();
}
if (maxAge == -1) {
maxAge = getDefaultMaxAge();
}
if (timeout == -1) {
timeout = getDefaultTimeout();
}
this.locationListener = listener;
// Start the location thread when interval > 0
if (interval > 0) {
locationThread = new LocationThread(this, listener, interval,
timeout, maxAge);
locationThread.start();
}
// Start the state update thread
stateThread = new StateThread(this, listener);
stateThread.start();
|
protected abstract LocationImpl | updateLocation(long timeout)
|