📄 positioninglistener.java
字号:
/*
* PositioningListener.java
*
*/
package com.sonyericsson.example;
import javax.microedition.location.Location;
import javax.microedition.location.LocationListener;
import javax.microedition.location.LocationProvider;
/**
*
*/
public class PositioningListener implements LocationListener {
private Location currentLocation = null;
private int currentState = 0;
private static final Object STATE_LOCK = new Object();
private static final Object LOCATION_LOCK = new Object();
private boolean locationUpdated = false;
private boolean stateUpdated = false;
public PositioningListener() {
}
public String getStateString() {
return Utils.getStateString(currentState);
}
public Location getCurrentLocation() {
synchronized (LOCATION_LOCK) {
return currentLocation;
}
}
public Location waitForLocation() {
synchronized (LOCATION_LOCK) {
try {
while (!locationUpdated) {
LOCATION_LOCK.wait();
}
locationUpdated = false; // reset flag
} catch (InterruptedException i) {
i.printStackTrace();
}
return currentLocation;
}
}
public int waitForStateChange() {
synchronized (STATE_LOCK) {
try {
while (!stateUpdated) {
STATE_LOCK.wait();
}
stateUpdated = false; // reset flag
} catch (InterruptedException i) {
i.printStackTrace();
}
}
return currentState;
}
public void providerStateChanged(LocationProvider locationProvider, int i) {
synchronized (STATE_LOCK) {
currentState = i;
stateUpdated = true;
STATE_LOCK.notifyAll();
}
}
public void locationUpdated(LocationProvider locationProvider, Location location) {
synchronized (LOCATION_LOCK) {
currentLocation = location;
locationUpdated = true;
LOCATION_LOCK.notifyAll();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -