Fields Summary |
---|
final String | TAG |
public static final String | CURRENT_LOCATION |
public static final String | CURRENT_SPEED |
public static final String | UNKNOWN_LOCATION |
private static final long | REPEAT_INTERVAL |
private static final long | FRESH_THRESHOLD |
private static final int | LOCATION_CHANGE |
private long | mProviderSetTime |
private android.os.Handler | mHandler |
private android.os.HandlerThread | mHandlerThread |
private android.app.AlarmManager | mAlarmManager |
private android.location.LocationManager | mLocationManager |
private ClusterManager | mClusterManager |
private android.location.Criteria | mCriteria |
private LocationUpdater | mLocationUpdater |
private android.content.Context | mContext |
private android.app.PendingIntent | mPendingIntent |
private String | mFakeLocation |
private final android.location.LocationListener | mLocationListener |
Methods Summary |
---|
public java.util.List | getClusterNames()
return mClusterManager.getClusterNames();
|
public java.util.Map | getFeatureValue(java.lang.String featureName)
HashMap<String,String> feature = new HashMap<String,String>();
if (featureName.equals(CURRENT_LOCATION)) {
// TODO: check last known location first before sending out location request.
/*
Location location =
mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
*/
String location = mClusterManager.getSemanticLocation();
if (!location.equals(UNKNOWN_LOCATION)) {
if (mFakeLocation != null) {
feature.put(CURRENT_LOCATION, mFakeLocation);
} else {
feature.put(CURRENT_LOCATION, location);
}
}
}
return (Map) feature;
|
private android.location.Location | getLastKnownLocation()
List<String> providers = mLocationManager.getAllProviders();
Location bestResult = null;
float bestAccuracy = Float.MAX_VALUE;
long bestTime;
// get the latest location data
long currTime = System.currentTimeMillis();
for (String provider : providers) {
Location location = mLocationManager.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();
if (currTime - time < FRESH_THRESHOLD && accuracy < bestAccuracy) {
bestResult = location;
bestAccuracy = accuracy;
bestTime = time;
}
}
}
if (bestResult != null) {
Log.i(TAG, "found location for free: " + bestResult);
}
return bestResult;
|
public java.lang.String[] | getListOfFeatures()
String[] list = { CURRENT_LOCATION } ;
return list;
|
public void | release()
mContext.unregisterReceiver(mLocationUpdater);
mAlarmManager.cancel(mPendingIntent);
|
private void | setClusteringThread(android.content.Context context)
mClusterManager = new ClusterManager(context);
mHandlerThread = new HandlerThread("Location Handler",
Process.THREAD_PRIORITY_BACKGROUND);
mHandlerThread.start();
mHandler = new Handler(mHandlerThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
if (!(msg.obj instanceof Location)) {
return;
}
Location location = (Location) msg.obj;
switch(msg.what) {
case LOCATION_CHANGE:
mClusterManager.addSample(location);
break;
default:
super.handleMessage(msg);
}
}
};
|
public void | setFakeLocation(java.lang.String name)
if (name != null && name.length() != 0)
mFakeLocation = name;
else mFakeLocation = null;
|