Search in sources :

Example 21 with Status

use of com.google.android.gms.common.api.Status in project IITB-App by wncc.

the class MapFragment method onStart.

@Override
public void onStart() {
    super.onStart();
    locationButton = (FloatingActionButton) getActivity().findViewById(R.id.location_button);
    locationButton.setImageResource(R.drawable.ic_my_location_black_24dp);
    locationButton.getDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimaryDark), PorterDuff.Mode.SRC_IN);
    locationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Log.v("MapFragment", "Location button pressed");
            try {
                LocationManager lm = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
                boolean gps_enabled = false;
                boolean network_enabled = false;
                if (ActivityCompat.checkSelfPermission(getActivity(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                    ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.ACCESS_COARSE_LOCATION }, MY_PERMISSIONS_REQUEST_LOCATION);
                    return;
                }
                try {
                    gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
                } catch (Exception ex) {
                }
                try {
                    network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                } catch (Exception ex) {
                }
                if (!gps_enabled && !network_enabled) {
                    LocationRequest locationRequest = LocationRequest.create();
                    locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
                    locationRequest.setInterval(30 * 1000);
                    locationRequest.setFastestInterval(5 * 1000);
                    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().addLocationRequest(locationRequest);
                    // **************************
                    // this is the key ingredient
                    builder.setAlwaysShow(true);
                    // **************************
                    PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi.checkLocationSettings(mGoogleApiClient, builder.build());
                    result.setResultCallback(new ResultCallback<LocationSettingsResult>() {

                        @Override
                        public void onResult(LocationSettingsResult result) {
                            final Status status = result.getStatus();
                            final LocationSettingsStates state = result.getLocationSettingsStates();
                            switch(status.getStatusCode()) {
                                case LocationSettingsStatusCodes.SUCCESS:
                                    // requests here.
                                    break;
                                case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                                    // a dialog.
                                    try {
                                        // Show the dialog by calling startResolutionForResult(),
                                        // and check the result in onActivityResult().
                                        status.startResolutionForResult(getActivity(), 1000);
                                    } catch (IntentSender.SendIntentException e) {
                                    // Ignore the error.
                                    }
                                    break;
                                case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                                    // settings so we won't show the dialog.
                                    break;
                            }
                        }
                    });
                }
                currentLocation = getLastKnownLocation();
                if (currentLocation != null) {
                    CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()), 17);
                    googleMap.animateCamera(cameraUpdate);
                    locationButton.getDrawable().setColorFilter(ContextCompat.getColor(getContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_IN);
                }
            } catch (Exception e) {
                checkLocationPermission();
                Toast.makeText(getContext(), "Please turn on Location from the Settings", Toast.LENGTH_SHORT).show();
            }
        }
    });
}
Also used : LocationManager(android.location.LocationManager) Status(com.google.android.gms.common.api.Status) ResultCallback(com.google.android.gms.common.api.ResultCallback) LocationRequest(com.google.android.gms.location.LocationRequest) LocationSettingsResult(com.google.android.gms.location.LocationSettingsResult) LocationSettingsStates(com.google.android.gms.location.LocationSettingsStates) View(android.view.View) PendingResult(com.google.android.gms.common.api.PendingResult) LatLng(com.google.android.gms.maps.model.LatLng) IntentSender(android.content.IntentSender) CameraUpdate(com.google.android.gms.maps.CameraUpdate)

Example 22 with Status

use of com.google.android.gms.common.api.Status in project braintree_android by braintree.

the class GooglePaymentExceptionTest method testGooglePaymentException_isSerializable.

@Test
public void testGooglePaymentException_isSerializable() {
    Status status = new Status(1, "Some status message");
    GooglePaymentException exception = new GooglePaymentException("Some message", status);
    Parcel parcel = Parcel.obtain();
    exception.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);
    GooglePaymentException actual = GooglePaymentException.CREATOR.createFromParcel(parcel);
    assertEquals("Some message", actual.getMessage());
    assertEquals("Some status message", actual.getStatus().getStatusMessage());
    assertEquals(1, actual.getStatus().getStatusCode());
}
Also used : Status(com.google.android.gms.common.api.Status) Parcel(android.os.Parcel) Test(org.junit.Test)

Example 23 with Status

use of com.google.android.gms.common.api.Status in project UniPool by divya21raj.

the class NewEntryActivity method onActivityResult.

// A place has been received; use requestCode to track the request.
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        Place place = PlaceAutocomplete.getPlace(this, data);
        Log.e("Tag", "Place: " + place.getAddress() + place.getPhoneNumber());
        LatLng latLng;
        switch(requestCode) {
            case 1:
                latLng = place.getLatLng();
                source = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                sourceSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                findSource.setText(sourceSet);
                break;
            case 2:
                latLng = place.getLatLng();
                destination = new GenLocation(place.getName().toString(), place.getAddress().toString(), latLng.latitude, // check
                latLng.longitude);
                destinationSet = (place.getName() + ",\n" + place.getAddress() + "\n" + // check
                place.getPhoneNumber());
                findDestination.setText(destinationSet);
                break;
        }
    } else if (resultCode == PlaceAutocomplete.RESULT_ERROR) {
        Status status = PlaceAutocomplete.getStatus(this, data);
        // TODO: Handle the error.
        Log.e("Tag", status.getStatusMessage());
    } else if (resultCode == RESULT_CANCELED) {
    // The user canceled the operation.
    // Toast.makeText(getApplicationContext(), "Cancelled...", Toast.LENGTH_SHORT).show();
    }
}
Also used : Status(com.google.android.gms.common.api.Status) LatLng(com.google.android.gms.maps.model.LatLng) GenLocation(garbagecollectors.com.unipool.GenLocation) Place(com.google.android.gms.location.places.Place)

Example 24 with Status

use of com.google.android.gms.common.api.Status in project butter-android by butterproject.

the class CastService method playMedia.

private void playMedia(final com.google.android.gms.cast.MediaInfo mediaInformation, final String mediaAppId, final LaunchListener listener) {
    final ApplicationConnectionResultCallback webAppLaunchCallback = new ApplicationConnectionResultCallback(new LaunchWebAppListener() {

        @Override
        public void onSuccess(final WebAppSession webAppSession) {
            ConnectionListener connectionListener = new ConnectionListener() {

                @Override
                public void onConnected() {
                    try {
                        mMediaPlayer.load(mApiClient, mediaInformation, true).setResultCallback(new ResultCallback<RemoteMediaPlayer.MediaChannelResult>() {

                            @Override
                            public void onResult(MediaChannelResult result) {
                                Status status = result.getStatus();
                                if (status.isSuccess()) {
                                    webAppSession.launchSession.setSessionType(LaunchSessionType.Media);
                                    // White text, black outline, no background
                                    TextTrackStyle textTrackStyle = new TextTrackStyle();
                                    textTrackStyle.setForegroundColor(Color.parseColor("#FFFFFFFF"));
                                    textTrackStyle.setBackgroundColor(Color.parseColor("#01000000"));
                                    textTrackStyle.setWindowType(TextTrackStyle.WINDOW_TYPE_NONE);
                                    textTrackStyle.setEdgeType(TextTrackStyle.EDGE_TYPE_OUTLINE);
                                    textTrackStyle.setEdgeColor(Color.BLACK);
                                    textTrackStyle.setFontGenericFamily(TextTrackStyle.FONT_FAMILY_SANS_SERIF);
                                    mMediaPlayer.setTextTrackStyle(mApiClient, textTrackStyle);
                                    mMediaPlayer.setActiveMediaTracks(mApiClient, new long[] { 1 });
                                    Util.postSuccess(listener, new MediaLaunchObject(webAppSession.launchSession, CastService.this));
                                } else {
                                    Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
                                }
                            }
                        });
                    } catch (Exception e) {
                        Util.postError(listener, new ServiceCommandError(0, "Unable to load", null));
                    }
                }
            };
            runCommand(connectionListener);
        }

        @Override
        public void onFailure(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    });
    launchingAppId = mediaAppId;
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            boolean relaunchIfRunning = false;
            try {
                if (Cast.CastApi.getApplicationStatus(mApiClient) == null || (!mediaAppId.equals(currentAppId))) {
                    relaunchIfRunning = true;
                }
                LaunchOptions options = new LaunchOptions();
                options.setRelaunchIfRunning(relaunchIfRunning);
                Cast.CastApi.launchApplication(mApiClient, mediaAppId, options).setResultCallback(webAppLaunchCallback);
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to launch", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : Status(com.google.android.gms.common.api.Status) ResultCallback(com.google.android.gms.common.api.ResultCallback) RemoteMediaPlayer(com.google.android.gms.cast.RemoteMediaPlayer) WebAppSession(com.connectsdk.service.sessions.WebAppSession) CastWebAppSession(com.connectsdk.service.sessions.CastWebAppSession) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) IOException(java.io.IOException) LaunchOptions(com.google.android.gms.cast.LaunchOptions) TextTrackStyle(com.google.android.gms.cast.TextTrackStyle) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult)

Example 25 with Status

use of com.google.android.gms.common.api.Status in project butter-android by butterproject.

the class CastService method seek.

@Override
public void seek(final long position, final ResponseListener<Object> listener) {
    if (mMediaPlayer == null || mMediaPlayer.getMediaStatus() == null) {
        Util.postError(listener, new ServiceCommandError(0, "There is no media currently available", null));
        return;
    }
    ConnectionListener connectionListener = new ConnectionListener() {

        @Override
        public void onConnected() {
            try {
                mMediaPlayer.seek(mApiClient, position, RemoteMediaPlayer.RESUME_STATE_UNCHANGED).setResultCallback(new ResultCallback<MediaChannelResult>() {

                    @Override
                    public void onResult(MediaChannelResult result) {
                        Status status = result.getStatus();
                        if (status.isSuccess()) {
                            Util.postSuccess(listener, null);
                        } else {
                            Util.postError(listener, new ServiceCommandError(status.getStatusCode(), status.getStatusMessage(), status));
                        }
                    }
                });
            } catch (Exception e) {
                Util.postError(listener, new ServiceCommandError(0, "Unable to seek", null));
            }
        }
    };
    runCommand(connectionListener);
}
Also used : Status(com.google.android.gms.common.api.Status) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) MediaChannelResult(com.google.android.gms.cast.RemoteMediaPlayer.MediaChannelResult) IOException(java.io.IOException)

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