You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by fi...@apache.org on 2012/03/09 21:36:52 UTC

[5/5] android commit: switched from "require" syntax to "cordova.require"

switched from "require" syntax to "cordova.require"


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/b4292868
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/b4292868
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/b4292868

Branch: refs/heads/master
Commit: b4292868eb2b50ec5cbe777ae74f24994da5e2d5
Parents: c5025ee
Author: Fil Maj <ma...@gmail.com>
Authored: Thu Mar 8 17:58:45 2012 -0800
Committer: Fil Maj <ma...@gmail.com>
Committed: Thu Mar 8 17:58:45 2012 -0800

----------------------------------------------------------------------
 framework/src/org/apache/cordova/AudioPlayer.java  |   26 +++++++-------
 .../org/apache/cordova/CordovaWebViewClient.java   |    2 +-
 framework/src/org/apache/cordova/DroidGap.java     |   12 +++---
 .../cordova/LinearLayoutSoftKeyboardDetect.java    |    4 +-
 framework/src/org/apache/cordova/Storage.java      |    6 ++--
 .../src/org/apache/cordova/api/PluginResult.java   |    4 +-
 6 files changed, 27 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/AudioPlayer.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/AudioPlayer.java b/framework/src/org/apache/cordova/AudioPlayer.java
index 22b4571..0a59460 100755
--- a/framework/src/org/apache/cordova/AudioPlayer.java
+++ b/framework/src/org/apache/cordova/AudioPlayer.java
@@ -116,7 +116,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 	public void startRecording(String file) {
 		if (this.mPlayer != null) {
 			Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode.");
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
 		}
 		
 		// Make sure we're not already recording
@@ -137,11 +137,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 			} catch (IOException e) {
 				e.printStackTrace();
 			}
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
 		}
 		else {
 		    Log.d(LOG_TAG, "AudioPlayer Error: Already recording.");
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
 		}
 	}
 	
@@ -183,7 +183,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 	public void startPlaying(String file) {
 		if (this.recorder != null) {
 		    Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode.");
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");
 		}
 		
 		// If this is a new request to play audio, or stopped
@@ -228,7 +228,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 			} 
 			catch (Exception e) { 
 				e.printStackTrace(); 
-				this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
+				this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
 			}
 		}
 
@@ -242,7 +242,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 			}
 			else {
 			    Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state);
-				this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
+				this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_ABORTED+");");			
 			}
 		}
 	} 
@@ -254,7 +254,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 		if (this.mPlayer != null) {
 		    this.mPlayer.seekTo(milliseconds);
 		    Log.d(LOG_TAG, "Send a onStatus update for the new seek");
-		    this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
+		    this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+milliseconds/1000.0f+");");
 		}
 	}
 	
@@ -270,7 +270,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 		}
 		else {
 		    Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state);			
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");			
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");			
 		}
 	}
 
@@ -284,7 +284,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 		}
 		else {
 		    Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state);			
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");			
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+MEDIA_ERR_NONE_ACTIVE+");");			
 		}
 	}
 	
@@ -305,7 +305,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 	public long getCurrentPosition() {
 		if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
 		    int curPos = this.mPlayer.getCurrentPosition();
-		    this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
+		    this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_POSITION+", "+curPos/1000.0f+");");
 			return curPos;
 		} 
 		else { 
@@ -384,7 +384,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 		this.prepareOnly = false;
 
 		// Send status notification to JavaScript
-		this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
+		this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_DURATION+","+this.duration+");");
 		
 	}
 
@@ -413,7 +413,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 		this.mPlayer.release();
 		
 		// Send error notification to JavaScript
-		this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
+		this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_ERROR+", "+arg1+");");
 		return false;
 	}
 	
@@ -424,7 +424,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
 	 */
 	private void setState(int state) {
 		if (this.state != state) {
-			this.handler.sendJavascript("require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
+			this.handler.sendJavascript("cordova.require('cordova/plugin/Media').onStatus('" + this.id + "', "+MEDIA_STATE+", "+state+");");
 		}
 		
 		this.state = state;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/CordovaWebViewClient.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaWebViewClient.java b/framework/src/org/apache/cordova/CordovaWebViewClient.java
index a44d23e..042f743 100755
--- a/framework/src/org/apache/cordova/CordovaWebViewClient.java
+++ b/framework/src/org/apache/cordova/CordovaWebViewClient.java
@@ -217,7 +217,7 @@ public class CordovaWebViewClient extends WebViewClient {
         // not loaded yet then just set a flag so that the onNativeReady can be fired
         // from the JS side when the JS gets to that code.
         if (!url.equals("about:blank")) {
-            ctx.appView.loadUrl("javascript:try{ require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
+            ctx.appView.loadUrl("javascript:try{ cordova.require('cordova/channel').onNativeReady.fire();}catch(e){_nativeReady = true;}");
         }
 
         // Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/DroidGap.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/DroidGap.java b/framework/src/org/apache/cordova/DroidGap.java
index ddc4fab..9df68cd 100755
--- a/framework/src/org/apache/cordova/DroidGap.java
+++ b/framework/src/org/apache/cordova/DroidGap.java
@@ -831,7 +831,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         }
 
         // Send pause event to JavaScript
-        this.appView.loadUrl("javascript:try{require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};");
+        this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onPause.fire();}catch(e){console.log('exception firing pause event from native');};");
 
         // Forward to plugins
         this.pluginManager.onPause(this.keepRunning);
@@ -872,7 +872,7 @@ public class DroidGap extends Activity implements CordovaInterface {
         }
 
         // Send resume event to JavaScript
-        this.appView.loadUrl("javascript:try{require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};");
+        this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onResume.fire();}catch(e){console.log('exception firing resume event from native');};");
 
         // Forward to plugins
         this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
@@ -902,7 +902,7 @@ public class DroidGap extends Activity implements CordovaInterface {
 
 
             // Send destroy event to JavaScript
-            this.appView.loadUrl("javascript:try{require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
+            this.appView.loadUrl("javascript:try{cordova.require('cordova/channel').onDestroy.fire();}catch(e){console.log('exception firing destroy event from native');};");
 
             // Load blank page so that JavaScript onunload is called
             this.appView.loadUrl("about:blank");
@@ -1068,7 +1068,7 @@ public class DroidGap extends Activity implements CordovaInterface {
 
             // If back key is bound, then send event to JavaScript
             if (this.bound) {
-                this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('backbutton');");
+                this.appView.loadUrl("javascript:cordova.require('cordova').fireDocumentEvent('backbutton');");
                 return true;
             }
 
@@ -1090,13 +1090,13 @@ public class DroidGap extends Activity implements CordovaInterface {
 
         // If menu key
         else if (keyCode == KeyEvent.KEYCODE_MENU) {
-            this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('menubutton');");
+            this.appView.loadUrl("javascript:cordova.require('cordova').fireDocumentEvent('menubutton');");
             return super.onKeyDown(keyCode, event);
         }
 
         // If search key
         else if (keyCode == KeyEvent.KEYCODE_SEARCH) {
-            this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('searchbutton');");
+            this.appView.loadUrl("javascript:cordova.require('cordova').fireDocumentEvent('searchbutton');");
             return true;
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java b/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
index 31ccf8a..6a18c9a 100755
--- a/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
+++ b/framework/src/org/apache/cordova/LinearLayoutSoftKeyboardDetect.java
@@ -87,13 +87,13 @@ public class LinearLayoutSoftKeyboardDetect extends LinearLayout {
         // gone away.
         else if (height > oldHeight) {
             if(app != null)
-                app.sendJavascript("require('cordova').fireDocumentEvent('hidekeyboard');");
+                app.sendJavascript("cordova.require('cordova').fireDocumentEvent('hidekeyboard');");
         } 
         // If the height as gotten smaller then we will assume the soft keyboard has 
         // been displayed.
         else if (height < oldHeight) {
             if(app != null)
-                app.sendJavascript("require('cordova').fireDocumentEvent('showkeyboard');");
+                app.sendJavascript("cordova.require('cordova').fireDocumentEvent('showkeyboard');");
         }
 
         // Update the old height for the next event

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/Storage.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Storage.java b/framework/src/org/apache/cordova/Storage.java
index 62e635c..98ec422 100755
--- a/framework/src/org/apache/cordova/Storage.java
+++ b/framework/src/org/apache/cordova/Storage.java
@@ -162,7 +162,7 @@ public class Storage extends Plugin {
 		try {
 			if (isDDL(query)) {
 				this.myDb.execSQL(query);
-				this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
+				this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', '');");
 			} 
 			else {
 				Cursor myCursor = this.myDb.rawQuery(query, params);
@@ -175,7 +175,7 @@ public class Storage extends Plugin {
 			System.out.println("Storage.executeSql(): Error=" +  ex.getMessage());
 			
 			// Send error message back to JavaScript
-			this.sendJavascript("require('cordova/plugin/android/storage').fail('" + ex.getMessage() + "','" + tx_id + "');");
+			this.sendJavascript("cordova.require('cordova/plugin/android/storage').fail('" + ex.getMessage() + "','" + tx_id + "');");
 		}
 	}
 
@@ -233,7 +233,7 @@ public class Storage extends Plugin {
 		}
 
 		// Let JavaScript know that there are no more rows
-		this.sendJavascript("require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
+		this.sendJavascript("cordova.require('cordova/plugin/android/storage').completeQuery('" + tx_id + "', " + result + ");");
 	}
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/b4292868/framework/src/org/apache/cordova/api/PluginResult.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/api/PluginResult.java b/framework/src/org/apache/cordova/api/PluginResult.java
index 3a12491..35c91ec 100755
--- a/framework/src/org/apache/cordova/api/PluginResult.java
+++ b/framework/src/org/apache/cordova/api/PluginResult.java
@@ -84,11 +84,11 @@ public class PluginResult {
 	}
 	
 	public String toSuccessCallbackString(String callbackId) {
-		return "require('cordova').callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
+		return "cordova.require('cordova').callbackSuccess('"+callbackId+"',"+this.getJSONString()+");";
 	}
 	
 	public String toErrorCallbackString(String callbackId) {
-		return "require('cordova').callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
+		return "cordova.require('cordova').callbackError('"+callbackId+"', " + this.getJSONString()+ ");";
 	}
 	
 	public static String[] StatusMessages = new String[] {