From 85aa740c9864881db562bb1f1fcf672531fea8b1 Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 11 Jul 2012 09:35:29 -0700 Subject: [PATCH 1/5] [CB-481] Removed todo comment introduced by bryce, clarified what is going on --- framework/src/org/apache/cordova/App.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/App.java b/framework/src/org/apache/cordova/App.java index 14816240..dbc89090 100755 --- a/framework/src/org/apache/cordova/App.java +++ b/framework/src/org/apache/cordova/App.java @@ -48,7 +48,10 @@ public class App extends Plugin { if (action.equals("clearCache")) { this.clearCache(); } - else if (action.equals("show")) { // TODO @bc - Not in master branch. When should this be called? + else if (action.equals("show")) { + // This gets called from JavaScript onCordovaReady to show the webview. + // I recommend we change the name of the Message as spinner/stop is not + // indicative of what this actually does (shows the webview). cordova.getActivity().runOnUiThread(new Runnable() { public void run() { webView.postMessage("spinner", "stop"); From 2eb4c5e960d633f67c9767b9cdd254111476b2cd Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Wed, 11 Jul 2012 10:26:14 -0700 Subject: [PATCH 2/5] [CB-1022] Reverted nanoTime back to currentTimeMillis. Updated mobile-spec tests as well. This passes all accel tests. --- framework/src/org/apache/cordova/AccelListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/AccelListener.java b/framework/src/org/apache/cordova/AccelListener.java index fdba7be2..4fd87181 100755 --- a/framework/src/org/apache/cordova/AccelListener.java +++ b/framework/src/org/apache/cordova/AccelListener.java @@ -215,7 +215,7 @@ public class AccelListener extends Plugin implements SensorEventListener { if (this.accuracy >= SensorManager.SENSOR_STATUS_ACCURACY_MEDIUM) { // Save time that event was received - this.timestamp = System.nanoTime(); + this.timestamp = System.currentTimeMillis(); this.x = event.values[0]; this.y = event.values[1]; this.z = event.values[2]; From b486711d68dc6426b58142143f938090605afbeb Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Wed, 11 Jul 2012 11:23:31 -0700 Subject: [PATCH 3/5] Combining plugins.xml and cordova.xml to make config.xml --- framework/res/xml/config.xml | 54 +++++++++++++++++++ .../org/apache/cordova/CordovaWebView.java | 7 ++- .../org/apache/cordova/api/PluginManager.java | 17 ++++-- 3 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 framework/res/xml/config.xml diff --git a/framework/res/xml/config.xml b/framework/res/xml/config.xml new file mode 100644 index 00000000..d37aba5c --- /dev/null +++ b/framework/res/xml/config.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/framework/src/org/apache/cordova/CordovaWebView.java b/framework/src/org/apache/cordova/CordovaWebView.java index ca0dd6d7..b3ad35c5 100755 --- a/framework/src/org/apache/cordova/CordovaWebView.java +++ b/framework/src/org/apache/cordova/CordovaWebView.java @@ -596,7 +596,12 @@ public class CordovaWebView extends WebView { * */ private void loadConfiguration() { - int id = getResources().getIdentifier("cordova", "xml", this.cordova.getActivity().getPackageName()); + int id = getResources().getIdentifier("config", "xml", this.cordova.getActivity().getPackageName()); + if(id == 0) + { + id = getResources().getIdentifier("cordova", "xml", this.cordova.getActivity().getPackageName()); + Log.i("CordovaLog", "config.xml missing, reverting to cordova.xml"); + } if (id == 0) { LOG.i("CordovaLog", "cordova.xml missing. Ignoring..."); return; diff --git a/framework/src/org/apache/cordova/api/PluginManager.java b/framework/src/org/apache/cordova/api/PluginManager.java index b9df52d7..a48de67b 100755 --- a/framework/src/org/apache/cordova/api/PluginManager.java +++ b/framework/src/org/apache/cordova/api/PluginManager.java @@ -92,9 +92,16 @@ public class PluginManager { * Load plugins from res/xml/plugins.xml */ public void loadPlugins() { - int id = this.ctx.getActivity().getResources().getIdentifier("plugins", "xml", this.ctx.getActivity().getPackageName()); + int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName()); + if(id == 0) + { + id = this.ctx.getActivity().getResources().getIdentifier("plugins", "xml", this.ctx.getActivity().getPackageName()); + LOG.i(TAG, "Using plugins.xml instead of config.xml. plugins.xml will eventually be deprecated"); + } if (id == 0) { this.pluginConfigurationMissing(); + //We have the error, we need to exit without crashing! + return; } XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id); int eventType = -1; @@ -361,9 +368,9 @@ public class PluginManager { } private void pluginConfigurationMissing() { - System.err.println("====================================================================================="); - System.err.println("ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project."); - System.err.println("https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml"); - System.err.println("====================================================================================="); + LOG.e(TAG, "====================================================================================="); + LOG.e(TAG, "ERROR: plugin.xml is missing. Add res/xml/plugins.xml to your project."); + LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=incubator-cordova-android.git;a=blob;f=framework/res/xml/plugins.xml"); + LOG.e(TAG, "====================================================================================="); } } From 0ccd11e587020084f6c3566dab7120e1a9f687b4 Mon Sep 17 00:00:00 2001 From: Anis Kadri Date: Wed, 11 Jul 2012 14:00:42 -0700 Subject: [PATCH 4/5] CB-1031 android create script fails --- bin/create | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bin/create b/bin/create index 688b5fd0..a12a715e 100755 --- a/bin/create +++ b/bin/create @@ -63,6 +63,19 @@ function on_error { [ -d $PROJECT_PATH ] && rm -rf $PROJECT_PATH } +function replace { + local pattern=$1 + local filename=$2 + # Mac OS X requires -i argument + if [ $OSTYPE = 'darwin11' ] + then + sed -i '' -e $pattern $filename + elif [ $OSTYPE = 'linux-gnu' ] + then + sed -i -e $pattern $filename + fi +} + # we do not want the script to silently fail trap on_error ERR trap on_exit EXIT @@ -116,12 +129,12 @@ fi # interpolate the activity name and package cp $BUILD_PATH/bin/templates/project/Activity.java $ACTIVITY_PATH -sed -i '' -e "s/__ACTIVITY__/${ACTIVITY}/g" $ACTIVITY_PATH -sed -i '' -e "s/__ID__/${PACKAGE}/g" $ACTIVITY_PATH +replace "s/__ACTIVITY__/${ACTIVITY}/g" $ACTIVITY_PATH +replace "s/__ID__/${PACKAGE}/g" $ACTIVITY_PATH cp $BUILD_PATH/bin/templates/project/AndroidManifest.xml $MANIFEST_PATH -sed -i '' -e "s/__ACTIVITY__/${ACTIVITY}/g" $MANIFEST_PATH -sed -i '' -e "s/__PACKAGE__/${PACKAGE}/g" $MANIFEST_PATH +replace "s/__ACTIVITY__/${ACTIVITY}/g" $MANIFEST_PATH +replace "s/__PACKAGE__/${PACKAGE}/g" $MANIFEST_PATH # creating cordova folder and copying emulate/debug/log/launch scripts mkdir $PROJECT_PATH/cordova From c6d8343de239b03c66ce38cc94192250f624a22a Mon Sep 17 00:00:00 2001 From: Fil Maj Date: Thu, 12 Jul 2012 13:37:08 -0700 Subject: [PATCH 5/5] [CB-1035] Including newest JS built based on refactored common device module. --- framework/assets/js/cordova.android.js | 206 +++++++++++++------------ 1 file changed, 111 insertions(+), 95 deletions(-) diff --git a/framework/assets/js/cordova.android.js b/framework/assets/js/cordova.android.js index 2fdf2d56..059f71ac 100644 --- a/framework/assets/js/cordova.android.js +++ b/framework/assets/js/cordova.android.js @@ -1,6 +1,6 @@ -// commit 5647225e12e18e15aefc33b151430d9a3804d9ea +// commit 32e35b75c5ea2946dffebbc6cf4d0fbc16c0839e -// File generated at :: Fri Jun 29 2012 12:32:24 GMT-0400 (EDT) +// File generated at :: Thu Jul 12 2012 13:35:26 GMT-0700 (PDT) /* Licensed to the Apache Software Foundation (ASF) under one @@ -713,7 +713,6 @@ channel.create('onDestroy'); // Channels that must fire before "deviceready" is fired. channel.waitForInitialization('onCordovaReady'); -channel.waitForInitialization('onCordovaInfoReady'); channel.waitForInitialization('onCordovaConnectionReady'); module.exports = channel; @@ -848,6 +847,9 @@ module.exports = { Coordinates: { path: 'cordova/plugin/Coordinates' }, + device: { + path: 'cordova/plugin/device' + }, DirectoryEntry: { path: 'cordova/plugin/DirectoryEntry' }, @@ -1114,7 +1116,7 @@ module.exports = { // Let native code know we are all done on the JS side. // Native code will then un-hide the WebView. channel.join(function() { - prompt("", "gap_init:"); + exec(null, null, "App", "show", []); }, [channel.onCordovaReady]); }, objects: { @@ -1135,9 +1137,6 @@ module.exports = { } } }, - device:{ - path: "cordova/plugin/android/device" - }, File: { // exists natively on Android WebView, override path: "cordova/plugin/File" }, @@ -1152,6 +1151,9 @@ module.exports = { } }, merges: { + device: { + path: 'cordova/plugin/android/device' + }, navigator: { children: { notification: { @@ -1873,7 +1875,7 @@ var utils = require('cordova/utils'), * {boolean} isDirectory always true (readonly) * {DOMString} name of the directory, excluding the path leading to it (readonly) * {DOMString} fullPath the absolute full path to the directory (readonly) - * {FileSystem} filesystem on which the directory resides (readonly) + * TODO: implement this!!! {FileSystem} filesystem on which the directory resides (readonly) */ var DirectoryEntry = function(name, fullPath) { DirectoryEntry.__super__.constructor.apply(this, [false, true, name, fullPath]); @@ -2598,13 +2600,12 @@ var DirectoryEntry = require('cordova/plugin/DirectoryEntry'); var FileSystem = function(name, root) { this.name = name || null; if (root) { - console.log('root.name ' + name); - console.log('root.root ' + root); this.root = new DirectoryEntry(root.name, root.fullPath); } }; module.exports = FileSystem; + }); // file: lib/common/plugin/FileTransfer.js @@ -3768,97 +3769,44 @@ module.exports = callback; define("cordova/plugin/android/device", function(require, exports, module) { var channel = require('cordova/channel'), utils = require('cordova/utils'), - exec = require('cordova/exec'); + exec = require('cordova/exec'), + app = require('cordova/plugin/android/app'); -/** - * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the - * phone, etc. - * @constructor - */ -function Device() { - this.available = false; - this.platform = null; - this.version = null; - this.name = null; - this.uuid = null; - this.cordova = null; +module.exports = { + /* + * DEPRECATED + * This is only for Android. + * + * You must explicitly override the back button. + */ + overrideBackButton:function() { + console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true)."); + app.overrideBackbutton(true); + }, - var me = this; + /* + * DEPRECATED + * This is only for Android. + * + * This resets the back button to the default behaviour + */ + resetBackButton:function() { + console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false)."); + app.overrideBackbutton(false); + }, - channel.onCordovaReady.subscribeOnce(function() { - me.getInfo(function(info) { - me.available = true; - me.platform = info.platform; - me.version = info.version; - me.name = info.name; - me.uuid = info.uuid; - me.cordova = info.cordova; - channel.onCordovaInfoReady.fire(); - },function(e) { - me.available = false; - utils.alert("[ERROR] Error initializing Cordova: " + e); - }); - }); -} - -/** - * Get device info - * - * @param {Function} successCallback The function to call when the heading data is available - * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) - */ -Device.prototype.getInfo = function(successCallback, errorCallback) { - - // successCallback required - if (typeof successCallback !== "function") { - console.log("Device Error: successCallback is not a function"); - return; + /* + * DEPRECATED + * This is only for Android. + * + * This terminates the activity! + */ + exitApp:function() { + console.log("Device.exitApp() is deprecated. Use App.exitApp()."); + app.exitApp(); } - - // errorCallback optional - if (errorCallback && (typeof errorCallback !== "function")) { - console.log("Device Error: errorCallback is not a function"); - return; - } - - // Get info - exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); }; -/* - * DEPRECATED - * This is only for Android. - * - * You must explicitly override the back button. - */ -Device.prototype.overrideBackButton = function() { - console.log("Device.overrideBackButton() is deprecated. Use App.overrideBackbutton(true)."); - navigator.app.overrideBackbutton(true); -}; - -/* - * DEPRECATED - * This is only for Android. - * - * This resets the back button to the default behaviour - */ -Device.prototype.resetBackButton = function() { - console.log("Device.resetBackButton() is deprecated. Use App.overrideBackbutton(false)."); - navigator.app.overrideBackbutton(false); -}; - -/* - * DEPRECATED - * This is only for Android. - * - * This terminates the activity! - */ -Device.prototype.exitApp = function() { - console.log("Device.exitApp() is deprecated. Use App.exitApp()."); - navigator.app.exitApp(); -}; - -module.exports = new Device(); }); // file: lib/android/plugin/android/notification.js @@ -4844,6 +4792,74 @@ module.exports = contacts; }); +// file: lib/common/plugin/device.js +define("cordova/plugin/device", function(require, exports, module) { +var channel = require('cordova/channel'), + utils = require('cordova/utils'), + exec = require('cordova/exec'); + +// Tell cordova channel to wait on the CordovaInfoReady event +channel.waitForInitialization('onCordovaInfoReady'); + +/** + * This represents the mobile device, and provides properties for inspecting the model, version, UUID of the + * phone, etc. + * @constructor + */ +function Device() { + this.available = false; + this.platform = null; + this.version = null; + this.name = null; + this.uuid = null; + this.cordova = null; + + var me = this; + + channel.onCordovaReady.subscribeOnce(function() { + me.getInfo(function(info) { + me.available = true; + me.platform = info.platform; + me.version = info.version; + me.name = info.name; + me.uuid = info.uuid; + me.cordova = info.cordova; + channel.onCordovaInfoReady.fire(); + },function(e) { + me.available = false; + utils.alert("[ERROR] Error initializing Cordova: " + e); + }); + }); +} + +/** + * Get device info + * + * @param {Function} successCallback The function to call when the heading data is available + * @param {Function} errorCallback The function to call when there is an error getting the heading data. (OPTIONAL) + */ +Device.prototype.getInfo = function(successCallback, errorCallback) { + + // successCallback required + if (typeof successCallback !== "function") { + console.log("Device Error: successCallback is not a function"); + return; + } + + // errorCallback optional + if (errorCallback && (typeof errorCallback !== "function")) { + console.log("Device Error: errorCallback is not a function"); + return; + } + + // Get info + exec(successCallback, errorCallback, "Device", "getDeviceInfo", []); +}; + +module.exports = new Device(); + +}); + // file: lib/common/plugin/geolocation.js define("cordova/plugin/geolocation", function(require, exports, module) { var utils = require('cordova/utils'),