?? 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 + -