Android Open Source - incubator-cordova-android Plugin






From Project

Back to project page incubator-cordova-android.

License

The source code is released under:

Apache License

If you think the Android project incubator-cordova-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
       Licensed to the Apache Software Foundation (ASF) under one
       or more contributor license agreements.  See the NOTICE file
       distributed with this work for additional information
       regarding copyright ownership.  The ASF licenses this file
       to you under the Apache License, Version 2.0 (the
       "License"); you may not use this file except in compliance
       with the License.  You may obtain a copy of the License at
/*from  w w w .j a  v  a  2  s  .  c o m*/
         http://www.apache.org/licenses/LICENSE-2.0

       Unless required by applicable law or agreed to in writing,
       software distributed under the License is distributed on an
       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
       KIND, either express or implied.  See the License for the
       specific language governing permissions and limitations
       under the License.
*/
package org.apache.cordova.api;

import org.apache.cordova.CordovaWebView;
import org.json.JSONArray;
import org.json.JSONObject;
import android.content.Intent;

/**
 * Plugin interface must be implemented by any plugin classes.
 *
 * The execute method is called by the PluginManager.
 */
public abstract class Plugin implements IPlugin {

    public String id;
    public CordovaWebView webView;          // WebView object
    public LegacyContext    ctx;              // LegacyContext object
    public CordovaInterface cordova;

    /**
     * Executes the request and returns PluginResult.
     *
     * @param action     The action to execute.
     * @param args       JSONArry of arguments for the plugin.
     * @param callbackId  The callback id used when calling back into JavaScript.
     * @return         A PluginResult object with a status and message.
     */
    public abstract PluginResult execute(String action, JSONArray args, String callbackId);

    /**
     * Identifies if action to be executed returns a value and should be run synchronously.
     *
     * @param action  The action to execute
     * @return      T=returns value
     */
    public boolean isSynch(String action) {
        return false;
    }

    /**
     * Sets the context of the Plugin. This can then be used to do things like
     * get file paths associated with the Activity.
     *
     * @param ctx The context of the main Activity.
     */
    public void setContext(CordovaInterface ctx) {
        this.cordova = ctx;
        this.ctx = new LegacyContext(cordova);
    }

    /**
     * Sets the main View of the application, this is the WebView within which
     * a Cordova app runs.
     *
     * @param webView The Cordova WebView
     */
    public void setView(CordovaWebView webView) {
        this.webView = webView;
    }

    /**
     * Called when the system is about to start resuming a previous activity.
     *
     * @param multitasking    Flag indicating if multitasking is turned on for app
     */
    public void onPause(boolean multitasking) {
    }

    /**
     * Called when the activity will start interacting with the user.
     *
     * @param multitasking    Flag indicating if multitasking is turned on for app
     */
    public void onResume(boolean multitasking) {
    }

    /**
     * Called when the activity receives a new intent.
     */
    public void onNewIntent(Intent intent) {
    }

    /**
     * The final call you receive before your activity is destroyed.
     */
    public void onDestroy() {
    }

    /**
     * Called when a message is sent to plugin.
     *
     * @param id            The message id
     * @param data          The message data
     * @return              Object to stop propagation or null
     */
    public Object onMessage(String id, Object data) {
        return null;
    }

    /**
     * Called when an activity you launched exits, giving you the requestCode you started it with,
     * the resultCode it returned, and any additional data from it.
     *
     * @param requestCode    The request code originally supplied to startActivityForResult(),
     *               allowing you to identify who this result came from.
     * @param resultCode    The integer result code returned by the child activity through its setResult().
     * @param data        An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
     */
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
    }

    /**
     * By specifying a <url-filter> in plugins.xml you can map a URL (using startsWith atm) to this method.
     *
     * @param url        The URL that is trying to be loaded in the Cordova webview.
     * @return          Return true to prevent the URL from loading. Default is false.
     */
    public boolean onOverrideUrlLoading(String url) {
        return false;
    }

    /**
     * Send generic JavaScript statement back to JavaScript.
     * success(...) and error(...) should be used instead where possible.
     *
     * @param statement
     */
    public void sendJavascript(String statement) {
        this.webView.sendJavascript(statement);
    }

    /**
     * Call the JavaScript success callback for this plugin.
     *
     * This can be used if the execute code for the plugin is asynchronous meaning
     * that execute should return null and the callback from the async operation can
     * call success(...) or error(...)
     *
     * @param pluginResult    The result to return.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void success(PluginResult pluginResult, String callbackId) {
        this.webView.sendJavascript(pluginResult.toSuccessCallbackString(callbackId));
    }

    /**
     * Helper for success callbacks that just returns the Status.OK by default
     *
     * @param message      The message to add to the success result.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void success(JSONObject message, String callbackId) {
        this.webView.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
    }

    /**
     * Helper for success callbacks that just returns the Status.OK by default
     *
     * @param message      The message to add to the success result.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void success(String message, String callbackId) {
        this.webView.sendJavascript(new PluginResult(PluginResult.Status.OK, message).toSuccessCallbackString(callbackId));
    }

    /**
     * Call the JavaScript error callback for this plugin.
     *
     * @param pluginResult    The result to return.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void error(PluginResult pluginResult, String callbackId) {
        this.webView.sendJavascript(pluginResult.toErrorCallbackString(callbackId));
    }

    /**
     * Helper for error callbacks that just returns the Status.ERROR by default
     *
     * @param message      The message to add to the error result.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void error(JSONObject message, String callbackId) {
        this.webView.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
    }

    /**
     * Helper for error callbacks that just returns the Status.ERROR by default
     *
     * @param message      The message to add to the error result.
     * @param callbackId    The callback id used when calling back into JavaScript.
     */
    public void error(String message, String callbackId) {
        this.webView.sendJavascript(new PluginResult(PluginResult.Status.ERROR, message).toErrorCallbackString(callbackId));
    }
}




Java Source Code List

com.phonegap.api.IPlugin.java
com.phonegap.api.LOG.java
com.phonegap.api.PhonegapActivity.java
com.phonegap.api.PluginManager.java
com.phonegap.api.PluginResult.java
com.phonegap.api.Plugin.java
org.apache.cordova.AccelListener.java
org.apache.cordova.App.java
org.apache.cordova.AudioHandler.java
org.apache.cordova.AudioPlayer.java
org.apache.cordova.AuthenticationToken.java
org.apache.cordova.BatteryListener.java
org.apache.cordova.CallbackServer.java
org.apache.cordova.CameraLauncher.java
org.apache.cordova.Capture.java
org.apache.cordova.CompassListener.java
org.apache.cordova.ContactAccessorSdk5.java
org.apache.cordova.ContactAccessor.java
org.apache.cordova.ContactManager.java
org.apache.cordova.CordovaChromeClient.java
org.apache.cordova.CordovaLocationListener.java
org.apache.cordova.CordovaWebViewClient.java
org.apache.cordova.CordovaWebView.java
org.apache.cordova.Device.java
org.apache.cordova.DirectoryManager.java
org.apache.cordova.DroidGap.java
org.apache.cordova.ExifHelper.java
org.apache.cordova.FileTransfer.java
org.apache.cordova.FileUploadResult.java
org.apache.cordova.FileUtils.java
org.apache.cordova.GPSListener.java
org.apache.cordova.GeoBroker.java
org.apache.cordova.HttpHandler.java
org.apache.cordova.LinearLayoutSoftKeyboardDetect.java
org.apache.cordova.NetworkListener.java
org.apache.cordova.NetworkManager.java
org.apache.cordova.Notification.java
org.apache.cordova.SplashScreen.java
org.apache.cordova.StandAlone.java
org.apache.cordova.Storage.java
org.apache.cordova.TempListener.java
org.apache.cordova.api.CordovaInterface.java
org.apache.cordova.api.IPlugin.java
org.apache.cordova.api.LOG.java
org.apache.cordova.api.LegacyContext.java
org.apache.cordova.api.PluginEntry.java
org.apache.cordova.api.PluginManager.java
org.apache.cordova.api.PluginResult.java
org.apache.cordova.api.Plugin.java
org.apache.cordova.file.EncodingException.java
org.apache.cordova.file.FileExistsException.java
org.apache.cordova.file.InvalidModificationException.java
org.apache.cordova.file.NoModificationAllowedException.java
org.apache.cordova.file.TypeMismatchException.java