Search in sources :

Example 1 with BluetoothScanResult

use of com.facebook.places.internal.BluetoothScanResult 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);
    }
}
Also used : WifiScanResult(com.facebook.places.internal.WifiScanResult) LocationPackage(com.facebook.places.internal.LocationPackage) Bundle(android.os.Bundle) BluetoothScanResult(com.facebook.places.internal.BluetoothScanResult) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ConfidenceLevel(com.facebook.places.model.CurrentPlaceRequestParams.ConfidenceLevel) JSONObject(org.json.JSONObject) FacebookException(com.facebook.FacebookException) Location(android.location.Location)

Aggregations

Location (android.location.Location)1 Bundle (android.os.Bundle)1 FacebookException (com.facebook.FacebookException)1 BluetoothScanResult (com.facebook.places.internal.BluetoothScanResult)1 LocationPackage (com.facebook.places.internal.LocationPackage)1 WifiScanResult (com.facebook.places.internal.WifiScanResult)1 ConfidenceLevel (com.facebook.places.model.CurrentPlaceRequestParams.ConfidenceLevel)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1 JSONObject (org.json.JSONObject)1