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

This commit is contained in:
Fil Maj 2012-03-08 17:58:45 -08:00
parent c5025ee2bb
commit b4292868eb
6 changed files with 27 additions and 27 deletions

View File

@ -116,7 +116,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
public void startRecording(String file) { public void startRecording(String file) {
if (this.mPlayer != null) { if (this.mPlayer != null) {
Log.d(LOG_TAG, "AudioPlayer Error: Can't record in play mode."); 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 // Make sure we're not already recording
@ -137,11 +137,11 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); 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 { else {
Log.d(LOG_TAG, "AudioPlayer Error: Already recording."); 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) { public void startPlaying(String file) {
if (this.recorder != null) { if (this.recorder != null) {
Log.d(LOG_TAG, "AudioPlayer Error: Can't play in record mode."); 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 // 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) { catch (Exception e) {
e.printStackTrace(); 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 { else {
Log.d(LOG_TAG, "AudioPlayer Error: startPlaying() called during invalid state: "+this.state); 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) { if (this.mPlayer != null) {
this.mPlayer.seekTo(milliseconds); this.mPlayer.seekTo(milliseconds);
Log.d(LOG_TAG, "Send a onStatus update for the new seek"); 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 { else {
Log.d(LOG_TAG, "AudioPlayer Error: pausePlaying() called during invalid state: "+this.state); 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 { else {
Log.d(LOG_TAG, "AudioPlayer Error: stopPlaying() called during invalid state: "+this.state); 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() { public long getCurrentPosition() {
if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) { if ((this.state == MEDIA_RUNNING) || (this.state == MEDIA_PAUSED)) {
int curPos = this.mPlayer.getCurrentPosition(); 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; return curPos;
} }
else { else {
@ -384,7 +384,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
this.prepareOnly = false; this.prepareOnly = false;
// Send status notification to JavaScript // 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(); this.mPlayer.release();
// Send error notification to JavaScript // 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; return false;
} }
@ -424,7 +424,7 @@ public class AudioPlayer implements OnCompletionListener, OnPreparedListener, On
*/ */
private void setState(int state) { private void setState(int state) {
if (this.state != 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; this.state = state;

View File

@ -217,7 +217,7 @@ public class CordovaWebViewClient extends WebViewClient {
// not loaded yet then just set a flag so that the onNativeReady can be fired // 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. // from the JS side when the JS gets to that code.
if (!url.equals("about:blank")) { 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 // Make app visible after 2 sec in case there was a JS error and Cordova JS never initialized correctly

View File

@ -831,7 +831,7 @@ public class DroidGap extends Activity implements CordovaInterface {
} }
// Send pause event to JavaScript // 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 // Forward to plugins
this.pluginManager.onPause(this.keepRunning); this.pluginManager.onPause(this.keepRunning);
@ -872,7 +872,7 @@ public class DroidGap extends Activity implements CordovaInterface {
} }
// Send resume event to JavaScript // 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 // Forward to plugins
this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning); this.pluginManager.onResume(this.keepRunning || this.activityResultKeepRunning);
@ -902,7 +902,7 @@ public class DroidGap extends Activity implements CordovaInterface {
// Send destroy event to JavaScript // 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 // Load blank page so that JavaScript onunload is called
this.appView.loadUrl("about:blank"); 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 back key is bound, then send event to JavaScript
if (this.bound) { if (this.bound) {
this.appView.loadUrl("javascript:require('cordova').fireDocumentEvent('backbutton');"); this.appView.loadUrl("javascript:cordova.require('cordova').fireDocumentEvent('backbutton');");
return true; return true;
} }
@ -1090,13 +1090,13 @@ public class DroidGap extends Activity implements CordovaInterface {
// If menu key // If menu key
else if (keyCode == KeyEvent.KEYCODE_MENU) { 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); return super.onKeyDown(keyCode, event);
} }
// If search key // If search key
else if (keyCode == KeyEvent.KEYCODE_SEARCH) { 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; return true;
} }

View File

@ -87,13 +87,13 @@ public class LinearLayoutSoftKeyboardDetect extends LinearLayout {
// gone away. // gone away.
else if (height > oldHeight) { else if (height > oldHeight) {
if(app != null) 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 // If the height as gotten smaller then we will assume the soft keyboard has
// been displayed. // been displayed.
else if (height < oldHeight) { else if (height < oldHeight) {
if(app != null) if(app != null)
app.sendJavascript("require('cordova').fireDocumentEvent('showkeyboard');"); app.sendJavascript("cordova.require('cordova').fireDocumentEvent('showkeyboard');");
} }
// Update the old height for the next event // Update the old height for the next event

View File

@ -162,7 +162,7 @@ public class Storage extends Plugin {
try { try {
if (isDDL(query)) { if (isDDL(query)) {
this.myDb.execSQL(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 { else {
Cursor myCursor = this.myDb.rawQuery(query, params); Cursor myCursor = this.myDb.rawQuery(query, params);
@ -175,7 +175,7 @@ public class Storage extends Plugin {
System.out.println("Storage.executeSql(): Error=" + ex.getMessage()); System.out.println("Storage.executeSql(): Error=" + ex.getMessage());
// Send error message back to JavaScript // 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 // 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 + ");");
} }
} }

View File

@ -84,11 +84,11 @@ public class PluginResult {
} }
public String toSuccessCallbackString(String callbackId) { 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) { 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[] { public static String[] StatusMessages = new String[] {