Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D30FC100F0 for ; Tue, 9 Apr 2013 22:36:00 +0000 (UTC) Received: (qmail 52191 invoked by uid 500); 9 Apr 2013 22:36:00 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 52167 invoked by uid 500); 9 Apr 2013 22:36:00 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 52159 invoked by uid 99); 9 Apr 2013 22:36:00 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Apr 2013 22:36:00 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 09 Apr 2013 22:35:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 470D72388C28; Tue, 9 Apr 2013 22:34:43 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: svn commit: r1466271 [15/41] - in /cordova/site: bin/ public/ public/docs/en/2.6.0/ public/docs/en/2.6.0/img/ public/docs/en/2.6.0/img/guide/ public/docs/en/2.6.0/img/guide/getting-started/ public/docs/en/2.6.0/img/guide/getting-started/android/ public... Date: Tue, 09 Apr 2013 22:34:33 -0000 To: commits@cordova.apache.org From: steven@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20130409223443.470D72388C28@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: cordova/site/public/docs/en/2.6.0/guide_getting-started_webos_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_getting-started_webos_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_getting-started_webos_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_getting-started_webos_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,201 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Getting Started with WebOS

+ +
+ + + +
+
+

Getting Started with WebOS

+ +

This guide describes how to set up your development environment for Cordova and run a sample application. Note that Cordova used to be called PhoneGap, so some of the sites still use the old PhoneGap name.

+ +

+Video Tutorials: +

+ + +

+1. Requirements +

+ +
    +
  • Windows, OS X, or Linux
  • +
+

+2. Install SDK + Cordova +

+ +
    +
  • Download and install Virtual Box +
  • +
  • Download and install WebOS SDK +
  • +
  • Download and install cygwin SDK (Windows only). Make sure you select "make" as it is not included by default
  • +
  • Download the latest copy of Cordova and extract its contents. We will be working with the webOS directory.
  • +
  • Download and install XCode from the Mac App Store (OSX only)
  • +
  • Download and install Command Line Tools for XCode (OSX only); this can be done by going to XCode's Preferences -> Downloads -> Components and then click install on Command Line Tools
  • +
+

+3. Setup New Project +

+ +
    +
  • Open up terminal/cygwin and navigate to where you extracted your Cordova Download. Go into the webOS directory.
  • +
+

+4. Hello World +

+ +

In phonegap/webOS/framework/www, open up index.html with your favourite editor. After the body tag add <h1>Hello World</h1>

+ +

+5A. Deploy to Simulator +

+ +
    +
  • Open up your Palm Emulator from your applications folder/start menu.
  • +
  • Type make in your terminal/cygwin while in the webOS directory.
  • +
+

+5B. Deploy to Device + +

+ + +

+Done! +

+ +

You can also checkout more detailed version of this guide here.

+ +
+
+ + + + + Added: cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-8_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-8_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-8_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-8_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,226 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Getting Started with Windows 8

+ +
+ + + +
+
+

Getting Started with Windows 8

+ +

This guide describes how to set up your development environment for Cordova and run a sample application. Note that Cordova used to be called PhoneGap, so some of the sites still use the old PhoneGap name.

+ +

During development of Windows 8 and Windows RT, Microsoft deprecated the name "Metro-style apps". On MSDN, this type of app is now called a "Windows Store" app. That's the name that we'll use in this guide. Also in this guide whenever we refer to Windows 8, you should take that to mean both Windows 8 and Windows RT.

+ +

+1. Requirements +

+ +
    +
  • Windows 8

  • +
  • Visual Studio 2012 Professional or better, or Visual Studio 2012 Express for Windows 8

  • +
+

Follow the instructions here to submit your apps Windows Store.

+ +

+2. Install SDK + Cordova +

+ +
    +
  • Setup your preferred variant of Visual Studio 2012. All of the paid versions of the product (Professional, etc) let you build Windows Store apps. To build Windows Store apps using the Express editions, you will need Express for Windows 8.
  • +
  • Download the latest copy of Cordova and extract its contents. We will be working with the subfolder lib\windows-8.
  • +
+

+3. Setup New Project +

+ +

You can already build Windows 8 apps using the "HTML/JavaScript track" available in Windows Store apps. The purpose of Cordova in Windows Store apps is to expose the same APIs used on all the other Cordova platforms.

+ +
    +
  • Open Visual Studio 2012 and choose New Project.
  • +
  • +

    Select Installed - Template - Other Languages - JavaScript - Windows Store from the tree, and then Blank App from the projects list. Enter whatever project name you like. We're using CordovaWin8Foo in this guide.

    + +

    +
  • +
  • +

    Microsoft continues to use default.html as the default page for use in websites, whereas most "open web" developers use index.html. (Plus it's likely that in the other platform variants of your project you are using index.html as the name of your default page.) To fix this, in Solution Explorer rename the default.html file to index.html. Then double-click the package.appxmanifest file and change the Start page value to index.html.

    + +

    +
  • +
  • To include cordova.js in your project, right-click on the js folder in Solution Explorer and select Add - New Item. Locate the cordova.js file in the lib\windows-8 folder that we called out previously.

  • +
  • Edit the code for index.html. Add a reference to cordova.js. You can do this manually, or by dragging the file from Solution Explorer.

  • +
+

Adding the reference...

+ +
    <!-- WinJS references -->
+    <link href="//Microsoft.WinJS.1.0/css/ui-dark.css" rel="stylesheet" />
+    <script src="//Microsoft.WinJS.1.0/js/base.js"></script>
+    <script src="//Microsoft.WinJS.1.0/js/ui.js"></script>
+
+    <!-- Cordova -->
+    <script src="/js/cordova.js"></script>
+
+    <!-- CordovaWin8Foo references -->
+    <link href="/css/default.css" rel="stylesheet" />
+    <script src="/js/default.js"></script>
+
+ +
    +
  • Next we want to add some code that will demonstrate that Cordova is working.
  • +
+

Adding a 'deviceready' handler...

+ +
<body>
+    <p>Content goes here</p>
+
+    <script type="text/javascript">
+
+        console.log("Subscribing...");
+        document.addEventListener("deviceready", function () {
+
+            navigator.notification.alert("The device is ready!");
+
+        });
+
+    </script>
+
+</body>
+
+ +

+5. Test the Project +

+ +
    +
  • +

    Run the project from Visual Studio. You'll see the message box appear.

    + +

    +
  • +
+

+Done! +

+ +

That's it! You're now ready to build Windows Store apps with Cordova.

+ +
+
+ + + + + Added: cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-7_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-7_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-7_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-7_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,244 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Getting Started with Windows Phone 7

+ +
+ + + +
+
+

Getting Started with Windows Phone 7

+ +

This guide describes how to set up your development environment for Cordova and run a sample application. Note that Cordova used to be called PhoneGap, so some of the sites still use the old PhoneGap name.

+ +

+Video Tutorials: +

+ + +

+1. Requirements +

+ +
    +
  • Windows 7 or Windows Vista with SP2
  • +
+

Note: Running in VM has issues, if you are on a Mac, you will need to setup a bootcamp partition with Windows 7 or Vista

+ +

Necessary for Installing on Device and Submitting to Market Place:

+ + +

+2. Install SDK + Cordova +

+ +
    +
  • Download and install Windows Phone SDK +
  • +
  • Download the latest copy of Cordova and extract its contents. We will be working with the subfolder: lib\windows-phone\
  • +
  • copy the file CordovaStarter-x.x.x.zip to the folder : \My Documents\Visual Studio 2010\Templates\ProjectTemplates\ +( if the template file does not exist, you will need to build it. See 2.1 below ) +if you have just installed VisualStudio, you should launch it once to create this folder +if you prefer, you may add the project instead to the "Silverlight for Windows Phone" subfolder of "Visual C#". This is up to you, and only affects where the project template is shown when creating a new project. Also, You may need to create this folder.
  • +
+

+2.1. Building the template +

+ +

( note, this step may not be required. If the lib\windows-phone directory already contains a file CordovaStarter-x.x.x.zip then you may skip this step ) +- Open the file lib\windows-phone\templates\standalone\CordovaSolution.sln in Visual Studio Express for Windows Phone +- From the file menu, select 'Export Template...' +- Choose template type 'Project template' +- Give the exported template a name, ex. CordovaStarter-2.1.0 will produce CordovaStarter-2.1.0.zip +- Optionally, you may add a description, icon image, and Preview image. These are what is displayed in Visual Studio in the 'New Project' dialog.- +- Note: If you select ( 'Automatically import the template ... ') then you will not need to copy the .zip file over as outlined in step 2. +- Press 'Finish'

+ +

+3. Setup New Project +

+ +
    +
  • Open Visual Studio Express for Windows Phone and choose New Project.
  • +
  • Select CordovaStarter. ( the version number will be displayed in the template description )
  • +
    • +
    • note: If you do not see it, you may have to select the top level 'Visual C#' to see it
    • +
  • +
  • +

    Give your project a name, and select OK.

    + +

    +
  • +
+

+4. Review the project structure +

+ +
    +
  • The 'www' folder contains your Cordova html/js/css and any other resources included in your app.
  • +
  • +

    Any content that you add here needs to be a part of the Visual Studio project, and it must be set as content.

    + +

    +
  • +
+

+5. Build and Deploy to Emulator +

+ +
    +
  • Make sure to have Windows Phone Emulator selected in the top drop-down menu.
  • +
  • +

    Hit the green play button beside the Windows Phone Emulator drop-down menu to start debugging or press F5.

    + +

    +
  • +
+

+6. Build your project for the device +

+ +

In order to test your application on a device, the device must be registered. Click here.aspx) to read documentation on deploying and testing on your Windows Phone.

+ +
    +
  • Make sure your phone is connected, and the screen is unlocked
  • +
  • In Visual Studio, select 'Windows Phone Device' from the top drop-down menu.
  • +
  • +

    Hit the green play button beside the drop-down menu to start debugging or press F5.

    + +

    +
  • +
+

+Done! +

+ +

You can also checkout more detailed version of this guide here.

+ +
+
+ + + + + Added: cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-8_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-8_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-8_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_getting-started_windows-phone-8_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,281 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Getting Started with Windows Phone 8

+ +
+ + + +
+
+

Getting Started with Windows Phone 8

+ +

This guide describes how to set up your development environment for Cordova and run a sample application. Note that Cordova used to be called PhoneGap, so some of the sites still use the old PhoneGap name.

+ +

Note: Applications built with Apache Cordova for Windows Phone 8 will only run on Windows Phone 8 devices. If you are looking to target both 7.5 AND 8 devices, then you should be using Apache Cordova for Windows Phone 7, which does not have all the new shiny features included in IE10, but implements the same APIs.

+ +

+1. System Requirements +

+ +
    +
  • +

    Operating System:

    + +
      +
    • Windows 8 or Windows 8 Pro +
        +
      • The 64-bit version (x64) of Windows is required for the SDK.
      • +
      • The Pro version is recommended so you can run a device emulator.
      • +
      +
    • +
    +
  • +
  • +

    Hardware:

    + +
      +
    • 6.5 GB of free hard disk space
    • +
    • 4 GB RAM
    • +
    • 64-bit (x64) CPU
    • +
    +
  • +
  • +

    Windows Phone 8 Emulator

    + + +
  • +
  • +

    SDK + IDE ( Visual Studio )

    + +
      +
    • Visual Studio 2012 Professional, Premium, or Ultimate. Note that Visual Studio Express for Windows Phone (included in the SDK) is not recommended because you can not build the template (see below) with VS Express, as it does not have the "Export Template" functionality, which is only in VS Pro or higher.
    • +
    +
  • +
  • Register and pay for a Windows Phone Dev Center account if you want to install your app on a real device and/or submit it to Market Place.

  • +
+

Note: Running the SDK in Virtual Machine might present some challenges. You can read this blog post that gives insight on the solutions to develop for Windows Phone on a Mac.

+ +

+2. Install SDK + Cordova +

+ +
    +
  • Download and install Windows Phone SDK +
  • +
  • Download the latest copy of Cordova and extract its contents. We will be working with the subfolder: lib\windows-phone-8\
  • +
  • copy the file CordovaWP8AppFull-x.x.x.zip to the folder : \My Documents\Visual Studio 2012\Templates\ProjectTemplates\
  • +
+

+2.1. Building the template +

+ +

Note: this step may not be required. If the lib\windows-phone directory already contains a file CordovaStarter-x.x.x.zip then you may skip this step.

+ +

In order to simplify the development process, Cordova comes with a Visual Studio template that allows creating a Cordova application rapidly. This template can be modified if needed and the below steps indicate how to proceed if you want to modify and re-generate the template.

+ +
    +
  • Open the file lib\windows-phone\templates\standalone\CordovaSolution.sln in Visual Studio Express for Windows Phone
  • +
  • From the file menu, select 'Export Template...'
  • +
  • Choose template type 'Project template'
  • +
  • Give the exported template a name, ex. CordovaStarter-2.1.0 will produce CordovaStarter-2.1.0.zip
  • +
  • Optionally, you may add a description, icon image, and Preview image. These are what is displayed in Visual Studio in the 'New Project' dialog.-
  • +
  • Note: If you select ( 'Automatically import the template ... ') then you will not need to copy the .zip file over as outlined in step 2.
  • +
  • Press 'Finish'
  • +
+

+2.2 About the different templates +

+ +

Apache Cordova for Windows Phone 8 supports 2 different types of templates.

+ +

The 'Full' template includes a pre-built dll containing all the framework code for Apache Cordova. This template will create a project that is easy to update, as you can simply replace the JavaScript and .dll in your project and rebuild when a new version comes out. The downside of this approach is that because the dll contains ALL of the Cordova API, it requires all available permissions even if the APIs are not called. When you submit an app to the App store, Microsoft will run a static analyzer against your application, and detect that you require all available permissions, and place a disclaimer on you app that is presented to the user when they choose to install your app. Users may be discouraged if they see a required permission that does not make sense ( ie, why does this drawing program need access to my media library and contacts ).

+ +

The 'Stand-Alone' template includes ALL the source code for Apache Cordova. This project is easier to fine-tune to use just the features you need, thereby working around the permissions issues of the 'Full' template, however this type of project will be more difficult to update, as you will need to update individual files within your project and manage any dependancies yourself. In order to exclude an API you are not using, you can simply right-click-select the Command class file in Visual Studio and choose 'do not include in project'.

+ +

+3. Setup New Project +

+ +
    +
  • Open Visual Studio Express for Windows Phone and choose New Project.
  • +
  • Select CordovaWP8AppFull or CordovaWP8AppStandalone. ( the version number will be displayed in the template description )
  • +
  • Give your project a name, and select OK.
  • +
+

+ +

+4. Review the project structure +

+ +
    +
  • The 'www' folder contains your Cordova html/js/css and any other resources included in your app.
  • +
  • Any content that you add here needs to be a part of the Visual Studio project, and it must be set as content.
  • +
+

+ +

+5. Build and Deploy to Emulator +

+ +
    +
  • Make sure to have Windows Phone Emulator selected in the top drop-down menu.
  • +
  • Hit the green play button beside the Windows Phone Emulator drop-down menu to start debugging or press F5.
  • +
+

+ +

+6. Build your project for the device +

+ +

In order to test your application on a device, the device must be registered. Click here.aspx) to read documentation on deploying and testing on your Windows Phone 8.

+ +
    +
  • Make sure your phone is connected, and the screen is unlocked
  • +
  • In Visual Studio, select 'Device' from the top drop-down menu.
  • +
  • Hit the green play button beside the drop-down menu to start debugging or press F5.
  • +
+

+ +

+Done! +

+ +

+Further Reading +

+ +

For more details on the specific differences between IE10 and WebKit browsers, and how to support both MS has a helpful guide here

+ +
+
+ + + + + Added: cordova/site/public/docs/en/2.6.0/guide_plugin-development_android_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_plugin-development_android_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_plugin-development_android_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_plugin-development_android_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,315 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Developing a Plugin on Android

+ +
+ + + +
+
+

Developing a Plugin on Android

+ +

Writing a plugin requires an understanding of the architecture of Cordova-Android. Cordova-Android consists +of an Android WebView with hooks attached to it. These plugins are represented as class mappings in the config.xml +file.

+ +

A plugin will consist of at least a single Java class that extends the CordovaPlugin class. A plugin must override one +of the execute methods from CordovaPlugin. In addition to this, there is a best practice that +the plugin should handle pause and resume events, and should handle message passing between plugins. +Plugins with long-running requests, background activity (e.g. playing media), listeners or internal state should implement the onReset() method as well. This method is run when the WebView navigates to a new page or refreshes, which reloads the Javascript.

+ +

+Plugin Class Mapping +

+ +

The JavaScript portion of a plugin always uses the cordova.exec method as follows:

+ +
exec(<successFunction>, <failFunction>, <service>, <action>, [<args>]);
+
+ +

This will marshal a request from the WebView to the Android native +side, more or less boiling down to calling the action method on the +service class, with the arguments passed in the args Array.

+ +

Whether you distribute your plugin as Java file or as a JAR of its own, the plugin must be added to the config.xml file in your Cordova-Android application's res/xml/ folder.

+ +
<plugin name="<service_name>" value="<full_name_including_namespace>"/>
+
+ +

The service name should match what you use in the JavaScript exec call, and the value will be the full name of the Java class including the namespace. Without this added, the plugin may compile but +will not be reachable by Cordova.

+ +

+Writing an Android Java Plugin +

+ +

We have JavaScript to fire off a plugin request to the native side. We +have the Android Java plugin mapped properly via the config.xml file. +So what does the final Android Java Plugin class look like?

+ +

What gets dispatched to the plugin via JavaScript's exec function gets +passed into the Plugin class's execute method. Most execute +implementations look like this:

+ +
@Override
+public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+    if ("beep".equals(action)) {
+        this.beep(args.getLong(0));
+        callbackContext.success();
+        return true;
+    }
+    return false;  // Returning false results in a "MethodNotFound" error.
+}
+
+ +

We compare the value of the action parameter, and dispatch +the request off to a (private) method in the class, optionally passing +some of the parameters to the method.

+ +

When catching exceptions and returning errors, it's important that the error we return to JavaScript match the Java exception as much as possible, for clarity.

+ +

Threading

+ +

JavaScript in the WebView does not run on the UI thread. It runs on +the WebCore thread. The execute method also runs on the WebCore thread.

+ +

If you need to interact with the UI, you should use the following:

+ +
@Override
+public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
+    if ("beep".equals(action)) {
+        final long duration = args.getLong(0);
+        cordova.getActivity().runOnUiThread(new Runnable() {
+            public void run() {
+                ...
+                callbackContext.success(); // Thread-safe.
+            }
+        });
+        return true;
+    }
+    return false;
+}
+
+ +

If you do not need to run on the UI thread, but do not want to block the WebCore thread:

+ +
@Override
+public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
+    if ("beep".equals(action)) {
+        final long duration = args.getLong(0);
+        cordova.getThreadPool().execute(new Runnable() {
+            public void run() {
+                ...
+                callbackContext.success(); // Thread-safe.
+            }
+        });
+        return true;
+    }
+    return false;
+}
+
+ +

Echo Android Plugin Example

+ +

We would add the following to our config.xml:

+ +
<plugin name="Echo" value="org.apache.cordova.plugin.Echo" />
+
+ +

Then we would add the following file to +src/org/apache/cordova/plugin/Echo.java inside our Cordova-Android +application:

+ +
package org.apache.cordova.plugin;
+
+import org.apache.cordova.api.CordovaPlugin;
+import org.apache.cordova.api.PluginResult;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
+/**
+ * This class echoes a string called from JavaScript.
+ */
+public class Echo extends CordovaPlugin {
+    @Override
+    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
+        if (action.equals("echo")) {
+            String message = args.getString(0); 
+            this.echo(message, callbackContext);
+            return true;
+        }
+        return false;
+    }
+
+    private void echo(String message, CallbackContext callbackContext) {
+        if (message != null && message.length() > 0) { 
+            callbackContext.success(message);
+        } else {
+            callbackContext.error("Expected one non-empty string argument.");
+        }
+    }
+}
+
+ +

Let's take a look at the code. At the top we have all of the necessary +Cordova imports. Our class extends from CordovaPlugin. We override +the execute() method in order to recieve messages from exec(). Our method +first compares against action: this plugin only supports +one action, the echo action. Any other action will return false, which +results in an error of type INVALID_ACTION - this will translate +into an error callback invocation on the JavaScript side. Next, we grab +the echo string using the getString method on our args, telling it +we want to get the 0th parameter in the parameter array. We do a bit of +parameter checking: make sure it is not null, and make sure it is not +a zero-length string. If it is, we call callbackContext.error() (which, +by now, you should know will invoke the error callback). If all of those +checks pass, then we call callbackContext.success(), and pass in the +message string we received as a parameter. This will finally translate +into a success callback invocation on the JavaScript side. It will also +pass the message parameter as a parameter into the JavaScript success +callback function.

+ +

+Debugging Plugins +

+ +

Eclipse can be used to debug an Android project, and the plugins can be debugged if the Java source is included in the project. Only the latest version of the Android Dev Tools is known to allow source code attachment to JAR dependencies, this is not fully supported at this time.

+ +

+Common Pitfalls +

+ +
    +
  • Plugins have access to a CordovaInterface object. This object has access to the Android Activity that is running the application. This is the Context required to launch +a new Android Intent. The CordovaInterface allows plugins to start an Activity for a result, and to set the callback plugin for when the Intent comes back to the application. This is important, since the +Intents system is how Android communicates between processes.
  • +
  • Plugins do not have direct access to the Context as they have in the past. The legacy ctx member is deprecated, and will be removed six months after 2.0 is released. All the methods that ctx has exist on the Context, so both getContext() and getActivity() are capable of returning the proper object required.
  • +
+

+Use the Source +

+ +

One of the best ways to prepare yourself to write your own plugin is to +have a look at other plugins that already exist.

+ +

You should also read through the comments in CordovaPlugin.java.

+ +
+
+ + + + + Added: cordova/site/public/docs/en/2.6.0/guide_plugin-development_bada_index.md.html URL: http://svn.apache.org/viewvc/cordova/site/public/docs/en/2.6.0/guide_plugin-development_bada_index.md.html?rev=1466271&view=auto ============================================================================== --- cordova/site/public/docs/en/2.6.0/guide_plugin-development_bada_index.md.html (added) +++ cordova/site/public/docs/en/2.6.0/guide_plugin-development_bada_index.md.html Tue Apr 9 22:34:28 2013 @@ -0,0 +1,193 @@ + + + + + + +Apache Cordova API Documentation + + + + + + +
+

Developing a Plugin on Bada

+ +
+ + + +
+
+

Developing a Plugin on Bada

+ +

Plugins are only supported on Bada 2.0 and above. Bada 1.2 does not support plugins.

+ +

The Bada implementation is a full javascript implementation. Therefore, adding a custom plugin involves updating CordovaJS with your plugin code. Follow these steps to add a simple Hello World plugin:

+ +
    +
  1. +

    Clone the CordovaJS repository

    + +
    git clone https://git-wip-us.apache.org/repos/asf/cordova-js.git
    +
    +
  2. +
  3. +

    Create a new javascript file under lib/bada/plugin/bada/ and name it HelloWorld.js. Add the following content:

    + +
    function HelloWorld() {
    +}
    +
    +
    +HelloWorld.prototype.printHello = function(success, fail, arg) {
    +    alert(Osp.Core.StringHelper('Hello %1', arg[0]));
    +}
    +
    +
    +module.exports = new HelloWorld();
    +
    +
  4. +
  5. +

    Add a link to your newly created plugin in lib/bada/platform.js under the objects property:

    + +
    objects: {
    +    ...
    +    HelloWorld: {
    +        'cordova/plugin/bada/HelloWorld' 
    +    },
    +    ...
    +}
    +...
    +
    +
  6. +
  7. +

    Update the plugin list under lib/bada/exec.js to include your plugin

    + +
    var plugins = {
    +    ...
    +    "HelloWorld": require('cordova/plugin/bada/HelloWorld')
    +};
    +
    +
  8. +
  9. +

    Now you can write your user-facing javascript however you like but remember that in order for your plugin to execute you need to call the following method

    + +
    exec(success, fail, 'HelloWorld', 'printHello', ['Jackson!']);
    +
    + +

    success is the success callback that gets executed when the plugin succeeds +fail is the failure callback that gets executed if the plugin fails +'HelloWorld' is the name of your plugin +'printHello' is your plugin action +Finally, the last argument is your plugin parameters (if any).

    +
  10. +
  11. +

    Run the following command to generate the new common javascript (make sure you have the jake npm module installed)

    + +
    jake
    +
    +
  12. +
  13. Copy the newly generated javascript under pkg/cordova.bada.js to your Bada project under Res/js

  14. +
  15. That is it! You can now add new Bada plugins and implement the many features that are not currently supported by Cordova Bada.

  16. +
+
+
+ + + + +