diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index d10b44a..ce8d72d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -10,6 +10,7 @@
+
+
\ No newline at end of file
diff --git a/res/layout/sms.xml b/res/layout/sms.xml
new file mode 100644
index 0000000..0bee917
--- /dev/null
+++ b/res/layout/sms.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/net/zaczek/launcherforblind/Helper.java b/src/net/zaczek/launcherforblind/Helper.java
index d6f5848..c66f3ba 100644
--- a/src/net/zaczek/launcherforblind/Helper.java
+++ b/src/net/zaczek/launcherforblind/Helper.java
@@ -1,9 +1,12 @@
package net.zaczek.launcherforblind;
import net.zaczek.launcherforblind.activitysupport.AbstractActivity;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
+import android.database.Cursor;
import android.net.Uri;
+import android.provider.ContactsContract.PhoneLookup;
public class Helper {
public static boolean actuallyDial = true;
@@ -21,4 +24,28 @@ public static void dial(Context ctx, String number) {
+ Uri.encode(number))));
}
}
+
+ /*
+ * Returns the contact name to a given number or returns the number if no name was found
+ */
+ public static String getContactName(Context ctx, String phoneNumber) {
+ ContentResolver cr = ctx.getContentResolver();
+ Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
+ Uri.encode(phoneNumber));
+ Cursor cursor = cr.query(uri,
+ new String[] { PhoneLookup.DISPLAY_NAME }, null, null, null);
+ if (cursor == null) {
+ return null;
+ }
+ String contactName = phoneNumber;
+ if (cursor.moveToFirst()) {
+ contactName = cursor.getString(cursor
+ .getColumnIndex(PhoneLookup.DISPLAY_NAME));
+ }
+ if (cursor != null && !cursor.isClosed()) {
+ cursor.close();
+ }
+ return contactName;
+ }
+
}
diff --git a/src/net/zaczek/launcherforblind/MainActivity.java b/src/net/zaczek/launcherforblind/MainActivity.java
index bb24a13..c781fe0 100644
--- a/src/net/zaczek/launcherforblind/MainActivity.java
+++ b/src/net/zaczek/launcherforblind/MainActivity.java
@@ -33,9 +33,10 @@ protected ListEntry[] getList() {
DialerActivity.class),
new NavigatorListEntry(getString(R.string.missedcalls), this,
MissedCallsActivity.class),
+ new NavigatorListEntry(getString(R.string.sms), this,
+ SMSActivity.class),
new NavigatorListEntry(getString(R.string.apps), this,
AppsActivity.class),
- // new NavigatorListEntry(getString(R.string.sms), this, null),
new TimeListEntry(getString(R.string.currenttime),
getString(R.string.time_format)), };
}
diff --git a/src/net/zaczek/launcherforblind/SMSActivity.java b/src/net/zaczek/launcherforblind/SMSActivity.java
new file mode 100644
index 0000000..a33c4fe
--- /dev/null
+++ b/src/net/zaczek/launcherforblind/SMSActivity.java
@@ -0,0 +1,48 @@
+package net.zaczek.launcherforblind;
+
+import net.zaczek.launcherforblind.activitysupport.AbstractCursorActivity;
+import net.zaczek.launcherforblind.listentries.ListEntry;
+import net.zaczek.launcherforblind.listentries.SMSListEntry;
+import android.database.Cursor;
+import android.net.Uri;
+import android.os.Bundle;
+import android.text.format.DateUtils;
+import android.util.Log;
+import android.widget.TextView;
+
+public class SMSActivity extends AbstractCursorActivity {
+ private static final String TAG = "launcherforblind";
+
+ private static final String[] PROJECTION = new String[] { "address", "date", "body" };
+
+ private TextView txtMain;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ Log.i(TAG, "onCreate");
+ setContentView(R.layout.sms);
+
+ txtMain = (TextView) findViewById(R.id.txtMain);
+ }
+
+ @Override
+ protected Cursor getCursor() {
+ Cursor c = managedQuery(Uri.parse("content://sms/inbox"), PROJECTION,
+ null, null, "date DESC");
+ return c;
+ }
+
+ @Override
+ protected ListEntry getListEntry(Cursor c) {
+ long date = c.getLong(1);
+ String strDate = DateUtils.formatDateTime(this, date,
+ DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_TIME);
+ return new SMSListEntry(this, c.getString(0), strDate, c.getString(2));
+ }
+
+ @Override
+ protected void giveFeedback(String label) {
+ txtMain.setText(label);
+ }
+}
diff --git a/src/net/zaczek/launcherforblind/listentries/SMSListEntry.java b/src/net/zaczek/launcherforblind/listentries/SMSListEntry.java
new file mode 100644
index 0000000..75ce1da
--- /dev/null
+++ b/src/net/zaczek/launcherforblind/listentries/SMSListEntry.java
@@ -0,0 +1,28 @@
+package net.zaczek.launcherforblind.listentries;
+
+import net.zaczek.launcherforblind.Helper;
+import android.content.Context;
+
+public class SMSListEntry extends AbstractListEntry {
+ String mNumber;
+ String mDate;
+ String mMessage;
+ Context mCtx;
+
+ public SMSListEntry(Context ctx, String number, String date, String msg) {
+ super(date);
+ mCtx = ctx;
+ mNumber = number;
+ mDate = date;
+ mMessage = msg;
+ }
+
+ @Override
+ public String getLabelToSay() {
+ return Helper.getContactName(mCtx, mNumber) + ", " + mDate + ".\n" + mMessage;
+ }
+
+ public String getNumber() {
+ return mNumber;
+ }
+}