Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi! I cleaned up your code for you! #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions default.properties
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
38 changes: 19 additions & 19 deletions src/kalsms/niryariv/itp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <b>" + this.identifier + "</b>";
}

infoText += " are now sent to <b>" + this.targetUrl +"</b> in the following format:";
infoText += "<p><tt>GET " + this.targetUrl + "?sender=&lt;phone#&gt;&msg=&lt;message&gt;</tt></p>";
infoText += "If the response body contains text, it will SMSed back to the sender.";

infoText += "<br /><br /><b>Press Menu to set SMS identifier or target URL.</b>";

infoText += "<br /><br /><br />Questions/feedback: [email protected]";

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) {
Expand All @@ -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();
}

}
4 changes: 2 additions & 2 deletions src/kalsms/niryariv/itp/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
68 changes: 34 additions & 34 deletions src/kalsms/niryariv/itp/SMSReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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<ArrayList<String>> 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);
Expand All @@ -93,21 +93,21 @@ public void onReceive(Context context, Intent intent) {
}
}
}

// delete SMS from inbox, to prevent it from filling up
DeleteSMSFromInbox(context, mesg);

}
}

}

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() + "'");
Expand All @@ -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;
Expand All @@ -144,22 +144,22 @@ private SmsMessage[] getMessagesFromIntent(Intent intent) {
}
return retMsgs;
}


public String openURL(String sender, String message, String targetUrl) {

List<NameValuePair> qparams = new ArrayList<NameValuePair>();
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;
Expand All @@ -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<ArrayList<String>> parseXML(String xml) {
ArrayList<ArrayList<String>> output = new ArrayList<ArrayList<String>>();

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<String> item = new ArrayList<String>();

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"));
Expand All @@ -221,5 +221,5 @@ public static ArrayList<ArrayList<String>> parseXML(String xml) {
e.printStackTrace();
return (output);
}
}
}
}
2 changes: 1 addition & 1 deletion src/kalsms/niryariv/itp/URLopen.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// final String s = new String(baf.toByteArray());
//// mHandler.post(showUpdate);
// } catch (Exception e) {
// //
// //
// }
// }
// };
Expand Down