summaryrefslogtreecommitdiff
path: root/workspace/BlaMail/src
diff options
context:
space:
mode:
authorLuke Miller <lgdmiller@hotmail.com>2010-11-04 12:23:01 +0000
committerLuke Miller <lgdmiller@hotmail.com>2010-11-04 12:23:01 +0000
commitc57ee288195b0b1f37aeaa0693c560f0593a7f9e (patch)
treec76b310baf2d6ac7ef4f1b1958086963dc14a3c0 /workspace/BlaMail/src
parent1b34eb31837a176d8d021791e78ec81bb084ecc2 (diff)
Fixed bug that would cause multiple threads to be created, each sending an SMS when an e-mail was received. Changed notifications to match the android documentation.
Diffstat (limited to 'workspace/BlaMail/src')
-rw-r--r--workspace/BlaMail/src/com/blatech/blamail/BlaMail.java85
1 files changed, 80 insertions, 5 deletions
diff --git a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
index 5c14e0a..b3397eb 100644
--- a/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
+++ b/workspace/BlaMail/src/com/blatech/blamail/BlaMail.java
@@ -78,19 +78,52 @@ public class BlaMail extends Activity {
@Override
public void onDataConnectionStateChanged(int state){
Thread t = null;
+ //Thread s = null;
try {
switch (state) {
- case TelephonyManager.DATA_CONNECTED:
- sendSMS("0000000000000000000", "07927278978", "Notification from blamail: blamail is up.");
+ case TelephonyManager.DATA_CONNECTED:
+ if(t != null){
+ t.destroy(); //not good practice. TODO: fix this!
+ }
+ sendSMS("0000000000000000000", "07927278978", "!blamail Notification from blamail: Connected. IP traffic should be available.");
t = new Thread(new Monitor());
t.start();
break;
case TelephonyManager.DATA_DISCONNECTED:
- sendSMS("0000000000000000000", "07927278978", "Notification from blamail: blamail is down.");
+ sendSMS("0000000000000000000", "07927278978", "!blamail Notification from blamail: Disconnected. IP traffic not available.");
if(t != null){
- t.interrupt();
+ t.destroy(); //not good practice. TODO: fix this!
+ //t.interrupt();
+ //s = new Thread(new StopIdle());
+ //s.start();
}
break;
+ case TelephonyManager.DATA_ACTIVITY_DORMANT:
+ if(t != null){
+ sendSMS("0000000000000000000", "07927278978", "!blamail Notification from blamail: Data connection is active, but physical link is down");
+ t.destroy(); //not good practice. TODO: fix this!
+ //t.interrupt();
+ //s = new Thread(new StopIdle());
+ //s.start();
+ }
+ break;
+ case TelephonyManager.DATA_SUSPENDED:
+ if(t != null){
+ sendSMS("0000000000000000000", "07927278978", "!blamail Notification from blamail: Suspended. The connection is up, but IP traffic is temporarily unavailable. For example, in a 2G network, data activity may be suspended when a voice call arrives.");
+ t.destroy(); //not good practice. TODO: fix this!
+ //t.interrupt();
+ //s = new Thread(new StopIdle());
+ //s.start();
+ }
+ break;
+ case TelephonyManager.DATA_CONNECTING:
+ if(t != null){
+ sendSMS("0000000000000000000", "07927278978", "!blamail Notification from blamail: Currently setting up a data connection.");
+ t.destroy(); //not good practice. TODO: fix this!
+ //t.interrupt();
+ //s = new Thread(new StopIdle());
+ //s.start();
+ }
}
} catch (AddressException e) {
// TODO Auto-generated catch block
@@ -124,6 +157,42 @@ public class BlaMail extends Activity {
});
}
+ /*private class StopIdle implements Runnable {
+ public void run() {
+ try {
+ Properties props = new Properties();
+
+ props.put("mail.smtps.auth", "true");
+
+ //IMAPS protocol
+ props.setProperty("mail.store.protocol", "imaps");
+
+ //Set receiveHost address
+ props.setProperty("mail.imaps.host", "imaps.gmail.com");
+ //Set specified port
+ props.setProperty("mail.imaps.port", "993");
+ //Using SSL
+ props.setProperty("mail.imaps.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
+ props.setProperty("mail.imaps.socketFactory.fallback", "false");
+ //Setting IMAP session
+ Session session = Session.getInstance(props);
+
+ Store store = session.getStore("imaps");
+
+ store.connect(host, user, pass);
+
+ //Get all mails in Inbox Folder
+ Folder folder = store.getFolder(mbox);
+
+ folder.close(false);
+
+ } catch (MessagingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }*/
+
private class Monitor implements Runnable {
String id;
@@ -188,6 +257,12 @@ public class BlaMail extends Activity {
IMAPFolder f = (IMAPFolder)folder;
for(;;){
f.idle();
+ /*sendSMS("0000000000000000000", "07927278978", "idle exited");
+ if (Thread.currentThread().isInterrupted()) {
+ Toast.makeText(getBaseContext(), "Interrupt",
+ Toast.LENGTH_SHORT).show();
+ throw new InterruptedException();
+ }*/
}
} catch (MessagingException e) {
@@ -254,7 +329,7 @@ public class BlaMail extends Activity {
case Activity.RESULT_CANCELED:
deliveredPI.cancel();
unregisterReceiver(this);
- sms.sendTextMessage("07927278978", null, "\"" + message + "\" was not delivered to " + phoneNumber, null, null);
+ sms.sendTextMessage("07927278978", null, "!blamail Notification from blamail: \"" + message + "\" was not delivered to " + phoneNumber, null, null);
break;
}
}