Skip to content

Commit

Permalink
SMS activity
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurzaczek committed May 12, 2014
1 parent 27c250b commit 65fb900
Show file tree
Hide file tree
Showing 6 changed files with 133 additions and 1 deletion.
4 changes: 4 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CALL_PHONE" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.READ_SMS"/>

<application
android:name="net.zaczek.launcherforblind.MyApplication"
Expand Down Expand Up @@ -40,6 +41,9 @@
<activity
android:name=".AppsActivity"
android:screenOrientation="portrait" />
<activity
android:name=".SMSActivity"
android:screenOrientation="portrait" />
</application>

</manifest>
24 changes: 24 additions & 0 deletions res/layout/sms.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
android:id="@+id/txtMain"
style="@style/Main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:text="@string/sms" />

<TextView
android:id="@+id/txtHelp"
style="@style/Help"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/txtMain"
android:gravity="center"
android:text="@string/main_help" />

</RelativeLayout>
27 changes: 27 additions & 0 deletions src/net/zaczek/launcherforblind/Helper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
}

}
3 changes: 2 additions & 1 deletion src/net/zaczek/launcherforblind/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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)), };
}
Expand Down
48 changes: 48 additions & 0 deletions src/net/zaczek/launcherforblind/SMSActivity.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
28 changes: 28 additions & 0 deletions src/net/zaczek/launcherforblind/listentries/SMSListEntry.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 65fb900

Please sign in to comment.