Search in sources :

Example 1 with CallbackContext

use of org.apache.cordova.api.CallbackContext in project cordova-android-chromeview by thedracle.

the class CordovaLocationListener method fail.

protected void fail(int code, String message) {
    this.cancelTimer();
    for (CallbackContext callbackContext : this.callbacks) {
        this.owner.fail(code, message, callbackContext, false);
    }
    if (this.owner.isGlobalListener(this) && this.watches.size() == 0) {
        Log.d(TAG, "Stopping global listener");
        this.stop();
    }
    this.callbacks.clear();
    Iterator<CallbackContext> it = this.watches.values().iterator();
    while (it.hasNext()) {
        this.owner.fail(code, message, it.next(), true);
    }
}
Also used : CallbackContext(org.apache.cordova.api.CallbackContext)

Example 2 with CallbackContext

use of org.apache.cordova.api.CallbackContext in project cordova-android-chromeview by thedracle.

the class CordovaLocationListener method win.

private void win(Location loc) {
    this.cancelTimer();
    for (CallbackContext callbackContext : this.callbacks) {
        this.owner.win(loc, callbackContext, false);
    }
    if (this.owner.isGlobalListener(this) && this.watches.size() == 0) {
        Log.d(TAG, "Stopping global listener");
        this.stop();
    }
    this.callbacks.clear();
    Iterator<CallbackContext> it = this.watches.values().iterator();
    while (it.hasNext()) {
        this.owner.win(loc, it.next(), true);
    }
}
Also used : CallbackContext(org.apache.cordova.api.CallbackContext)

Example 3 with CallbackContext

use of org.apache.cordova.api.CallbackContext in project cordova-android-chromeview by thedracle.

the class BatteryListener method execute.

/**
     * Executes the request.
     *
     * @param action        	The action to execute.
     * @param args          	JSONArry of arguments for the plugin.
     * @param callbackContext 	The callback context used when calling back into JavaScript.
     * @return              	True if the action was valid, false if not.
     */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
    if (action.equals("start")) {
        if (this.batteryCallbackContext != null) {
            callbackContext.error("Battery listener already running.");
            return true;
        }
        this.batteryCallbackContext = callbackContext;
        // We need to listen to power events to update battery status
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
        if (this.receiver == null) {
            this.receiver = new BroadcastReceiver() {

                @Override
                public void onReceive(Context context, Intent intent) {
                    updateBatteryInfo(intent);
                }
            };
            cordova.getActivity().registerReceiver(this.receiver, intentFilter);
        }
        // Don't return any result now, since status results will be sent when events come in from broadcast receiver
        PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
        pluginResult.setKeepCallback(true);
        callbackContext.sendPluginResult(pluginResult);
        return true;
    } else if (action.equals("stop")) {
        removeBatteryListener();
        // release status callback in JS side
        this.sendUpdate(new JSONObject(), false);
        this.batteryCallbackContext = null;
        callbackContext.success();
        return true;
    }
    return false;
}
Also used : Context(android.content.Context) CallbackContext(org.apache.cordova.api.CallbackContext) IntentFilter(android.content.IntentFilter) PluginResult(org.apache.cordova.api.PluginResult) JSONObject(org.json.JSONObject) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver)

Aggregations

CallbackContext (org.apache.cordova.api.CallbackContext)3 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 PluginResult (org.apache.cordova.api.PluginResult)1 JSONObject (org.json.JSONObject)1