use of com.facebook.places.internal.LocationPackage in project facebook-android-sdk by facebook.
the class PlaceManager method getCurrentPlaceParameters.
private static Bundle getCurrentPlaceParameters(CurrentPlaceRequestParams request, LocationPackage locationPackage) throws FacebookException {
if (request == null) {
throw new FacebookException("Request and location must be specified.");
}
if (locationPackage == null) {
locationPackage = new LocationPackage();
}
if (locationPackage.location == null) {
locationPackage.location = request.getLocation();
}
if (locationPackage.location == null) {
throw new FacebookException("A location must be specified");
}
try {
Bundle parameters = new Bundle(6);
parameters.putString(PARAM_SUMMARY, PARAM_TRACKING);
int limit = request.getLimit();
if (limit > 0) {
parameters.putInt(PARAM_LIMIT, limit);
}
Set<String> fields = request.getFields();
if (fields != null && !fields.isEmpty()) {
parameters.putString(PARAM_FIELDS, TextUtils.join(",", fields));
}
// Coordinates.
Location location = locationPackage.location;
JSONObject coordinates = new JSONObject();
coordinates.put(PARAM_LATITUDE, location.getLatitude());
coordinates.put(PARAM_LONGITUDE, location.getLongitude());
if (location.hasAccuracy()) {
coordinates.put(PARAM_ACCURACY, location.getAccuracy());
}
if (location.hasAltitude()) {
coordinates.put(PARAM_ALTITUDE, location.getAltitude());
}
if (location.hasBearing()) {
coordinates.put(PARAM_HEADING, location.getBearing());
}
if (location.hasSpeed()) {
coordinates.put(PARAM_SPEED, location.getSpeed());
}
parameters.putString(PARAM_COORDINATES, coordinates.toString());
// min confidence level
ConfidenceLevel minConfidenceLevel = request.getMinConfidenceLevel();
if (minConfidenceLevel == ConfidenceLevel.LOW || minConfidenceLevel == ConfidenceLevel.MEDIUM || minConfidenceLevel == ConfidenceLevel.HIGH) {
String minConfidenceLevelString = minConfidenceLevel.toString().toLowerCase(Locale.US);
parameters.putString(PARAM_MIN_CONFIDENCE_LEVEL, minConfidenceLevelString);
}
if (locationPackage != null) {
// wifi
JSONObject wifi = new JSONObject();
wifi.put(PARAM_ENABLED, locationPackage.isWifiScanningEnabled);
WifiScanResult connectedWifi = locationPackage.connectedWifi;
if (connectedWifi != null) {
wifi.put(PARAM_CURRENT_CONNECTION, getWifiScanJson(connectedWifi));
}
List<WifiScanResult> ambientWifi = locationPackage.ambientWifi;
if (ambientWifi != null) {
JSONArray array = new JSONArray();
for (WifiScanResult wifiScanResult : ambientWifi) {
array.put(getWifiScanJson(wifiScanResult));
}
wifi.put(PARAM_ACCESS_POINTS, array);
}
parameters.putString(PARAM_WIFI, wifi.toString());
// bluetooth
JSONObject bluetooth = new JSONObject();
bluetooth.put(PARAM_ENABLED, locationPackage.isBluetoothScanningEnabled);
List<BluetoothScanResult> bluetoothScanResults = locationPackage.ambientBluetoothLe;
if (bluetoothScanResults != null) {
JSONArray array = new JSONArray();
for (BluetoothScanResult bluetoothScanResult : bluetoothScanResults) {
JSONObject bluetoothData = new JSONObject();
bluetoothData.put(PARAM_PAYLOAD, bluetoothScanResult.payload);
bluetoothData.put(PARAM_RSSI, bluetoothScanResult.rssi);
array.put(bluetoothData);
}
bluetooth.put(PARAM_SCANS, array);
}
parameters.putString(PARAM_BLUETOOTH, bluetooth.toString());
}
return parameters;
} catch (JSONException ex) {
throw new FacebookException(ex);
}
}
use of com.facebook.places.internal.LocationPackage in project facebook-android-sdk by facebook.
the class PlaceManager method newCurrentPlaceRequest.
/**
* Creates a new current place request.
* <p>
* The current place request estimates the place where the user is currently located.
* The response contains a list of places and their associated confidence levels.
* <p>
* If a location is not specified in {@link CurrentPlaceRequestParams}, then the SDK
* retrieves the current location using {@link android.location.LocationManager}.
*
* @param requestParams the request parameters. See {@link CurrentPlaceRequestParams}
* @param callback a {@link OnRequestReadyCallback} that is invoked when the
* {@link GraphRequest} has been created and is ready to be executed.
*/
public static void newCurrentPlaceRequest(final CurrentPlaceRequestParams requestParams, final OnRequestReadyCallback callback) {
Location location = requestParams.getLocation();
CurrentPlaceRequestParams.ScanMode scanMode = requestParams.getScanMode();
LocationPackageRequestParams.Builder builder = new LocationPackageRequestParams.Builder();
// Don't scan for a location if one is provided.
builder.setLocationScanEnabled(location == null);
if (scanMode != null && scanMode == CurrentPlaceRequestParams.ScanMode.LOW_LATENCY) {
// In low-latency mode, avoid active Wi-Fi scanning which can takes
// several seconds.
builder.setWifiActiveScanAllowed(false);
}
LocationPackageManager.requestLocationPackage(builder.build(), new LocationPackageManager.Listener() {
@Override
public void onLocationPackage(LocationPackage locationPackage) {
if (locationPackage.locationError != null) {
callback.onLocationError(getLocationError(locationPackage.locationError));
} else {
Bundle parameters = getCurrentPlaceParameters(requestParams, locationPackage);
GraphRequest graphRequest = new GraphRequest(AccessToken.getCurrentAccessToken(), CURRENT_PLACE_RESULTS, parameters, HttpMethod.GET);
callback.onRequestReady(graphRequest);
}
}
});
}
Aggregations