diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c091839 --- /dev/null +++ b/.gitignore @@ -0,0 +1,50 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Numerous always-ignore extensions +################### +*.diff +*.err +*.orig +*.log +*.rej +*.swo +*.swp +*.vi +*~ + +*.sass-cache +# Folders to ignore +################### +.hg +.svn +.CVS +# OS or Editor folders +################### +.DS_Store +Icon? +Thumbs.db +ehthumbs.db +nbproject +.cache +.project +.settings +.tmproj +*.esproj +*.sublime-project +*.sublime-workspace +# Dreamweaver added files +################### +_notes +dwsync.xml +# Komodo +################### +*.komodoproject +.komodotools diff --git a/default.properties b/default.properties index 9d6f70d..5dad0b5 100644 --- a/default.properties +++ b/default.properties @@ -1,8 +1,8 @@ # This file is automatically generated by Android Tools. # Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# +# # This file must be checked in Version Control Systems. -# +# # To customize properties used by the Ant build system use, # "build.properties", and override values to adapt the script to your # project structure. diff --git a/src/kalsms/niryariv/itp/Main.java b/src/kalsms/niryariv/itp/Main.java index 3f5328f..2e5d7ac 100644 --- a/src/kalsms/niryariv/itp/Main.java +++ b/src/kalsms/niryariv/itp/Main.java @@ -14,55 +14,55 @@ import android.widget.TextView; public class Main extends Activity { - + // public static final String PREFS_NAME = "KalPrefsFile"; - + public String identifier = ""; public String targetUrl = ""; - - + + public void onResume() { Log.d("KALSMS", "RESUME"); super.onResume(); - + SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); - + this.identifier = settings.getString("pref_identifier", ""); this.targetUrl = settings.getString("pref_target_url", ""); Log.d("KALSMS", "onResume ident:" + this.identifier +"\ntarget:" + this.targetUrl); - + String infoText = new String(); - + infoText = "All SMS messages"; - + if (this.identifier.trim() != "") { infoText += " starting with " + this.identifier + ""; } - + infoText += " are now sent to " + this.targetUrl +" in the following format:"; infoText += "

GET " + this.targetUrl + "?sender=<phone#>&msg=<message>

"; infoText += "If the response body contains text, it will SMSed back to the sender."; infoText += "

Press Menu to set SMS identifier or target URL."; - + infoText += "


Questions/feedback: niryariv@gmail.com"; - + TextView info = (TextView) this.findViewById(R.id.info); info.setText(Html.fromHtml(infoText)); - } - + } + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); PreferenceManager.setDefaultValues(this, R.xml.prefs, false); - + Log.d("KALSMS", "STARTED"); } - + // first time the Menu key is pressed public boolean onCreateOptionsMenu(Menu menu) { @@ -75,12 +75,12 @@ public boolean onPrepareOptionsMenu(Menu menu) { startActivity(new Intent(this, Prefs.class)); return(true); } - - + + @Override protected void onStop(){ // dont do much with this, atm.. super.onStop(); } - + } diff --git a/src/kalsms/niryariv/itp/Prefs.java b/src/kalsms/niryariv/itp/Prefs.java index 10b3fa1..c787c70 100644 --- a/src/kalsms/niryariv/itp/Prefs.java +++ b/src/kalsms/niryariv/itp/Prefs.java @@ -10,14 +10,14 @@ public class Prefs extends PreferenceActivity { - + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } - + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Preference pref = findPreference(key); diff --git a/src/kalsms/niryariv/itp/SMSReceiver.java b/src/kalsms/niryariv/itp/SMSReceiver.java index 207774c..4aa20c4 100644 --- a/src/kalsms/niryariv/itp/SMSReceiver.java +++ b/src/kalsms/niryariv/itp/SMSReceiver.java @@ -43,7 +43,7 @@ public class SMSReceiver extends BroadcastReceiver { - + @Override // source: http://www.devx.com/wireless/Article/39495/1954 public void onReceive(Context context, Intent intent) { @@ -63,28 +63,28 @@ public void onReceive(Context context, Intent intent) { SmsMessage mesg = msgs[i]; String message = mesg.getDisplayMessageBody(); String sender = mesg.getDisplayOriginatingAddress(); - - if (message != null && message.length() > 0 + + if (message != null && message.length() > 0 && (message.toLowerCase().startsWith(identifier) || identifier.trim() == "")) { Log.d("KALSMS", "MSG RCVD:\"" + message + "\" from: " + sender); - + // send the message to the URL String resp = openURL(sender, message, targetUrl).toString(); - + Log.d("KALSMS", "RESP:\"" + resp); - + // SMS back the response if (resp.trim().length() > 0) { ArrayList> items = parseXML(resp); - + SmsManager smgr = SmsManager.getDefault(); - + for (int j = 0; j < items.size(); j++) { String sendTo = items.get(j).get(0); if (sendTo.toLowerCase() == "sender") sendTo = sender; String sendMsg = items.get(j).get(1); - + try { Log.d("KALSMS", "SEND MSG:\"" + sendMsg + "\" TO: " + sendTo); smgr.sendTextMessage(sendTo, null, sendMsg, null, null); @@ -93,10 +93,10 @@ public void onReceive(Context context, Intent intent) { } } } - + // delete SMS from inbox, to prevent it from filling up DeleteSMSFromInbox(context, mesg); - + } } @@ -104,10 +104,10 @@ public void onReceive(Context context, Intent intent) { private void DeleteSMSFromInbox(Context context, SmsMessage mesg) { Log.d("KALSMS", "try to delete SMS"); - + try { Uri uriSms = Uri.parse("content://sms/inbox"); - + StringBuilder sb = new StringBuilder(); sb.append("address='" + mesg.getOriginatingAddress() + "' AND "); sb.append("body='" + mesg.getMessageBody() + "'"); @@ -125,8 +125,8 @@ private void DeleteSMSFromInbox(Context context, SmsMessage mesg) { } } - - // from http://github.com/dimagi/rapidandroid + + // from http://github.com/dimagi/rapidandroid // source: http://www.devx.com/wireless/Article/39495/1954 private SmsMessage[] getMessagesFromIntent(Intent intent) { SmsMessage retMsgs[] = null; @@ -144,22 +144,22 @@ private SmsMessage[] getMessagesFromIntent(Intent intent) { } return retMsgs; } - + public String openURL(String sender, String message, String targetUrl) { - + List qparams = new ArrayList(); qparams.add(new BasicNameValuePair("sender", sender)); qparams.add(new BasicNameValuePair("msg", message)); String url = targetUrl + "?" + URLEncodedUtils.format(qparams, "UTF-8"); try { - HttpClient client = new DefaultHttpClient(); + HttpClient client = new DefaultHttpClient(); HttpGet get = new HttpGet(url); - - HttpResponse responseGet = client.execute(get); - HttpEntity resEntityGet = responseGet.getEntity(); - if (resEntityGet != null) { + + HttpResponse responseGet = client.execute(get); + HttpEntity resEntityGet = responseGet.getEntity(); + if (resEntityGet != null) { String resp = EntityUtils.toString(resEntityGet); Log.e("KALSMS", "HTTP RESP" + resp); return resp; @@ -168,34 +168,34 @@ public String openURL(String sender, String message, String targetUrl) { Log.e("KALSMS", "HTTP REQ FAILED:" + url); e.printStackTrace(); } - + return ""; } - - + + public static ArrayList> parseXML(String xml) { ArrayList> output = new ArrayList>(); - + try { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(new InputSource(new StringReader(xml))); - + NodeList rnodes = doc.getElementsByTagName("reply"); - - NodeList nodes = rnodes.item(0).getChildNodes(); - + + NodeList nodes = rnodes.item(0).getChildNodes(); + for (int i=0; i < nodes.getLength(); i++) { try { List item = new ArrayList(); - + Node node = nodes.item(i); if (node.getNodeType() != Node.ELEMENT_NODE) continue; - + Element e = (Element) node; String nodeName = e.getNodeName(); - + if (nodeName.equalsIgnoreCase("sms")) { if (!e.getAttribute("phone").equals("")) { item.add(e.getAttribute("phone")); @@ -221,5 +221,5 @@ public static ArrayList> parseXML(String xml) { e.printStackTrace(); return (output); } - } + } } diff --git a/src/kalsms/niryariv/itp/URLopen.java b/src/kalsms/niryariv/itp/URLopen.java index 4aa8c1f..241062a 100644 --- a/src/kalsms/niryariv/itp/URLopen.java +++ b/src/kalsms/niryariv/itp/URLopen.java @@ -27,7 +27,7 @@ // final String s = new String(baf.toByteArray()); //// mHandler.post(showUpdate); // } catch (Exception e) { -// // +// // // } // } // };