Example usage for org.apache.cordova CallbackContext CallbackContext

List of usage examples for org.apache.cordova CallbackContext CallbackContext

Introduction

In this page you can find the example usage for org.apache.cordova CallbackContext CallbackContext.

Prototype

public CallbackContext(String callbackId, CordovaWebView webView) 

Source Link

Usage

From source file:com.kanayo.tts.TTS.java

License:Open Source License

@Override
public void initialize(CordovaInterface cordova, final CordovaWebView webView) {
    tts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this);
    tts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
        @Override/*from  ww w .  jav a2s .com*/
        public void onStart(String s) {
            // do nothing
        }

        @Override
        public void onDone(String callbackId) {
            if (!callbackId.equals("")) {
                CallbackContext context = new CallbackContext(callbackId, webView);
                context.success();
            }
        }

        @Override
        public void onError(String callbackId) {
            if (!callbackId.equals("")) {
                CallbackContext context = new CallbackContext(callbackId, webView);
                context.error(ERR_UNKNOWN);
            }
        }
    });
}

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

private void _onActivityResultLocationPage(Bundle bundle) {
    String callbackId = bundle.getString("callbackId");
    CallbackContext callbackContext = new CallbackContext(callbackId, this.webView);

    LocationManager locationManager = (LocationManager) this.activity
            .getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    int availableProviders = 0;
    if (mPluginLayout != null && mPluginLayout.isDebug) {
        Log.d(TAG, "---debug at getMyLocation(available providers)--");
    }//from  www.  ja v a  2 s.  c om
    Iterator<String> iterator = providers.iterator();
    String provider;
    boolean isAvailable;
    while (iterator.hasNext()) {
        provider = iterator.next();
        isAvailable = locationManager.isProviderEnabled(provider);
        if (isAvailable) {
            availableProviders++;
        }
        if (mPluginLayout != null && mPluginLayout.isDebug) {
            Log.d(TAG, "   " + provider + " = " + (isAvailable ? "" : "not ") + "available");
        }
    }
    if (availableProviders == 0) {
        JSONObject result = new JSONObject();
        try {
            result.put("status", false);
            result.put("error_code", "not_available");
            result.put("error_message",
                    "Since this device does not have any location provider, this app can not detect your location.");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        callbackContext.error(result);
        return;
    }

    _inviteLocationUpdateAfterActivityResult(bundle);
}

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

private void _inviteLocationUpdateAfterActivityResult(Bundle bundle) {
    boolean enableHighAccuracy = bundle.getBoolean("enableHighAccuracy");
    String callbackId = bundle.getString("callbackId");
    CallbackContext callbackContext = new CallbackContext(callbackId, this.webView);
    this._requestLocationUpdate(false, enableHighAccuracy, callbackContext);
}

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

private void _userRefusedToUseLocationAfterActivityResult(Bundle bundle) {
    String callbackId = bundle.getString("callbackId");
    CallbackContext callbackContext = new CallbackContext(callbackId, this.webView);
    JSONObject result = new JSONObject();
    try {/*ww  w. j  a va 2  s  . c  om*/
        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);
}

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

private void _onActivityResultLocationPage(Bundle bundle) {
    String callbackId = bundle.getString("callbackId");
    CallbackContext callbackContext = new CallbackContext(callbackId, this.webView);

    LocationManager locationManager = (LocationManager) this.activity
            .getSystemService(Context.LOCATION_SERVICE);
    List<String> providers = locationManager.getAllProviders();
    int availableProviders = 0;
    if (isDebug) {
        Log.d("CordovaLog", "---debug at getMyLocation(available providers)--");
    }/*  w  w  w.  j  av a 2s .  co  m*/
    Iterator<String> iterator = providers.iterator();
    String provider;
    boolean isAvailable = false;
    while (iterator.hasNext()) {
        provider = iterator.next();
        isAvailable = locationManager.isProviderEnabled(provider);
        if (isAvailable) {
            availableProviders++;
        }
        if (isDebug) {
            Log.d("CordovaLog", "   " + provider + " = " + (isAvailable ? "" : "not ") + "available");
        }
    }
    if (availableProviders == 0) {
        JSONObject result = new JSONObject();
        try {
            result.put("status", false);
            result.put("error_code", "not_available");
            result.put("error_message",
                    "Since this device does not have any location provider, this app can not detect your location.");
        } catch (JSONException e) {
        }
        callbackContext.error(result);
        return;
    }

    _inviteLocationUpdateAfterActivityResult(bundle);
}

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

private void _userRefusedToUseLocationAfterActivityResult(Bundle bundle) {
    String callbackId = bundle.getString("callbackId");
    CallbackContext callbackContext = new CallbackContext(callbackId, this.webView);
    JSONObject result = new JSONObject();
    try {// w  w  w .java  2  s.c o  m
        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) {
    }
    callbackContext.error(result);
}