Example usage for android.os Bundle hashCode

List of usage examples for android.os Bundle hashCode

Introduction

In this page you can find the example usage for android.os Bundle hashCode.

Prototype

@HotSpotIntrinsicCandidate
public native int hashCode();

Source Link

Document

Returns a hash code value for the object.

Usage

From source file:plugin.google.maps.CordovaGoogleMaps.java

private void _showLocationSettingsPage(final boolean enableHighAccuracy,
        final CallbackContext callbackContext) {
    //Ask the user to turn on the location services.
    AlertDialog.Builder builder = new AlertDialog.Builder(this.activity);
    builder.setTitle("Improve location accuracy");
    builder.setMessage("To enhance your Maps experience:\n\n" + " - Enable Google apps location access\n\n"
            + " - Turn on GPS and mobile network location");
    builder.setPositiveButton("Settings", new DialogInterface.OnClickListener() {
        @Override//from www .  j  av a 2 s  . c om
        public void onClick(DialogInterface dialog, int which) {
            //Keep the callback id
            Bundle bundle = new Bundle();
            bundle.putInt("type", ACTIVITY_LOCATION_PAGE);
            bundle.putString("callbackId", callbackContext.getCallbackId());
            bundle.putBoolean("enableHighAccuracy", enableHighAccuracy);
            int hashCode = bundle.hashCode();

            bufferForLocationDialog.put("bundle_" + hashCode, bundle);
            CordovaGoogleMaps.this.sendNoResult(callbackContext);

            //Launch settings, allowing user to make a change
            cordova.setActivityResultCallback(CordovaGoogleMaps.this);
            Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
            activity.startActivityForResult(intent, hashCode);
        }
    });
    builder.setNegativeButton("Skip", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            //No location service, no Activity
            dialog.dismiss();

            JSONObject result = new JSONObject();
            try {
                result.put("status", false);
                result.put("error_code", "service_denied");
                result.put("error_message", "This app has been rejected to use Location Services.");
            } catch (JSONException e) {
                e.printStackTrace();
            }
            callbackContext.error(result);
        }
    });
    builder.create().show();
}

From source file:plugin.google.maps.CordovaGoogleMaps.java

private void _checkLocationSettings(final boolean enableHighAccuracy, final CallbackContext callbackContext) {

    LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder().setAlwaysShow(true);

    LocationRequest locationRequest;/*from  w  w  w.  j  a  v  a  2 s . c  o m*/
    locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY);
    builder.addLocationRequest(locationRequest);

    if (enableHighAccuracy) {
        locationRequest = LocationRequest.create().setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        builder.addLocationRequest(locationRequest);
    }

    PendingResult<LocationSettingsResult> locationSettingsResult = LocationServices.SettingsApi
            .checkLocationSettings(googleApiClient, builder.build());

    locationSettingsResult.setResultCallback(new ResultCallback<LocationSettingsResult>() {

        @Override
        public void onResult(@NonNull LocationSettingsResult result) {
            final Status status = result.getStatus();
            switch (status.getStatusCode()) {
            case LocationSettingsStatusCodes.SUCCESS:
                _requestLocationUpdate(false, enableHighAccuracy, callbackContext);
                break;

            case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
                // Location settings are not satisfied. But could be fixed by showing the user
                // a dialog.
                try {
                    //Keep the callback id
                    Bundle bundle = new Bundle();
                    bundle.putInt("type", ACTIVITY_LOCATION_DIALOG);
                    bundle.putString("callbackId", callbackContext.getCallbackId());
                    bundle.putBoolean("enableHighAccuracy", enableHighAccuracy);
                    int hashCode = bundle.hashCode();

                    bufferForLocationDialog.put("bundle_" + hashCode, bundle);
                    CordovaGoogleMaps.this.sendNoResult(callbackContext);

                    // Show the dialog by calling startResolutionForResult(),
                    // and check the result in onActivityResult().
                    cordova.setActivityResultCallback(CordovaGoogleMaps.this);
                    status.startResolutionForResult(cordova.getActivity(), hashCode);
                } catch (SendIntentException e) {
                    // Show the dialog that is original version of this plugin.
                    _showLocationSettingsPage(enableHighAccuracy, callbackContext);
                }
                break;

            case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
                // Location settings are not satisfied. However, we have no way to fix the
                // settings so we won't show the dialog.

                JSONObject jsResult = new JSONObject();
                try {
                    jsResult.put("status", false);
                    jsResult.put("error_code", "service_not_available");
                    jsResult.put("error_message", "This app has been rejected to use Location Services.");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                callbackContext.error(jsResult);
                break;
            }
        }

    });
}