diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 4aac3e48..3be9c6a5 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,11 +13,13 @@ + + + android:label="@string/app_name" android:configChanges="orientation|keyboardHidden"> diff --git a/assets/gap.js b/assets/gap.js index 30236518..4c092701 100644 --- a/assets/gap.js +++ b/assets/gap.js @@ -306,7 +306,82 @@ var Device = { get: function(url, file) { window.DroidGap.httpGet(url, file); } - } + }, + + file: { + result: "", + getFreeDiskSpace: function(){ + Device.file.result = window.DroidGap.getFreeDiskSpace(); + return Device.file.result; + }, + testFileExists: function(file){ + Device.file.result = window.DroidGap.testFileExists(file); + return Device.file.result; + }, + testDirectoryExists: function(file){ + Device.file.result = window.DroidGap.testFileExists(file); + return Device.file.result; + }, + deleteFile: function(file){ + Device.file.result = window.DroidGap.deleteFile(file); + return Device.file.result; + }, + deleteDirectory: function(file){ + Device.file.result = window.DroidGap.deleteDirectory(file); + return Device.file.result; + }, + createDirectory: function(file){ + Device.file.result = window.DroidGap.createDirectory(file); + return Device.file.result; + } + }, + + + audio: { + startRecording: function(file) { + window.DroidGap.startRecordingAudio(file); + }, + stopRecording: function() { + window.DroidGap.stopRecordingAudio(); + }, + startPlaying: function(file) { + window.DroidGap.startPlayingAudio(file); + }, + stopPlaying: function() { + window.DroidGap.stopPlayingAudio(); + }, + getCurrentPosition: function() { + return window.DroidGap.getCurrentPositionAudio(); + }, + getDuration: function(file) { + return window.DroidGap.getDurationAudio(file); + }, + setAudioOutputDevice: function(output){ + window.DroidGap.setAudioOutputDevice(output); + }, + getAudioOutputDevice: function (){ + return window.DroidGap.getAudioOutputDevice(); + } + }, + information: { + getLine1Number: function(){ + return window.DroidGap.getLine1Number(); + }, + getVoiceMailNumber: function(){ + return window.DroidGap.getVoiceMailNumber(); + }, + getNetworkOperatorName: function(){ + return window.DroidGap.getNetworkOperatorName(); + }, + getSimCountryIso: function(){ + return window.DroidGap.getSimCountryIso(); + }, + getTimeZoneID: function(){ + return window.DroidGap.getTimeZoneID(); + } + } + + } function gotLocation(lat, lon) { diff --git a/assets/index.html b/assets/index.html index d069a134..f72433b7 100644 --- a/assets/index.html +++ b/assets/index.html @@ -1,5 +1,6 @@ - + + @@ -105,16 +106,79 @@ function onReceiveSms(number, message) http = function(func) { if (func == 'get') { - Device.http.get($('httpGetUrl').value, $('httpGetFile').value) + Device.http.get($('httpGetUrl').value, $('httpGetFile').value); } } +fileManagement = function(x){ + if (x == 'getFreeDiskSpace'){ + $('file_status').value = Device.file.getFreeDiskSpace(); + }else + if (x == 'testFileExists'){ + $('file_status').value = Device.file.testFileExists($('checkfile').value); + }else + if (x == 'testDirectoryExists'){ + $('file_status').value = Device.file.testDirectoryExists($('checkdir').value); + }else + if (x == 'createDir'){ + $('file_status').value = Device.file.createDirectory($('createfile').value); + }else + if (x == 'delFile'){ + $('file_status').value = Device.file.deleteFile($('delfile').value); + }else + if (x == 'delDir'){ + $('file_status').value = Device.file.deleteDirectory($('deldir').value); + } +} + +audio = function(func) +{ + if (func == 'startPlaying') { + Device.audio.startPlaying($('audioFile').value); + } else + if (func == 'stopPlaying') { + Device.audio.stopPlaying(); + } else + if (func == 'startRecording') { + Device.audio.startRecording($('audioFile').value); + } else + if (func == 'stopRecording') { + Device.audio.stopRecording(); + } else + if (func == 'getCurrentPosition') { + $('posdur').value = Device.audio.getCurrentPosition(); + } else + if (func == 'getDuration') { + $('posdur').value = Device.audio.getDuration($('audioFile').value); + }else + if (func == 'setEarpiece') { + Device.audio.setAudioOutputDevice(1); + } else + if (func == 'setSpeaker') { + Device.audio.setAudioOutputDevice(2); + }else + if (func == 'getAudioOutputDevice') { + $('audoutput').value = Device.audio.getAudioOutputDevice(); + } + +} + +phInformation = function(){ + alert ('Device.information.getLine1Number()'); + $('phnumber').value = Device.information.getLine1Number(); + $('vmnumber').value = Device.information.getVoiceMailNumber(); + $('nwoperator').value = Device.information.getNetworkOperatorName(); + $('simiso').value = Device.information.getSimCountryIso(); + $('tzid').value = Device.information.getTimeZoneID(); +} addLoadEvent(initGap); - + + + Main @@ -130,8 +194,11 @@ addLoadEvent(initGap); Vibration Play Sound Photo... + Audio... Notification... HTTP... + File IO... + Phone Info... About @@ -171,7 +238,6 @@ addLoadEvent(initGap); - Change Location @@ -185,13 +251,10 @@ addLoadEvent(initGap); Update Location - - - Read Location @@ -203,11 +266,9 @@ addLoadEvent(initGap); - - Change Intervals @@ -221,13 +282,10 @@ addLoadEvent(initGap); Set Intervals - - - Accelerometer @@ -289,4 +347,103 @@ addLoadEvent(initGap); - + + file IO + + + File IO + + + + getFreeDiskSpace + + + testFileExists + + + + testDirExists + + + + Create Directory + + + + Delete File + + + + + Delete Directory + + + + + + Audio + Make sure your Android sdk sdcard is mounted! + + + AudioFile: + + + + startRecording + stopRecording + + + startPlaying + stopPlaying + + + info: + + + + getDuration + getPosition + + + Earpiece + Speaker + + + getAudioDevice + + + + + + + + + + Phone NO. + + + + Voice Mail NO. + + + + Operator + + + + Sim Country ISO + + + + Time Zone + + + + + + + + + + + diff --git a/src/com/nitobi/phonegap/DroidGap.java b/src/com/nitobi/phonegap/DroidGap.java index 1a7fe67f..5b925f45 100644 --- a/src/com/nitobi/phonegap/DroidGap.java +++ b/src/com/nitobi/phonegap/DroidGap.java @@ -25,6 +25,7 @@ package com.nitobi.phonegap; import java.lang.reflect.Field; import android.app.Activity; +import android.content.res.Configuration; import android.os.Bundle; import android.os.Handler; import android.util.Log; @@ -79,8 +80,12 @@ public class DroidGap extends Activity { appView.loadUrl(uri); } - - + + @Override + public void onConfigurationChanged(Configuration newConfig) { + //don't reload the current page when the orientation is changed + super.onConfigurationChanged(newConfig); + } private void bindBrowser(WebView appView) { diff --git a/src/com/nitobi/phonegap/HttpHandler.java b/src/com/nitobi/phonegap/HttpHandler.java index f4912928..0f953d8a 100644 --- a/src/com/nitobi/phonegap/HttpHandler.java +++ b/src/com/nitobi/phonegap/HttpHandler.java @@ -11,7 +11,7 @@ import org.apache.http.impl.client.DefaultHttpClient; public class HttpHandler { - public Boolean get(String url, String file) + protected Boolean get(String url, String file) { HttpEntity entity = getHttpEntity(url); try { diff --git a/src/com/nitobi/phonegap/PhoneGap.java b/src/com/nitobi/phonegap/PhoneGap.java index faccb4be..79ed8042 100644 --- a/src/com/nitobi/phonegap/PhoneGap.java +++ b/src/com/nitobi/phonegap/PhoneGap.java @@ -22,6 +22,7 @@ package com.nitobi.phonegap; * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ import java.io.IOException; +import java.util.TimeZone; import android.content.Context; import android.content.IntentFilter; @@ -49,6 +50,8 @@ public class PhoneGap{ private NetworkListener mNetwork; protected LocationProvider provider; SmsListener mSmsListener; + DirectoryManager fileManager; + AudioHandler audio; public PhoneGap(Context ctx, Handler handler, WebView appView) { this.mCtx = ctx; @@ -57,6 +60,8 @@ public class PhoneGap{ mGps = new GpsListener(ctx); mNetwork = new NetworkListener(ctx); mSmsListener = new SmsListener(ctx,mAppView); + fileManager = new DirectoryManager(); + audio = new AudioHandler("/sdcard/tmprecording.mp3", ctx); } public void updateAccel(){ @@ -244,5 +249,149 @@ public class PhoneGap{ HttpHandler http = new HttpHandler(); http.get(url, file); } + + + + + public int testSaveLocationExists(){ + if (fileManager.testSaveLocationExists()) + return 0; + else + return 1; + } + + public long getFreeDiskSpace(){ + long freeDiskSpace=fileManager.getFreeDiskSpace(); + return freeDiskSpace; + } + + public int testFileExists(String file){ + if (fileManager.testFileExists(file)) + return 0; + else + return 1; + } + + public int testDirectoryExists(String file){ + if (fileManager.testFileExists(file)) + return 0; + else + return 1; + } + + /** + * Delete a specific directory. + * Everyting in side the directory would be gone. + * TODO: JavaScript Call backs for success and error handling + */ + public int deleteDirectory (String dir){ + if (fileManager.deleteDirectory(dir)) + return 0; + else + return 1; + } + + + /** + * Delete a specific file. + * TODO: JavaScript Call backs for success and error handling + */ + public int deleteFile (String file){ + if (fileManager.deleteFile(file)) + return 0; + else + return 1; + } + + + /** + * Create a new directory. + * TODO: JavaScript Call backs for success and error handling + */ + public int createDirectory(String dir){ + if (fileManager.createDirectory(dir)) + return 0; + 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(); + } + + public String getLine1Number() { + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getLine1Number()); + } + + public String getVoiceMailNumber() { + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getVoiceMailNumber()); + } + + public String getNetworkOperatorName(){ + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getNetworkOperatorName()); + } + + public String getSimCountryIso(){ + TelephonyManager tm = + (TelephonyManager)mCtx.getSystemService(Context.TELEPHONY_SERVICE); + return(tm.getSimCountryIso()); + } + + public String getTimeZoneID() { + TimeZone tz = TimeZone.getDefault(); + return(tz.getID()); + } + } diff --git a/src/com/nitobi/phonegap/SmsListener.java b/src/com/nitobi/phonegap/SmsListener.java index 411dad9c..a42359bc 100644 --- a/src/com/nitobi/phonegap/SmsListener.java +++ b/src/com/nitobi/phonegap/SmsListener.java @@ -36,7 +36,7 @@ public class SmsListener extends BroadcastReceiver } } - public void onReceiveSMS(String sendersNumber, String smsContent) + protected void onReceiveSMS(String sendersNumber, String smsContent) /** * Call back to Java Script */
Make sure your Android sdk sdcard is mounted!