Search in sources :

Example 26 with Status

use of com.google.android.gms.common.api.Status in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method getAutocompletePredictions.

@ReactMethod
public void getAutocompletePredictions(String query, ReadableMap options, final Promise promise) {
    String type = options.getString("type");
    String country = options.getString("country");
    country = country.isEmpty() ? null : country;
    double latitude = options.getDouble("latitude");
    double longitude = options.getDouble("longitude");
    double radius = options.getDouble("radius");
    LatLng center = new LatLng(latitude, longitude);
    LatLngBounds bounds = null;
    if (latitude != 0 && longitude != 0 && radius != 0) {
        bounds = this.getLatLngBounds(center, radius);
    }
    PendingResult<AutocompletePredictionBuffer> results = Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query, bounds, getFilterType(type, country));
    AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);
    final Status status = autocompletePredictions.getStatus();
    if (status.isSuccess()) {
        if (autocompletePredictions.getCount() == 0) {
            WritableArray emptyResult = Arguments.createArray();
            autocompletePredictions.release();
            promise.resolve(emptyResult);
            return;
        }
        WritableArray predictionsList = Arguments.createArray();
        for (AutocompletePrediction prediction : autocompletePredictions) {
            WritableMap map = Arguments.createMap();
            map.putString("fullText", prediction.getFullText(null).toString());
            map.putString("primaryText", prediction.getPrimaryText(null).toString());
            map.putString("secondaryText", prediction.getSecondaryText(null).toString());
            map.putString("placeID", prediction.getPlaceId().toString());
            if (prediction.getPlaceTypes() != null) {
                List<String> types = new ArrayList<>();
                for (Integer placeType : prediction.getPlaceTypes()) {
                    types.add(findPlaceTypeLabelByPlaceTypeId(placeType));
                }
                map.putArray("types", Arguments.fromArray(types.toArray(new String[0])));
            }
            predictionsList.pushMap(map);
        }
        // Release the buffer now that all data has been copied.
        autocompletePredictions.release();
        promise.resolve(predictionsList);
    } else {
        Log.i(TAG, "Error making autocomplete prediction API call: " + status.toString());
        autocompletePredictions.release();
        promise.reject("E_AUTOCOMPLETE_ERROR", new Error("Error making autocomplete prediction API call: " + status.toString()));
        return;
    }
}
Also used : Status(com.google.android.gms.common.api.Status) WritableMap(com.facebook.react.bridge.WritableMap) WritableArray(com.facebook.react.bridge.WritableArray) AutocompletePredictionBuffer(com.google.android.gms.location.places.AutocompletePredictionBuffer) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) ArrayList(java.util.ArrayList) AutocompletePrediction(com.google.android.gms.location.places.AutocompletePrediction) LatLng(com.google.android.gms.maps.model.LatLng) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 27 with Status

use of com.google.android.gms.common.api.Status in project react-native-google-places by tolu360.

the class RNGooglePlacesModule method onActivityResult.

/**
 * Called after the autocomplete activity has finished to return its result.
 */
@Override
public void onActivityResult(Activity activity, final int requestCode, final int resultCode, final Intent data) {
    // Check that the result was from the autocomplete widget.
    if (requestCode == AUTOCOMPLETE_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            // Get the user's selected place from the Intent.
            Place place = PlaceAutocomplete.getPlace(this.reactContext.getApplicationContext(), data);
            Log.i(TAG, "Place Selected: " + place.getName());
            WritableMap map = propertiesMapForPlace(place);
            resolvePromise(map);
        } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
            Status status = PlaceAutocomplete.getStatus(this.reactContext.getApplicationContext(), data);
            Log.e(TAG, "Error: Status = " + status.toString());
            rejectPromise("E_RESULT_ERROR", new Error(status.toString()));
        } else if (resultCode == Activity.RESULT_CANCELED) {
            // Indicates that the activity closed before a selection was made. For example if
            // the user pressed the back button.
            rejectPromise("E_USER_CANCELED", new Error("Search cancelled"));
        }
    }
    if (requestCode == PLACE_PICKER_REQUEST_CODE) {
        if (resultCode == Activity.RESULT_OK) {
            Place place = PlacePicker.getPlace(this.reactContext.getApplicationContext(), data);
            Log.i(TAG, "Place Selected: " + place.getName());
            WritableMap map = propertiesMapForPlace(place);
            resolvePromise(map);
        }
    }
}
Also used : Status(com.google.android.gms.common.api.Status) WritableMap(com.facebook.react.bridge.WritableMap) Place(com.google.android.gms.location.places.Place)

Example 28 with Status

use of com.google.android.gms.common.api.Status in project hypertrack-live-android by hypertrack.

the class ActionManager method addGeofencingRequest.

public void addGeofencingRequest() {
    if (geofencingRequest == null) {
        return;
    }
    if (this.mGoogleAPIClient == null || !this.mGoogleAPIClient.isConnected()) {
        this.addGeofencingRequest = true;
        setupGoogleAPIClient();
        return;
    }
    try {
        Intent geofencingIntent = new Intent(mContext, GeofenceTransitionsIntentService.class);
        mGeofencePendingIntent = PendingIntent.getService(mContext, 0, geofencingIntent, PendingIntent.FLAG_UPDATE_CURRENT);
        LocationServices.GeofencingApi.addGeofences(mGoogleAPIClient, geofencingRequest, mGeofencePendingIntent).setResultCallback(new ResultCallback<Status>() {

            @Override
            public void onResult(@NonNull Status status) {
                if (status.isSuccess()) {
                    HyperLog.i(TAG, "Geofence set at Expected Place");
                    addGeofencingRequest = false;
                } else {
                    HyperLog.e(TAG, "Geofence error at Expected Place" + status.getStatusMessage());
                    addGeofencingRequest = true;
                }
            }
        });
    } catch (Exception exception) {
        HyperLog.e(TAG, "Geofence error at Expected Place" + exception.getMessage());
        CrashlyticsWrapper.log(exception);
    }
}
Also used : Status(com.google.android.gms.common.api.Status) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent)

Example 29 with Status

use of com.google.android.gms.common.api.Status in project android_packages_apps_GmsCore by microg.

the class SafetyNetClientServiceImpl method attestWithApiKey.

@Override
public void attestWithApiKey(final ISafetyNetCallbacks callbacks, final byte[] nonce, String apiKey) throws RemoteException {
    if (nonce == null) {
        callbacks.onAttestationData(new Status(CommonStatusCodes.DEVELOPER_ERROR), null);
        return;
    }
    if (!SafetyNetPrefs.get(context).isEnabled()) {
        Log.d(TAG, "ignoring SafetyNet request, it's disabled");
        callbacks.onAttestationData(Status.CANCELED, null);
        return;
    }
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                try {
                    attestation.buildPayload(nonce);
                    RemoteDroidGuardConnector conn = new RemoteDroidGuardConnector(context);
                    Bundle bundle = new Bundle();
                    bundle.putString("contentBinding", attestation.getPayloadHashBase64());
                    RemoteDroidGuardConnector.Result dg = conn.guard("attest", Long.toString(LastCheckinInfo.read(context).androidId), bundle);
                    if (!SafetyNetPrefs.get(context).isOfficial() || dg != null && dg.getStatusCode() == 0 && dg.getResult() != null) {
                        if (dg != null && dg.getStatusCode() == 0 && dg.getResult() != null) {
                            attestation.setDroidGaurdResult(Base64.encodeToString(dg.getResult(), Base64.NO_WRAP + Base64.NO_PADDING + Base64.URL_SAFE));
                        }
                        AttestationData data = new AttestationData(attestation.attest());
                        callbacks.onAttestationData(Status.SUCCESS, data);
                    } else {
                        callbacks.onAttestationData(dg == null ? Status.INTERNAL_ERROR : new Status(dg.getStatusCode()), null);
                    }
                } catch (IOException e) {
                    Log.w(TAG, e);
                    callbacks.onAttestationData(Status.INTERNAL_ERROR, null);
                }
            } catch (RemoteException e) {
                Log.w(TAG, e);
            }
        }
    }).start();
}
Also used : Status(com.google.android.gms.common.api.Status) AttestationData(com.google.android.gms.safetynet.AttestationData) RemoteDroidGuardConnector(org.microg.gms.droidguard.RemoteDroidGuardConnector) Bundle(android.os.Bundle) IOException(java.io.IOException) RemoteException(android.os.RemoteException)

Example 30 with Status

use of com.google.android.gms.common.api.Status in project android_packages_apps_GmsCore by microg.

the class PlacePickerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    resultIntent = new Intent();
    place = new PlaceImpl();
    setContentView(R.layout.pick_place);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    if (getIntent().hasExtra(EXTRA_PRIMARY_COLOR)) {
        toolbar.setBackgroundColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR, 0));
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
            getWindow().setStatusBarColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR_DARK, 0));
        ((TextView) findViewById(R.id.place_picker_title)).setTextColor(getIntent().getIntExtra(EXTRA_PRIMARY_COLOR_DARK, 0));
    }
    mapView = (BackendMapView) findViewById(R.id.map);
    mapView.map().getEventLayer().enableRotation(false);
    mapView.map().getEventLayer().enableTilt(false);
    mapView.map().events.bind(this);
    LatLngBounds latLngBounds = getIntent().getParcelableExtra(LocationConstants.EXTRA_BOUNDS);
    if (latLngBounds != null) {
        place.viewport = latLngBounds;
        MapPosition mp = new MapPosition();
        mp.setByBoundingBox(fromLatLngBounds(latLngBounds), mapView.map().getWidth(), mapView.map().getHeight());
        mapView.map().getMapPosition(mp);
    } else {
        if (ActivityCompat.checkSelfPermission(PlacePickerActivity.this, ACCESS_FINE_LOCATION) != PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(PlacePickerActivity.this, new String[] { ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION }, 0);
        } else {
            updateMapFromLocationManager();
        }
    }
    findViewById(R.id.place_picker_select).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            resultIntent.putExtra(LocationConstants.EXTRA_STATUS, SafeParcelUtil.asByteArray(new Status(CommonStatusCodes.SUCCESS)));
            resultIntent.putExtra(LocationConstants.EXTRA_PLACE, SafeParcelUtil.asByteArray(place));
            resultIntent.putExtra(LocationConstants.EXTRA_FINAL_BOUNDS, SafeParcelUtil.asByteArray(place.viewport));
            setResult(RESULT_OK, resultIntent);
            finish();
        }
    });
}
Also used : Status(com.google.android.gms.common.api.Status) PlaceImpl(com.google.android.gms.location.places.internal.PlaceImpl) LatLngBounds(com.google.android.gms.maps.model.LatLngBounds) GmsMapsTypeHelper.fromLatLngBounds(org.microg.gms.maps.GmsMapsTypeHelper.fromLatLngBounds) Intent(android.content.Intent) TextView(android.widget.TextView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) BackendMapView(org.microg.gms.maps.BackendMapView) MapPosition(org.oscim.core.MapPosition) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

Status (com.google.android.gms.common.api.Status)35 LocationRequest (com.google.android.gms.location.LocationRequest)5 LocationSettingsResult (com.google.android.gms.location.LocationSettingsResult)5 Place (com.google.android.gms.location.places.Place)5 LatLng (com.google.android.gms.maps.model.LatLng)5 Activity (android.app.Activity)4 View (android.view.View)4 GoogleApiClient (com.google.android.gms.common.api.GoogleApiClient)4 PlaceSelectionListener (com.google.android.gms.location.places.ui.PlaceSelectionListener)4 PendingIntent (android.app.PendingIntent)3 Location (android.location.Location)3 FragmentActivity (android.support.v4.app.FragmentActivity)3 WritableMap (com.facebook.react.bridge.WritableMap)3 Credential (com.google.android.gms.auth.api.credentials.Credential)3 LocationSettingsRequest (com.google.android.gms.location.LocationSettingsRequest)3 LatLngBounds (com.google.android.gms.maps.model.LatLngBounds)3 IOException (java.io.IOException)3 DialogInterface (android.content.DialogInterface)2 Intent (android.content.Intent)2 IntentSender (android.content.IntentSender)2