diff --git a/src/com/phonegap/demo/DroidGap.java b/src/com/phonegap/demo/DroidGap.java index 0ad6767b..1a491730 100644 --- a/src/com/phonegap/demo/DroidGap.java +++ b/src/com/phonegap/demo/DroidGap.java @@ -47,6 +47,7 @@ public class DroidGap extends Activity { private AccelListener accel; private CameraLauncher launcher; private ContactManager mContacts; + private FileUtils fs; /** Called when the activity is first created. */ @Override @@ -100,12 +101,15 @@ public class DroidGap extends Activity { accel = new AccelListener(this, appView); launcher = new CameraLauncher(appView, this); mContacts = new ContactManager(this, appView); + fs = new FileUtils(); + // This creates the new javascript interfaces for PhoneGap appView.addJavascriptInterface(gap, "DroidGap"); appView.addJavascriptInterface(geo, "Geo"); appView.addJavascriptInterface(accel, "Accel"); appView.addJavascriptInterface(launcher, "GapCam"); appView.addJavascriptInterface(mContacts, "ContactHook"); + appView.addJavascriptInterface(fs, "FileUtil"); } /** @@ -159,4 +163,4 @@ public class DroidGap extends Activity { } } -} \ No newline at end of file +} diff --git a/src/com/phonegap/demo/FileUtils.java b/src/com/phonegap/demo/FileUtils.java new file mode 100644 index 00000000..d352c7ab --- /dev/null +++ b/src/com/phonegap/demo/FileUtils.java @@ -0,0 +1,104 @@ +package com.phonegap.demo; + +import java.io.*; + +public class FileUtils { + + DirectoryManager fileManager; + FileReader f_in; + FileWriter f_out; + + 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; + } + + public String read(String filename) + { + String data = ""; + String output = ""; + try { + FileInputStream fstream = new FileInputStream(filename); + DataInputStream in = new DataInputStream(fstream); + while (in.available() !=0) + { + data += in.readLine(); + } + } catch (FileNotFoundException e) { + data = "FAIL: File not found"; + } catch (IOException e) { + data = "FAIL: IO ERROR"; + } + + return data; + } + + public int write(String filename, String data) + { + try { + FileOutputStream out = new FileOutputStream(filename); + PrintStream p = new PrintStream(out); + p.print(data); + } catch (FileNotFoundException e) { + return -1; + } + return 0; + } +} diff --git a/src/com/phonegap/demo/PhoneGap.java b/src/com/phonegap/demo/PhoneGap.java index 021a2308..1a9f53f5 100644 --- a/src/com/phonegap/demo/PhoneGap.java +++ b/src/com/phonegap/demo/PhoneGap.java @@ -21,13 +21,12 @@ package com.phonegap.demo; * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * 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; import android.net.Uri; -import android.os.Handler; import android.os.Vibrator; import android.telephony.TelephonyManager; import android.webkit.WebView; @@ -41,7 +40,7 @@ public class PhoneGap{ * UUID, version and availability */ public boolean droid = true; - public static String version = "0.2"; + public static String version = "0.8.0"; public static String platform = "Android"; public static String uuid; private Context mCtx; @@ -62,9 +61,8 @@ public class PhoneGap{ public void beep(long pattern) { - RingtoneManager beeper = new RingtoneManager(mCtx); - Uri ringtone = beeper.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); - Ringtone notification = beeper.getRingtone(mCtx, ringtone); + Uri ringtone = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); + Ringtone notification = RingtoneManager.getRingtone(mCtx, ringtone); for (long i = 0; i < pattern; ++i) { notification.play(); @@ -162,9 +160,6 @@ public class PhoneGap{ http.get(url, file); } - - - /** * AUDIO * TODO: Basic functions done but needs more work on error handling and call backs, remove record hack