From 4c5f8203166608dd8f9463c8b0f2156b09a41626 Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 8 Jun 2010 15:55:57 -0700 Subject: [PATCH 1/3] Hacking together a work-around for the default back behaviour --- framework/assets/js/device.js | 26 ++++++++++++ framework/assets/js/keyevent.js | 11 +---- framework/src/com/phonegap/DroidGap.java | 51 +++++++++++++----------- 3 files changed, 56 insertions(+), 32 deletions(-) diff --git a/framework/assets/js/device.js b/framework/assets/js/device.js index d6be6016..4a786a8d 100644 --- a/framework/assets/js/device.js +++ b/framework/assets/js/device.js @@ -28,6 +28,32 @@ function Device() { } } +/* + * You must explicitly override the back button. + */ + +Device.prototype.overrideBackButton = function() +{ + BackButton.override(); +} + +/* + * This resets the back button to the default behaviour + */ + +Device.prototype.resetBackButton = function() +{ + BackButton.reset(); +} + +/* + * This terminates the activity! + */ +Device.prototype.exitApp = function() +{ + BackButton.exitApp(); +} + PhoneGap.addConstructor(function() { navigator.device = window.device = new Device(); }); diff --git a/framework/assets/js/keyevent.js b/framework/assets/js/keyevent.js index 26f789f1..9b72ac0c 100644 --- a/framework/assets/js/keyevent.js +++ b/framework/assets/js/keyevent.js @@ -2,17 +2,10 @@ function KeyEvent() { } -KeyEvent.prototype.menuTrigger = function() +KeyEvent.prototype.backTrigger = function() { var e = document.createEvent('Events'); - e.initEvent('menuKeyDown'); - document.dispatchEvent(e); -} - -KeyEvent.prototype.searchTrigger= function() -{ - var e = document.createEvent('Events'); - e.initEvent('searchKeyDown'); + e.initEvent('backKeyDown'); document.dispatchEvent(e); } diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index b0ac1cd2..6a746e72 100644 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -63,6 +63,7 @@ public class DroidGap extends Activity { private CompassListener mCompass; private Storage cupcakeStorage; private CryptoHandler crypto; + private BrowserKey mKey; /** Called when the activity is first created. */ @Override @@ -142,6 +143,7 @@ public class DroidGap extends Activity { netMan = new NetworkManager(appView, this); mCompass = new CompassListener(appView, this); crypto = new CryptoHandler(appView); + mKey = new BrowserKey(appView, this); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(gap, "DroidGap"); @@ -153,6 +155,7 @@ public class DroidGap extends Activity { appView.addJavascriptInterface(netMan, "NetworkManager"); appView.addJavascriptInterface(mCompass, "CompassHook"); appView.addJavascriptInterface(crypto, "GapCrypto"); + appView.addJavascriptInterface(mKey, "BackButton"); if (android.os.Build.VERSION.RELEASE.startsWith("1.")) @@ -211,6 +214,8 @@ public class DroidGap extends Activity { } else { + //We clear the back button state + mKey.reset(); view.loadUrl(url); return false; } @@ -301,43 +306,43 @@ public class DroidGap extends Activity { quotaUpdater.updateQuota(currentQuota); } } - - // This is a test of console.log, because we don't have this in Android 2.01 - public void addMessageToConsole(String message, int lineNumber, String sourceID) - { - Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message); - } // console.log in api level 7: http://developer.android.com/guide/developing/debug-tasks.html - public void onConsoleMessage(String message, int lineNumber, String sourceID) - { - Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message); - } + public void onConsoleMessage(String message, int lineNumber, String sourceID) + { + // This is a kludgy hack!!!! + Log.d(TAG, sourceID + ": Line " + Integer.toString(lineNumber) + " : " + message); + } } public boolean onKeyDown(int keyCode, KeyEvent event) { - if (keyCode == KeyEvent.KEYCODE_BACK) { - String testUrl = appView.getUrl(); - appView.goBack(); - if(appView.getUrl() == testUrl) - { - return super.onKeyDown(keyCode, event); - } + + if (keyCode == KeyEvent.KEYCODE_BACK) { + if (mKey.isBound()) + { + //We fire an event here! + appView.loadUrl("javascript:document.keyEvent.backTrigger()"); + } + else + { + String testUrl = appView.getUrl(); + appView.goBack(); + if(appView.getUrl() == testUrl) + { + return super.onKeyDown(keyCode, event); + } + } } if (keyCode == KeyEvent.KEYCODE_MENU) { + // This is where we launch the menu appView.loadUrl("javascript:keyEvent.menuTrigger()"); } - - if (keyCode == KeyEvent.KEYCODE_SEARCH) - { - appView.loadUrl("javascript:keyEvent.searchTrigger()"); - } - + return false; } From 7ad30dfc63338611ee738197ccdb6bdb78ec439d Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 8 Jun 2010 16:30:20 -0700 Subject: [PATCH 2/3] Removed PhoneGap.java, renaming to device and audio --- framework/src/com/phonegap/AudioHandler.java | 241 +++++------------- framework/src/com/phonegap/AudioPlayer.java | 193 ++++++++++++++ framework/src/com/phonegap/BrowserKey.java | 46 ++++ .../phonegap/{PhoneGap.java => Device.java} | 84 +----- framework/src/com/phonegap/DroidGap.java | 7 +- 5 files changed, 314 insertions(+), 257 deletions(-) create mode 100644 framework/src/com/phonegap/AudioPlayer.java create mode 100644 framework/src/com/phonegap/BrowserKey.java rename framework/src/com/phonegap/{PhoneGap.java => Device.java} (67%) diff --git a/framework/src/com/phonegap/AudioHandler.java b/framework/src/com/phonegap/AudioHandler.java index b971873a..349dea2b 100644 --- a/framework/src/com/phonegap/AudioHandler.java +++ b/framework/src/com/phonegap/AudioHandler.java @@ -1,193 +1,68 @@ package com.phonegap; -import java.io.File; -import java.io.IOException; - import android.content.Context; -import android.media.AudioManager; -import android.media.MediaPlayer; -import android.media.MediaPlayer.OnErrorListener; -import android.media.MediaRecorder; -import android.media.MediaPlayer.OnBufferingUpdateListener; -import android.media.MediaPlayer.OnCompletionListener; -import android.media.MediaPlayer.OnPreparedListener; -import android.util.Log; +import android.webkit.WebView; -public class AudioHandler implements OnCompletionListener, OnPreparedListener, OnErrorListener { - private MediaRecorder recorder; - private boolean isRecording = false; - MediaPlayer mPlayer; - private boolean isPlaying = false; - private String recording; - private String saveFile; - private Context mCtx; +public class AudioHandler { - public AudioHandler(String file, Context ctx) { - this.recording = file; - this.mCtx = ctx; - } + AudioPlayer audio; + WebView mAppView; + Context mCtx; - protected void startRecording(String file){ - if (!isRecording){ - saveFile=file; - recorder = new MediaRecorder(); - recorder.setAudioSource(MediaRecorder.AudioSource.MIC); - recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); - recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); - recorder.setOutputFile(this.recording); - try { - recorder.prepare(); - } catch (IllegalStateException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - isRecording = true; - recorder.start(); - } - } - - private void moveFile(String file) { - /* this is a hack to save the file as the specified name */ - File f = new File (this.recording); - f.renameTo(new File("/sdcard" + file)); - } - - protected void stopRecording(){ - try{ - if((recorder != null)&&(isRecording)) - { - isRecording = false; - recorder.stop(); - recorder.release(); - } - moveFile(saveFile); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - - protected void startPlaying(String file) { - if (isPlaying==false) { - try { - mPlayer = new MediaPlayer(); - isPlaying=true; - Log.d("Audio startPlaying", "audio: " + file); - if (isStreaming(file)) - { - Log.d("AudioStartPlaying", "Streaming"); - // Streaming prepare async - mPlayer.setDataSource(file); - mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - mPlayer.prepareAsync(); - } else { - Log.d("AudioStartPlaying", "File"); - // Not streaming prepare synchronous, abstract base directory - mPlayer.setDataSource("/sdcard/" + file); - mPlayer.prepare(); - } - mPlayer.setOnPreparedListener(this); - } catch (Exception e) - { - e.printStackTrace(); - } - } - } - - public void stopPlaying() { - if (isPlaying) { - mPlayer.stop(); - mPlayer.release(); - isPlaying=false; - } - } - - public void onCompletion(MediaPlayer mPlayer) { - mPlayer.stop(); - mPlayer.release(); - isPlaying=false; - } - - protected long getCurrentPosition() { - if (isPlaying) - { - return(mPlayer.getCurrentPosition()); - } else { return(-1); } - } - - private boolean isStreaming(String file) + AudioHandler(WebView view, Context ctx) { - if (file.contains("http://")) { - return true; - } else { - return false; - } - } - - protected long getDuration(String file) { - long duration = -2; - if (!isPlaying & !isStreaming(file)) { - try { - mPlayer = new MediaPlayer(); - mPlayer.setDataSource("/sdcard/" + file); - mPlayer.prepare(); - duration = mPlayer.getDuration(); - mPlayer.release(); - } catch (Exception e) { e.printStackTrace(); return(-3); } - } else - if (isPlaying & !isStreaming(file)) { - duration = mPlayer.getDuration(); - } else - if (isPlaying & isStreaming(file)) { - try { - duration = mPlayer.getDuration(); - } catch (Exception e) { e.printStackTrace(); return(-4); } - }else { return -1; } - return duration; + mAppView = view; + mCtx = ctx; + // YES, I know this is bad, but I can't do it the right way because Google didn't have the + // foresight to add android.os.environment.getExternalDataDirectory until Android 2.2 + audio = new AudioPlayer("/sdcard/tmprecording.mp3", mCtx); } - public void onPrepared(MediaPlayer mPlayer) { - if (isPlaying) { - mPlayer.setOnCompletionListener(this); - mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() - { - public void onBufferingUpdate(MediaPlayer mPlayer, int percent) - { - /* TODO: call back, e.g. update outer progress bar */ - Log.d("AudioOnBufferingUpdate", "percent: " + percent); - } - }); - mPlayer.start(); - } - } - - public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) { - Log.e("AUDIO onError", "error " + arg1 + " " + arg2); - return false; - } - - protected void setAudioOutputDevice(int output){ - // Changes the default audio output device to speaker or earpiece - AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE); - if (output == (2)) - audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); - else if (output == (1)){ - audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); - }else - Log.e("AudioHandler setAudioOutputDevice", " unknown output device"); - } - - protected int getAudioOutputDevice(){ - AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE); - if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) - return 1; - else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) - return 2; - else - return -1; - } + /** + * AUDIO + * TODO: Basic functions done but needs more work on error handling and call backs, remove record hack + */ + + public void startRecordingAudio(String file) + { + /* for this to work the recording needs to be specified in the constructor, + * a hack to get around this, I'm moving the recording after it's complete + */ + audio.startRecording(file); + } + + public void stopRecordingAudio() + { + audio.stopRecording(); + } + + public void startPlayingAudio(String file) + { + audio.startPlaying(file); + } + + public void stopPlayingAudio() + { + audio.stopPlaying(); + } + + public long getCurrentPositionAudio() + { + System.out.println(audio.getCurrentPosition()); + return(audio.getCurrentPosition()); + } + + public long getDurationAudio(String file) + { + System.out.println(audio.getDuration(file)); + return(audio.getDuration(file)); + } + + public void setAudioOutputDevice(int output){ + audio.setAudioOutputDevice(output); + } + + public int getAudioOutputDevice(){ + return audio.getAudioOutputDevice(); + } } diff --git a/framework/src/com/phonegap/AudioPlayer.java b/framework/src/com/phonegap/AudioPlayer.java new file mode 100644 index 00000000..a52262b7 --- /dev/null +++ b/framework/src/com/phonegap/AudioPlayer.java @@ -0,0 +1,193 @@ +package com.phonegap; + +import java.io.File; +import java.io.IOException; + +import android.content.Context; +import android.media.AudioManager; +import android.media.MediaPlayer; +import android.media.MediaPlayer.OnErrorListener; +import android.media.MediaRecorder; +import android.media.MediaPlayer.OnBufferingUpdateListener; +import android.media.MediaPlayer.OnCompletionListener; +import android.media.MediaPlayer.OnPreparedListener; +import android.util.Log; + +public class AudioPlayer implements OnCompletionListener, OnPreparedListener, OnErrorListener { + private MediaRecorder recorder; + private boolean isRecording = false; + MediaPlayer mPlayer; + private boolean isPlaying = false; + private String recording; + private String saveFile; + private Context mCtx; + + public AudioPlayer(String file, Context ctx) { + this.recording = file; + this.mCtx = ctx; + } + + protected void startRecording(String file){ + if (!isRecording){ + saveFile=file; + recorder = new MediaRecorder(); + recorder.setAudioSource(MediaRecorder.AudioSource.MIC); + recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); + recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); + recorder.setOutputFile(this.recording); + try { + recorder.prepare(); + } catch (IllegalStateException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + isRecording = true; + recorder.start(); + } + } + + private void moveFile(String file) { + /* this is a hack to save the file as the specified name */ + File f = new File (this.recording); + f.renameTo(new File("/sdcard" + file)); + } + + protected void stopRecording(){ + try{ + if((recorder != null)&&(isRecording)) + { + isRecording = false; + recorder.stop(); + recorder.release(); + } + moveFile(saveFile); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + protected void startPlaying(String file) { + if (isPlaying==false) { + try { + mPlayer = new MediaPlayer(); + isPlaying=true; + Log.d("Audio startPlaying", "audio: " + file); + if (isStreaming(file)) + { + Log.d("AudioStartPlaying", "Streaming"); + // Streaming prepare async + mPlayer.setDataSource(file); + mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); + mPlayer.prepareAsync(); + } else { + Log.d("AudioStartPlaying", "File"); + // Not streaming prepare synchronous, abstract base directory + mPlayer.setDataSource("/sdcard/" + file); + mPlayer.prepare(); + } + mPlayer.setOnPreparedListener(this); + } catch (Exception e) + { + e.printStackTrace(); + } + } + } + + public void stopPlaying() { + if (isPlaying) { + mPlayer.stop(); + mPlayer.release(); + isPlaying=false; + } + } + + public void onCompletion(MediaPlayer mPlayer) { + mPlayer.stop(); + mPlayer.release(); + isPlaying=false; + } + + protected long getCurrentPosition() { + if (isPlaying) + { + return(mPlayer.getCurrentPosition()); + } else { return(-1); } + } + + private boolean isStreaming(String file) + { + if (file.contains("http://")) { + return true; + } else { + return false; + } + } + + protected long getDuration(String file) { + long duration = -2; + if (!isPlaying & !isStreaming(file)) { + try { + mPlayer = new MediaPlayer(); + mPlayer.setDataSource("/sdcard/" + file); + mPlayer.prepare(); + duration = mPlayer.getDuration(); + mPlayer.release(); + } catch (Exception e) { e.printStackTrace(); return(-3); } + } else + if (isPlaying & !isStreaming(file)) { + duration = mPlayer.getDuration(); + } else + if (isPlaying & isStreaming(file)) { + try { + duration = mPlayer.getDuration(); + } catch (Exception e) { e.printStackTrace(); return(-4); } + }else { return -1; } + return duration; + } + + public void onPrepared(MediaPlayer mPlayer) { + if (isPlaying) { + mPlayer.setOnCompletionListener(this); + mPlayer.setOnBufferingUpdateListener(new OnBufferingUpdateListener() + { + public void onBufferingUpdate(MediaPlayer mPlayer, int percent) + { + /* TODO: call back, e.g. update outer progress bar */ + Log.d("AudioOnBufferingUpdate", "percent: " + percent); + } + }); + mPlayer.start(); + } + } + + public boolean onError(MediaPlayer mPlayer, int arg1, int arg2) { + Log.e("AUDIO onError", "error " + arg1 + " " + arg2); + return false; + } + + protected void setAudioOutputDevice(int output){ + // Changes the default audio output device to speaker or earpiece + AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE); + if (output == (2)) + audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_SPEAKER, AudioManager.ROUTE_ALL); + else if (output == (1)){ + audiMgr.setRouting(AudioManager.MODE_NORMAL, AudioManager.ROUTE_EARPIECE, AudioManager.ROUTE_ALL); + }else + Log.e("AudioHandler setAudioOutputDevice", " unknown output device"); + } + + protected int getAudioOutputDevice(){ + AudioManager audiMgr = (AudioManager) mCtx.getSystemService(Context.AUDIO_SERVICE); + if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_EARPIECE) + return 1; + else if (audiMgr.getRouting(AudioManager.MODE_NORMAL) == AudioManager.ROUTE_SPEAKER) + return 2; + else + return -1; + } +} diff --git a/framework/src/com/phonegap/BrowserKey.java b/framework/src/com/phonegap/BrowserKey.java new file mode 100644 index 00000000..2079e869 --- /dev/null +++ b/framework/src/com/phonegap/BrowserKey.java @@ -0,0 +1,46 @@ +package com.phonegap; + +import android.app.Activity; +import android.util.Log; +import android.webkit.WebView; + +/* + * This class literally exists to protect DroidGap from Javascript directly. + * + * + */ + + +public class BrowserKey { + + DroidGap mAction; + boolean bound; + + WebView mView; + + BrowserKey(WebView view, DroidGap action) + { + bound = false; + } + + public void override() + { + Log.d("PhoneGap", "WARNING: Back Button Default Behaviour will be overridden. The backKeyDown event will be fired!"); + bound = true; + } + + public boolean isBound() + { + return bound; + } + + public void reset() + { + bound = false; + } + + public void exitApp() + { + mAction.finish(); + } +} diff --git a/framework/src/com/phonegap/PhoneGap.java b/framework/src/com/phonegap/Device.java similarity index 67% rename from framework/src/com/phonegap/PhoneGap.java rename to framework/src/com/phonegap/Device.java index 1141e708..074f72f5 100644 --- a/framework/src/com/phonegap/PhoneGap.java +++ b/framework/src/com/phonegap/Device.java @@ -25,8 +25,6 @@ package com.phonegap; import java.util.TimeZone; import android.content.Context; -import android.content.IntentFilter; -import android.hardware.SensorManager; import android.net.Uri; import android.os.Vibrator; import android.provider.Settings; @@ -35,24 +33,23 @@ import android.webkit.WebView; import android.media.Ringtone; import android.media.RingtoneManager; -public class PhoneGap{ +public class Device{ private static final String LOG_TAG = "PhoneGap"; /* * UUID, version and availability */ public boolean droid = true; - public static String version = "0.9.99999"; + public static String version = "0.91"; public static String platform = "Android"; public static String uuid; private Context mCtx; private WebView mAppView; - AudioHandler audio; + AudioPlayer audio; - public PhoneGap(WebView appView, Context ctx) { + public Device(WebView appView, Context ctx) { this.mCtx = ctx; this.mAppView = appView; - audio = new AudioHandler("/sdcard/tmprecording.mp3", ctx); uuid = getUuid(); } @@ -87,22 +84,25 @@ public class PhoneGap{ return uuid; } - public String getLine1Number(){ + public String getLine1Number(){ TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); return operator.getLine1Number(); - } + } + public String getDeviceId(){ TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); return operator.getDeviceId(); - } + } + public String getSimSerialNumber(){ TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); return operator.getSimSerialNumber(); } - public String getSubscriberId(){ + + public String getSubscriberId(){ TelephonyManager operator = (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); return operator.getSubscriberId(); - } + } public String getModel() { @@ -129,66 +129,6 @@ public class PhoneGap{ { return version; } - - - public void httpGet(String url, String file) - /** - * grabs a file from specified url and saves it to a name and location - * the base directory /sdcard is abstracted so that paths may be the same from one mobile OS to another - * TODO: JavaScript call backs and error handling - */ - { - HttpHandler http = new HttpHandler(); - http.get(url, file); - } - - /** - * AUDIO - * TODO: Basic functions done but needs more work on error handling and call backs, remove record hack - */ - - public void startRecordingAudio(String file) - { - /* for this to work the recording needs to be specified in the constructor, - * a hack to get around this, I'm moving the recording after it's complete - */ - audio.startRecording(file); - } - - public void stopRecordingAudio() - { - audio.stopRecording(); - } - - public void startPlayingAudio(String file) - { - audio.startPlaying(file); - } - - public void stopPlayingAudio() - { - audio.stopPlaying(); - } - - public long getCurrentPositionAudio() - { - System.out.println(audio.getCurrentPosition()); - return(audio.getCurrentPosition()); - } - - public long getDurationAudio(String file) - { - System.out.println(audio.getDuration(file)); - return(audio.getDuration(file)); - } - - public void setAudioOutputDevice(int output){ - audio.setAudioOutputDevice(output); - } - - public int getAudioOutputDevice(){ - return audio.getAudioOutputDevice(); - } public String getTimeZoneID() { TimeZone tz = TimeZone.getDefault(); diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 6a746e72..299710bc 100644 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -53,7 +53,7 @@ public class DroidGap extends Activity { protected WebView appView; private LinearLayout root; - private PhoneGap gap; + private Device gap; private GeoBroker geo; private AccelBroker accel; private CameraLauncher launcher; @@ -64,6 +64,7 @@ public class DroidGap extends Activity { private Storage cupcakeStorage; private CryptoHandler crypto; private BrowserKey mKey; + private AudioHandler audio; /** Called when the activity is first created. */ @Override @@ -134,7 +135,7 @@ public class DroidGap extends Activity { private void bindBrowser(WebView appView) { - gap = new PhoneGap(appView, this); + gap = new Device(appView, this); geo = new GeoBroker(appView, this); accel = new AccelBroker(appView, this); launcher = new CameraLauncher(appView, this); @@ -144,6 +145,7 @@ public class DroidGap extends Activity { mCompass = new CompassListener(appView, this); crypto = new CryptoHandler(appView); mKey = new BrowserKey(appView, this); + audio = new AudioHandler(appView, this); // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(gap, "DroidGap"); @@ -156,6 +158,7 @@ public class DroidGap extends Activity { appView.addJavascriptInterface(mCompass, "CompassHook"); appView.addJavascriptInterface(crypto, "GapCrypto"); appView.addJavascriptInterface(mKey, "BackButton"); + appView.addJavascriptInterface(audio, "GapAudio"); if (android.os.Build.VERSION.RELEASE.startsWith("1.")) From bab03882e1c8541860b4d2d7c0c2a9a7c76e2d0c Mon Sep 17 00:00:00 2001 From: Joe Bowser Date: Tue, 8 Jun 2010 16:36:07 -0700 Subject: [PATCH 3/3] framework/assets/js/media.js --- framework/assets/js/media.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/assets/js/media.js b/framework/assets/js/media.js index eaf433b6..17e0db73 100644 --- a/framework/assets/js/media.js +++ b/framework/assets/js/media.js @@ -44,19 +44,19 @@ MediaError.MEDIA_ERR_NONE_SUPPORTED = 4; */ Media.prototype.play = function() { - DroidGap.startPlayingAudio(this.src); + GapAudio.startPlayingAudio(this.src); } Media.prototype.stop = function() { - DroidGap.stopPlayingAudio(); + GapAudio.stopPlayingAudio(); } Media.prototype.startRecord = function() { - DroidGap.startRecordingAudio(this.src); + GapAudio.startRecordingAudio(this.src); } Media.prototype.stopRecordingAudio = function() { - DroidGap.stopRecordingAudio(); + GapAudio.stopRecordingAudio(); }