diff --git a/.classpath b/.classpath index ae50e9d9..9f892e85 100644 --- a/.classpath +++ b/.classpath @@ -1,6 +1,6 @@ - + diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 57a440a4..4aac3e48 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -12,6 +12,7 @@ + diff --git a/assets/gap.js b/assets/gap.js index b81f3dc5..30236518 100644 --- a/assets/gap.js +++ b/assets/gap.js @@ -4,7 +4,7 @@ * website: http://phonegap.com * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the - * “Software”), to deal in the Software without restriction, including + * Software), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to @@ -13,7 +13,7 @@ * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE @@ -284,16 +284,29 @@ var Device = { return Device.exec("vibrate") }, - playSound: function(clip) { - xsound = "sound:"; - if (Device.whatPlatform == "Android") { - xsound = "playSound"; - return Device.exec(xsound + clip); - } - - return Device.exec(xsound + clip); + playSound: function(clip) { + xsound = "sound:"; + if (Device.whatPlatform == "Android") { + xsound = "playSound"; + return Device.exec(xsound + clip); + } + return Device.exec(xsound + clip); + }, + + notification: { + watchPosition: function(filter) { + window.DroidGap.notificationWatchPosition(filter); + }, + clearWatch: function(filter) { + window.DroidGap.notificationClearWatch(filter); + } + }, + + http: { + get: function(url, file) { + window.DroidGap.httpGet(url, file); } - + } } function gotLocation(lat, lon) { @@ -301,3 +314,4 @@ function gotLocation(lat, lon) { return Device.Location.set(lat, lon) } + diff --git a/assets/index.html b/assets/index.html index de87a53e..d069a134 100644 --- a/assets/index.html +++ b/assets/index.html @@ -86,6 +86,31 @@ updateAccel = function(){ } +receiveSmsNotification = function(func) +{ + if (func == 'watchPosition') { + Device.notification.watchPosition('SMS'); + } else + if (func == 'clearWatch') { + Device.notification.clearWatch('SMS'); + } +} + +function onReceiveSms(number, message) +{ + $('number').value = number; + $('message').value = message; +} + +http = function(func) +{ + if (func == 'get') { + Device.http.get($('httpGetUrl').value, $('httpGetFile').value) + } +} + + + addLoadEvent(initGap); @@ -105,6 +130,8 @@ addLoadEvent(initGap);
  • Vibration
  • Play Sound
  • Photo...
  • +
  • Notification...
  • +
  • HTTP...
  • About
  • @@ -218,6 +245,48 @@ addLoadEvent(initGap); +
    +

    Notification

    +
    + +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    +
    +

    HTTP

    +

    Make sure your Android sdk sdcard is mounted!

    +
    + +
    +
    +
    + + +
    +
    +
    +
    + + +
    +
    +
    -
    \ No newline at end of file +
    diff --git a/bin/DroidGap.apk b/bin/DroidGap.apk index 1294fd45..e7deffed 100644 Binary files a/bin/DroidGap.apk and b/bin/DroidGap.apk differ diff --git a/bin/classes.dex b/bin/classes.dex index 4fc49a6d..f89159ba 100644 Binary files a/bin/classes.dex and b/bin/classes.dex differ diff --git a/bin/com/nitobi/phonegap/AccelTuple.class b/bin/com/nitobi/phonegap/AccelTuple.class index c169d985..b023969b 100644 Binary files a/bin/com/nitobi/phonegap/AccelTuple.class and b/bin/com/nitobi/phonegap/AccelTuple.class differ diff --git a/bin/com/nitobi/phonegap/CameraHandler.class b/bin/com/nitobi/phonegap/CameraHandler.class index d1c55bae..87db7fad 100644 Binary files a/bin/com/nitobi/phonegap/CameraHandler.class and b/bin/com/nitobi/phonegap/CameraHandler.class differ diff --git a/bin/com/nitobi/phonegap/CameraListener.class b/bin/com/nitobi/phonegap/CameraListener.class index 6d5eb962..fd0cf9be 100644 Binary files a/bin/com/nitobi/phonegap/CameraListener.class and b/bin/com/nitobi/phonegap/CameraListener.class differ diff --git a/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class b/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class index d08936f0..ad51e474 100644 Binary files a/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class and b/bin/com/nitobi/phonegap/DroidGap$MyWebChromeClient.class differ diff --git a/bin/com/nitobi/phonegap/DroidGap.class b/bin/com/nitobi/phonegap/DroidGap.class index 084c9d5f..132a749e 100644 Binary files a/bin/com/nitobi/phonegap/DroidGap.class and b/bin/com/nitobi/phonegap/DroidGap.class differ diff --git a/bin/com/nitobi/phonegap/GeoTuple.class b/bin/com/nitobi/phonegap/GeoTuple.class index 93bc4a86..abc64963 100644 Binary files a/bin/com/nitobi/phonegap/GeoTuple.class and b/bin/com/nitobi/phonegap/GeoTuple.class differ diff --git a/bin/com/nitobi/phonegap/GpsListener.class b/bin/com/nitobi/phonegap/GpsListener.class index 64b88b96..582bcc94 100644 Binary files a/bin/com/nitobi/phonegap/GpsListener.class and b/bin/com/nitobi/phonegap/GpsListener.class differ diff --git a/bin/com/nitobi/phonegap/HttpHandler.class b/bin/com/nitobi/phonegap/HttpHandler.class new file mode 100644 index 00000000..832e6c93 Binary files /dev/null and b/bin/com/nitobi/phonegap/HttpHandler.class differ diff --git a/bin/com/nitobi/phonegap/NetworkListener.class b/bin/com/nitobi/phonegap/NetworkListener.class index 9fde9fbe..1fd9193f 100644 Binary files a/bin/com/nitobi/phonegap/NetworkListener.class and b/bin/com/nitobi/phonegap/NetworkListener.class differ diff --git a/bin/com/nitobi/phonegap/Orientation.class b/bin/com/nitobi/phonegap/Orientation.class index f654506c..a5595ae2 100644 Binary files a/bin/com/nitobi/phonegap/Orientation.class and b/bin/com/nitobi/phonegap/Orientation.class differ diff --git a/bin/com/nitobi/phonegap/PhoneGap$1.class b/bin/com/nitobi/phonegap/PhoneGap$1.class index a30a025b..205e8096 100644 Binary files a/bin/com/nitobi/phonegap/PhoneGap$1.class and b/bin/com/nitobi/phonegap/PhoneGap$1.class differ diff --git a/bin/com/nitobi/phonegap/PhoneGap$2.class b/bin/com/nitobi/phonegap/PhoneGap$2.class index 35be8929..78cc1a05 100644 Binary files a/bin/com/nitobi/phonegap/PhoneGap$2.class and b/bin/com/nitobi/phonegap/PhoneGap$2.class differ diff --git a/bin/com/nitobi/phonegap/PhoneGap.class b/bin/com/nitobi/phonegap/PhoneGap.class index 20e6eac2..52e39721 100644 Binary files a/bin/com/nitobi/phonegap/PhoneGap.class and b/bin/com/nitobi/phonegap/PhoneGap.class differ diff --git a/bin/com/nitobi/phonegap/R$attr.class b/bin/com/nitobi/phonegap/R$attr.class index f94be60a..23dc64ed 100644 Binary files a/bin/com/nitobi/phonegap/R$attr.class and b/bin/com/nitobi/phonegap/R$attr.class differ diff --git a/bin/com/nitobi/phonegap/R$drawable.class b/bin/com/nitobi/phonegap/R$drawable.class index e81430a8..862620ca 100644 Binary files a/bin/com/nitobi/phonegap/R$drawable.class and b/bin/com/nitobi/phonegap/R$drawable.class differ diff --git a/bin/com/nitobi/phonegap/R$id.class b/bin/com/nitobi/phonegap/R$id.class index 21850e97..ef630e1a 100644 Binary files a/bin/com/nitobi/phonegap/R$id.class and b/bin/com/nitobi/phonegap/R$id.class differ diff --git a/bin/com/nitobi/phonegap/R$layout.class b/bin/com/nitobi/phonegap/R$layout.class index c43a5eea..6d977387 100644 Binary files a/bin/com/nitobi/phonegap/R$layout.class and b/bin/com/nitobi/phonegap/R$layout.class differ diff --git a/bin/com/nitobi/phonegap/R$raw.class b/bin/com/nitobi/phonegap/R$raw.class index 145e16cb..21cf9055 100644 Binary files a/bin/com/nitobi/phonegap/R$raw.class and b/bin/com/nitobi/phonegap/R$raw.class differ diff --git a/bin/com/nitobi/phonegap/R$string.class b/bin/com/nitobi/phonegap/R$string.class index 1994ce71..53d84ae2 100644 Binary files a/bin/com/nitobi/phonegap/R$string.class and b/bin/com/nitobi/phonegap/R$string.class differ diff --git a/bin/com/nitobi/phonegap/R.class b/bin/com/nitobi/phonegap/R.class index 942c719f..16bcfcf5 100644 Binary files a/bin/com/nitobi/phonegap/R.class and b/bin/com/nitobi/phonegap/R.class differ diff --git a/bin/com/nitobi/phonegap/SmsListener.class b/bin/com/nitobi/phonegap/SmsListener.class new file mode 100644 index 00000000..c174d51f Binary files /dev/null and b/bin/com/nitobi/phonegap/SmsListener.class differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ index 7cb51327..b5044bb1 100644 Binary files a/bin/resources.ap_ and b/bin/resources.ap_ differ diff --git a/src/com/nitobi/phonegap/HttpHandler.java b/src/com/nitobi/phonegap/HttpHandler.java new file mode 100644 index 00000000..f4912928 --- /dev/null +++ b/src/com/nitobi/phonegap/HttpHandler.java @@ -0,0 +1,65 @@ +package com.nitobi.phonegap; + +import java.io.EOFException; +import java.io.FileOutputStream; +import java.io.InputStream; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.DefaultHttpClient; + +public class HttpHandler { + + public Boolean get(String url, String file) + { + HttpEntity entity = getHttpEntity(url); + try { + writeToDisk(entity, file); + } catch (Exception e) { e.printStackTrace(); return false; } + try { + entity.consumeContent(); + } catch (Exception e) { e.printStackTrace(); return false; } + return true; + } + + private HttpEntity getHttpEntity(String url) + /** + * get the http entity at a given url + */ + { + HttpEntity entity=null; + try { + DefaultHttpClient httpclient = new DefaultHttpClient(); + HttpGet httpget = new HttpGet(url); + HttpResponse response = httpclient.execute(httpget); + entity = response.getEntity(); + } catch (Exception e) { e.printStackTrace(); return null; } + return entity; + } + + private void writeToDisk(HttpEntity entity, String file) throws EOFException + /** + * writes a HTTP entity to the specified filename and location on disk + */ + { + int i=0; + String FilePath="/sdcard/" + file; + try { + InputStream in = entity.getContent(); + byte buff[] = new byte[1024]; + FileOutputStream out= + new FileOutputStream(FilePath); + do { + int numread = in.read(buff); + if (numread <= 0) + break; + out.write(buff, 0, numread); + System.out.println("numread" + numread); + i++; + } while (true); + out.flush(); + out.close(); + } catch (Exception e) { e.printStackTrace(); } + } +} diff --git a/src/com/nitobi/phonegap/PhoneGap.java b/src/com/nitobi/phonegap/PhoneGap.java index 1d930f54..faccb4be 100644 --- a/src/com/nitobi/phonegap/PhoneGap.java +++ b/src/com/nitobi/phonegap/PhoneGap.java @@ -4,7 +4,7 @@ package com.nitobi.phonegap; * website: http://phonegap.com * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the - * “Software”), to deal in the Software without restriction, including + * Software), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to @@ -13,7 +13,7 @@ package com.nitobi.phonegap; * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * - * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, + * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE @@ -24,17 +24,14 @@ package com.nitobi.phonegap; import java.io.IOException; import android.content.Context; +import android.content.IntentFilter; import android.hardware.SensorManager; import android.location.Location; -import android.location.LocationManager; -import android.location.LocationListener; import android.location.LocationProvider; import android.media.MediaPlayer; -import android.os.Bundle; import android.os.Handler; import android.os.Vibrator; import android.telephony.TelephonyManager; -import android.util.Log; import android.webkit.WebView; public class PhoneGap{ @@ -51,6 +48,7 @@ public class PhoneGap{ private GpsListener mGps; private NetworkListener mNetwork; protected LocationProvider provider; + SmsListener mSmsListener; public PhoneGap(Context ctx, Handler handler, WebView appView) { this.mCtx = ctx; @@ -58,6 +56,7 @@ public class PhoneGap{ this.mAppView = appView; mGps = new GpsListener(ctx); mNetwork = new NetworkListener(ctx); + mSmsListener = new SmsListener(ctx,mAppView); } public void updateAccel(){ @@ -155,11 +154,7 @@ public class PhoneGap{ mp.prepare(); mp.start(); } - - - - - + //mp.setDataSource("file:///android_asset/" + filename); //mp.setDataSource("http://ventrix.nsdc.gr/stuff/TERMITES_SKONH.mp3"); mp.prepare(); @@ -214,5 +209,40 @@ public class PhoneGap{ return version; } + public void notificationWatchPosition(String filter) + /** + * Starts the listener for incoming notifications of type filter + * TODO: JavaScript Call backs for success and error handling. More filter types. + */ + { + if (filter.contains("SMS")) + { + IntentFilter mFilter = new IntentFilter("android.provider.Telephony.SMS_RECEIVED"); + mCtx.registerReceiver(mSmsListener,mFilter); + } + } + public void notificationClearWatch(String filter) + /** + * Stops the listener for incoming notifications of type filter + * TODO: JavaScript Call backs for success and error handling + */ + { + if (filter.contains("SMS")) + { + mCtx.unregisterReceiver(mSmsListener); + } + } + + 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); + } } + diff --git a/src/com/nitobi/phonegap/SmsListener.java b/src/com/nitobi/phonegap/SmsListener.java new file mode 100644 index 00000000..411dad9c --- /dev/null +++ b/src/com/nitobi/phonegap/SmsListener.java @@ -0,0 +1,68 @@ +package com.nitobi.phonegap; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Bundle; +import android.telephony.gsm.SmsMessage; +import android.util.Log; +import android.webkit.WebView; + +public class SmsListener extends BroadcastReceiver +{ + private WebView mAppView; + + public SmsListener(Context ctx, WebView mAppView) + { + this.mAppView = mAppView; + } + + String ACTION = "android.provider.Telephony.SMS_RECEIVED"; + + public void onReceive(Context ctx, Intent intent) + { + SmsMessage[] msg; + if (intent.getAction().equals(ACTION)) + { + msg = getMessagesFromIntent(intent); + String smsContent = null; + String sendersNumber = null; + for(int i=0; i < msg.length; i++) + { + sendersNumber = msg[i].getDisplayOriginatingAddress(); + smsContent = msg[i].getDisplayMessageBody(); + } + onReceiveSMS(sendersNumber, smsContent); + } + } + + public void onReceiveSMS(String sendersNumber, String smsContent) + /** + * Call back to Java Script + */ + { + mAppView.loadUrl("javascript:onReceiveSms('"+sendersNumber+"',"+"'"+ smsContent +"'"+")"); + } + + private SmsMessage[] getMessagesFromIntent(Intent intent) + { + SmsMessage retMsgs[] = null; + Bundle bdl = intent.getExtras(); + try + { + Object pdus[] = (Object [])bdl.get("pdus"); + retMsgs = new SmsMessage[pdus.length]; + for(int n=0; n < pdus.length; n++) + { + byte[] byteData = (byte[])pdus[n]; + retMsgs[n] = SmsMessage.createFromPdu(byteData); + } + } catch(Exception e) + { + Log.e("SMS_getMessagesFromIntent", "fail", e); + } + return retMsgs; + } + +} +