Code cleaning and reformating

This commit is contained in:
Mathieu Maret 2012-11-06 10:35:01 +01:00
parent 95bb2d1651
commit f516231b9c
9 changed files with 723 additions and 716 deletions

View File

@ -19,10 +19,11 @@ import android.util.Log;
public class DeliveryDbAdapter extends ContentProvider {
public static final String PROVIDER_NAME = "com.hectorone.multismssender.provider";
public static final Uri CONTENT_DELIVERY_URI = Uri.parse("content://" + PROVIDER_NAME + "/delivery");
public static final Uri CONTENT_MESSAGE_URI = Uri.parse("content://" + PROVIDER_NAME + "/message");
public static final Uri CONTENT_DELIVERY_URI = Uri.parse("content://"
+ PROVIDER_NAME + "/delivery");
public static final Uri CONTENT_MESSAGE_URI = Uri.parse("content://"
+ PROVIDER_NAME + "/message");
private static final int ENTRIES = 1;
private static final int ENTRY_ID = 2;
@ -38,14 +39,12 @@ public class DeliveryDbAdapter extends ContentProvider {
uriMatcher.addURI(PROVIDER_NAME, "message/#", MESSAGES_ID);
}
public static final String KEY_DELIVERY_ENTRY_ROWID = "_id";
public static final String KEY_DELIVERY_ENTRY_NAME = "name";
public static final String KEY_DELIVERY_ENTRY_NUMBER = "number";
public static final String KEY_DELIVERY_ENTRY_DELIVERED = "delivered";
public static final String KEY_DELIVERY_ENTRY_MESSAGE_ID = "message_id";
public static final String KEY_MESSAGE_ROWID = "_id";
public static final String KEY_MESSAGE_NAME = "name";
public static final String KEY_MESSAGE_DATE = "date";
@ -62,18 +61,16 @@ public class DeliveryDbAdapter extends ContentProvider {
public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
public static final String DATABASE_MESSAGE_TABLE = "message";
public static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table "
+ DATABASE_DELIVERY_ENTRY_TABLE
+ " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, "
+ KEY_DELIVERY_ENTRY_NAME + " text not null,"
+ KEY_DELIVERY_ENTRY_NUMBER + " text not null,"
+ DATABASE_DELIVERY_ENTRY_TABLE + " (" + KEY_DELIVERY_ENTRY_ROWID
+ " integer primary key autoincrement, " + KEY_DELIVERY_ENTRY_NAME
+ " text not null," + KEY_DELIVERY_ENTRY_NUMBER + " text not null,"
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
+ KEY_DELIVERY_ENTRY_MESSAGE_ID + " integer);";
public static final String DATABASE_DELIVERY_CREATE = "create table "
+ DATABASE_MESSAGE_TABLE
+ " (" + KEY_MESSAGE_ROWID + " integer primary key autoincrement, "
+ KEY_MESSAGE_NAME + " text not null,"
+ KEY_MESSAGE_DATE + " text not null);";
+ DATABASE_MESSAGE_TABLE + " (" + KEY_MESSAGE_ROWID
+ " integer primary key autoincrement, " + KEY_MESSAGE_NAME
+ " text not null," + KEY_MESSAGE_DATE + " text not null);";
public static final int DATABASE_VERSION = 4;
@ -83,18 +80,22 @@ public class DeliveryDbAdapter extends ContentProvider {
static {
sDeliveryProjectionMap = new HashMap<String, String>();
sMessageProjectionMap = new HashMap<String, String>();
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_ROWID , KEY_DELIVERY_ENTRY_ROWID);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NAME , KEY_DELIVERY_ENTRY_NAME);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NUMBER , KEY_DELIVERY_ENTRY_NUMBER);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_DELIVERED , KEY_DELIVERY_ENTRY_DELIVERED);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_MESSAGE_ID, KEY_DELIVERY_ENTRY_MESSAGE_ID);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_ROWID,
KEY_DELIVERY_ENTRY_ROWID);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NAME,
KEY_DELIVERY_ENTRY_NAME);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NUMBER,
KEY_DELIVERY_ENTRY_NUMBER);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_DELIVERED,
KEY_DELIVERY_ENTRY_DELIVERED);
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_MESSAGE_ID,
KEY_DELIVERY_ENTRY_MESSAGE_ID);
sMessageProjectionMap.put(KEY_MESSAGE_ROWID, KEY_MESSAGE_ROWID);
sMessageProjectionMap.put(KEY_MESSAGE_NAME, KEY_MESSAGE_NAME);
sMessageProjectionMap.put(KEY_MESSAGE_DATE, KEY_MESSAGE_DATE);
}
private static class DeliveryDbHelper extends SQLiteOpenHelper {
DeliveryDbHelper(Context context) {
@ -119,8 +120,6 @@ public class DeliveryDbAdapter extends ContentProvider {
}
}
// *********************** Content Provider ****************************************
@Override
@ -130,14 +129,18 @@ public class DeliveryDbAdapter extends ContentProvider {
switch (uriMatcher.match(uri)) {
case ENTRIES:
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, selection, selectionArgs);
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, selection,
selectionArgs);
break;
case ENTRY_ID:
{
case ENTRY_ID: {
String id = uri.getPathSegments().get(1);
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_DELIVERY_ENTRY_ROWID + "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
count = db.delete(
DATABASE_DELIVERY_ENTRY_TABLE,
KEY_DELIVERY_ENTRY_ROWID
+ "="
+ id
+ (!TextUtils.isEmpty(selection) ? " AND ("
+ selection + ')' : ""), selectionArgs);
break;
}
@ -145,11 +148,13 @@ public class DeliveryDbAdapter extends ContentProvider {
count = db.delete(DATABASE_MESSAGE_TABLE, selection, selectionArgs);
break;
case MESSAGES_ID:
{
case MESSAGES_ID: {
String id = uri.getPathSegments().get(1);
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_MESSAGE_ROWID + "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_MESSAGE_ROWID
+ "="
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
}
@ -162,7 +167,6 @@ public class DeliveryDbAdapter extends ContentProvider {
return count;
}
@Override
public String getType(Uri uri) {
switch (uriMatcher.match(uri)) {
@ -179,7 +183,6 @@ public class DeliveryDbAdapter extends ContentProvider {
}
}
@Override
public Uri insert(Uri uri, ContentValues values) {
ContentValues initialValues;
@ -192,20 +195,25 @@ public class DeliveryDbAdapter extends ContentProvider {
switch (uriMatcher.match(uri)) {
case ENTRIES: {
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NAME) == false) {
throw new SQLException(KEY_DELIVERY_ENTRY_NAME+ " must be specified");
throw new SQLException(KEY_DELIVERY_ENTRY_NAME
+ " must be specified");
}
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NUMBER) == false) {
throw new SQLException(KEY_DELIVERY_ENTRY_NUMBER+ " must be specified");
throw new SQLException(KEY_DELIVERY_ENTRY_NUMBER
+ " must be specified");
}
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_MESSAGE_ID) == false) {
throw new SQLException(KEY_DELIVERY_ENTRY_MESSAGE_ID+ " must be specified");
throw new SQLException(KEY_DELIVERY_ENTRY_MESSAGE_ID
+ " must be specified");
}
initialValues.put(KEY_DELIVERY_ENTRY_DELIVERED, 0);
SQLiteDatabase db = mDbHelper.getWritableDatabase();
long rowId = db.insert(DATABASE_DELIVERY_ENTRY_TABLE, null, initialValues);
long rowId = db.insert(DATABASE_DELIVERY_ENTRY_TABLE, null,
initialValues);
if (rowId > 0) {
Uri newUri = ContentUris.withAppendedId( CONTENT_DELIVERY_URI, rowId);
Uri newUri = ContentUris.withAppendedId(CONTENT_DELIVERY_URI,
rowId);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
@ -213,8 +221,7 @@ public class DeliveryDbAdapter extends ContentProvider {
}
case MESSAGES:
{
case MESSAGES: {
if (initialValues.containsKey(KEY_MESSAGE_NAME) == false) {
throw new SQLException(KEY_MESSAGE_NAME + " must be specified");
}
@ -225,7 +232,8 @@ public class DeliveryDbAdapter extends ContentProvider {
SQLiteDatabase db = mDbHelper.getWritableDatabase();
long rowId = db.insert(DATABASE_MESSAGE_TABLE, null, initialValues);
if (rowId > 0) {
Uri newUri = ContentUris.withAppendedId( CONTENT_MESSAGE_URI, rowId);
Uri newUri = ContentUris.withAppendedId(CONTENT_MESSAGE_URI,
rowId);
getContext().getContentResolver().notifyChange(newUri, null);
return newUri;
}
@ -239,14 +247,12 @@ public class DeliveryDbAdapter extends ContentProvider {
}
}
@Override
public boolean onCreate() {
mDbHelper = new DeliveryDbHelper(getContext());
return true;
}
@Override
public Cursor query(Uri uri, String[] projection, String selection,
String[] selectionArgs, String sortOrder) {
@ -262,7 +268,8 @@ public class DeliveryDbAdapter extends ContentProvider {
case ENTRY_ID:
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
qb.setProjectionMap(sDeliveryProjectionMap);
qb.appendWhere(KEY_DELIVERY_ENTRY_ROWID + "=" + uri.getPathSegments().get(1));
qb.appendWhere(KEY_DELIVERY_ENTRY_ROWID + "="
+ uri.getPathSegments().get(1));
break;
case MESSAGES:
@ -273,7 +280,8 @@ public class DeliveryDbAdapter extends ContentProvider {
case MESSAGES_ID:
qb.setTables(DATABASE_MESSAGE_TABLE);
qb.setProjectionMap(sMessageProjectionMap);
qb.appendWhere(KEY_MESSAGE_ROWID + "=" + uri.getPathSegments().get(1));
qb.appendWhere(KEY_MESSAGE_ROWID + "="
+ uri.getPathSegments().get(1));
break;
default:
@ -283,14 +291,15 @@ public class DeliveryDbAdapter extends ContentProvider {
// Run the query
SQLiteDatabase db = mDbHelper.getReadableDatabase();
Cursor c = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
Cursor c = qb.query(db, projection, selection, selectionArgs, null,
null, sortOrder);
// Tell the cursor what uri to watch, so it knows when its source data changes
// Tell the cursor what uri to watch, so it knows when its source data
// changes
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
@ -299,25 +308,31 @@ public class DeliveryDbAdapter extends ContentProvider {
switch (uriMatcher.match(uri)) {
case ENTRIES:
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, selection, selectionArgs);
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, selection,
selectionArgs);
break;
case ENTRY_ID:
{
case ENTRY_ID: {
String id = uri.getPathSegments().get(1);
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, Words._ID + "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, Words._ID
+ "="
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
}
case MESSAGES:
count = db.update(DATABASE_MESSAGE_TABLE, values, selection, selectionArgs);
count = db.update(DATABASE_MESSAGE_TABLE, values, selection,
selectionArgs);
break;
case MESSAGES_ID:
{
case MESSAGES_ID: {
String id = uri.getPathSegments().get(1);
count = db.update(DATABASE_MESSAGE_TABLE, values, Words._ID + "=" + id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
count = db.update(DATABASE_MESSAGE_TABLE, values, Words._ID
+ "="
+ id
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
+ ')' : ""), selectionArgs);
break;
}
@ -330,5 +345,4 @@ public class DeliveryDbAdapter extends ContentProvider {
return count;
}
}

View File

@ -10,7 +10,6 @@ import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Contacts;
import android.provider.ContactsContract.Data;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
@ -33,11 +32,14 @@ public class GroupEditActivity extends ListActivity {
setContentView(R.layout.edit_group_list);
mGroupNameText = (EditText) findViewById(R.id.groupName);
//Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, Phones.NAME);
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
null, Contacts.DISPLAY_NAME);
// Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null,
// null, Phones.NAME);
Cursor c = getContentResolver().query(
Data.CONTENT_URI,
new String[] { Data._ID, Data.MIMETYPE, Phone.NUMBER,
Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME },
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
Contacts.DISPLAY_NAME);
startManagingCursor(c);
String[] mSelected = {};
@ -47,12 +49,14 @@ public class GroupEditActivity extends ListActivity {
Long groupId;
Bundle extras = getIntent().getExtras();
groupId = extras != null ? extras.getLong(SelectGroupActivity.PARAM_GROUP_ID): null;
groupId = extras != null ? extras
.getLong(SelectGroupActivity.PARAM_GROUP_ID) : null;
if (groupId != null) {
Cursor groupNameCursor = mDb.fetchGroup(groupId);
startManagingCursor(groupNameCursor);
String groupName = groupNameCursor.getString(groupNameCursor.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME));
String groupName = groupNameCursor.getString(groupNameCursor
.getColumnIndex(GroupsDbAdapter.KEY_GROUP_NAME));
mGroupNameText.setText(groupName);
Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
startManagingCursor(numbers);
@ -67,10 +71,9 @@ public class GroupEditActivity extends ListActivity {
mGid = groupId;
}
mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c, new String[] {
Contacts.DISPLAY_NAME, Phone.NUMBER
}, new int[] {R.id.name, R.id.phone}, mSelected);
mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c,
new String[] { Contacts.DISPLAY_NAME, Phone.NUMBER },
new int[] { R.id.name, R.id.phone }, mSelected);
setListAdapter(mAdpater);
Button ok = (Button) findViewById(R.id.okGroups);
@ -88,18 +91,18 @@ public class GroupEditActivity extends ListActivity {
}
protected void onStart() {
Log.d("GroupEdit","---onStart");
//Log.d("GroupEdit", "---onStart");
mDb.open();
super.onStart();
}
protected void onResume() {
Log.d("GroupEdit","---onResume");
//Log.d("GroupEdit", "---onResume");
super.onResume();
}
protected void onStop() {
Log.d("GroupEdit","---OnStop");
//Log.d("GroupEdit", "---OnStop");
mDb.close();
super.onStop();
}
@ -149,30 +152,30 @@ public class GroupEditActivity extends ListActivity {
Cursor c = getCursor();
startManagingCursor(c);
c.moveToPosition(position);
// String name = c.getString(nameidx);
String contactNumber = c.getString(numberidx);
long id = c.getLong(idIdx);
View v = super.getView(position, convertView, parent);
LinearLayout background = (LinearLayout)v.findViewById(R.id.row_background);
LinearLayout background = (LinearLayout) v
.findViewById(R.id.row_background);
CheckBox checkbox = (CheckBox) v.findViewById(R.id.CheckBox);
checkbox.setOnClickListener(new addNumberToGroupClickListener(id));
checkbox.setChecked(selected.contains(contactNumber));
background.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
CheckBox checkbox = (CheckBox) v
.findViewById(R.id.CheckBox);
checkbox.performClick();
}
});
return v;
}
}
@ -181,13 +184,11 @@ public class GroupEditActivity extends ListActivity {
Long mId;
public addNumberToGroupClickListener(Long id) {
super();
this.mId = id;
}
public void onClick(View v) {
CheckBox cBox = (CheckBox) v;
createGroup();

View File

@ -1,4 +1,3 @@
package com.hectorone.multismssender;
import android.content.ContentValues;
@ -14,13 +13,12 @@ import android.util.Log;
/**
* Simple groups database access helper class. Defines the basic CRUD operations
* for the group add example, and gives the ability to list all groups as well as
* retrieve or modify a specific group.
* for the group add example, and gives the ability to list all groups as well
* as retrieve or modify a specific group.
*
*/
public class GroupsDbAdapter {
public static final String KEY_GROUP_NAME = "name";
public static final String KEY_GROUP_ROWID = "_id";
@ -35,12 +33,10 @@ public class GroupsDbAdapter {
/**
* Database creation sql statement
*/
private static final String DATABASE_GROUP_CREATE =
"create table groups (_id integer primary key autoincrement, "
private static final String DATABASE_GROUP_CREATE = "create table groups (_id integer primary key autoincrement, "
+ "name text not null);";
private static final String DATABASE_GROUP_TO_PHONE_CREATE =
"create table group_TO_PHONE (_id integer primary key autoincrement, "
private static final String DATABASE_GROUP_TO_PHONE_CREATE = "create table group_TO_PHONE (_id integer primary key autoincrement, "
+ "gid integer not null, pid integer not null);";
private static final String DATABASE_NAME = "dataGroup";
@ -63,7 +59,6 @@ public class GroupsDbAdapter {
db.execSQL(DATABASE_GROUP_TO_PHONE_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
@ -78,7 +73,8 @@ public class GroupsDbAdapter {
* Constructor - takes the context to allow the database to be
* opened/created
*
* @param ctx the Context within which to work
* @param ctx
* the Context within which to work
*/
public GroupsDbAdapter(Context ctx) {
this.mCtx = ctx;
@ -91,7 +87,8 @@ public class GroupsDbAdapter {
*
* @return this (self reference, allowing this to be chained in an
* initialization call)
* @throws SQLException if the database could be neither opened or created
* @throws SQLException
* if the database could be neither opened or created
*/
public GroupsDbAdapter open() throws SQLException {
mDbHelper = new GroupDbHelper(mCtx);
@ -104,13 +101,13 @@ public class GroupsDbAdapter {
mDbHelper.close();
}
/**
* Create a new group using the name provided. If the group is
* successfully created return the new rowId for that group, otherwise return
* a -1 to indicate failure.
* Create a new group using the name provided. If the group is successfully
* created return the new rowId for that group, otherwise return a -1 to
* indicate failure.
*
* @param name the name of the group
* @param name
* the name of the group
*/
public long createGroup(String name) {
ContentValues initialValues = new ContentValues();
@ -122,12 +119,16 @@ public class GroupsDbAdapter {
/**
* Delete the group with the given rowId
*
* @param rowId id of group to delete
* @param rowId
* id of group to delete
* @return true if deleted, false otherwise
*/
public boolean deleteGroup(long rowId) {
return mDb.delete(DATABASE_GROUP_TABLE, KEY_GROUP_ROWID + "=" + rowId, null) > 0 && mDb.delete(DATABASE_GROUP_TO_PHONE_TABLE, KEY_GROUP_TO_PHONE_GROUPID + "=" + rowId, null) > 0;
return mDb.delete(DATABASE_GROUP_TABLE, KEY_GROUP_ROWID + "=" + rowId,
null) > 0
&& mDb.delete(DATABASE_GROUP_TO_PHONE_TABLE,
KEY_GROUP_TO_PHONE_GROUPID + "=" + rowId, null) > 0;
}
@ -138,22 +139,26 @@ public class GroupsDbAdapter {
*/
public Cursor fetchAllGroups() {
return mDb.query(DATABASE_GROUP_TABLE, new String[] {KEY_GROUP_ROWID, KEY_GROUP_NAME}, null, null, null, null, KEY_GROUP_NAME);
return mDb.query(DATABASE_GROUP_TABLE, new String[] { KEY_GROUP_ROWID,
KEY_GROUP_NAME }, null, null, null, null, KEY_GROUP_NAME);
}
/**
* Return a Cursor positioned at the group that matches the given rowId
*
* @param rowId id of group to retrieve
* @param rowId
* id of group to retrieve
* @return Cursor positioned to matching group, if found
* @throws SQLException if group could not be found/retrieved
* @throws SQLException
* if group could not be found/retrieved
*/
public Cursor fetchGroup(long rowId) throws SQLException {
Cursor mCursor =
mDb.query(true, DATABASE_GROUP_TABLE, new String[] {KEY_GROUP_ROWID, KEY_GROUP_NAME}, KEY_GROUP_ROWID + "=" + rowId, null,
null, null, null, null);
mDb.query(true, DATABASE_GROUP_TABLE, new String[] { KEY_GROUP_ROWID,
KEY_GROUP_NAME }, KEY_GROUP_ROWID + "=" + rowId, null, null,
null, null, null);
if (mCursor != null) {
mCursor.moveToFirst();
}
@ -162,32 +167,40 @@ public class GroupsDbAdapter {
}
/**
* @param rowId id of group to update
* @param name value to set group name to
* @param rowId
* id of group to update
* @param name
* value to set group name to
*/
public boolean updateGroup(long rowId, String name) {
ContentValues args = new ContentValues();
args.put(KEY_GROUP_NAME, name);
return mDb.update(DATABASE_GROUP_TABLE, args, KEY_GROUP_ROWID + "=" + rowId, null) > 0;
return mDb.update(DATABASE_GROUP_TABLE, args, KEY_GROUP_ROWID + "="
+ rowId, null) > 0;
}
public Cursor fetchPhonesFromGroup(long groupId) {
Cursor mCursor = mDb.query(true, DATABASE_GROUP_TO_PHONE_TABLE, new String[] {KEY_GROUP_TO_PHONE_PHONEID}, KEY_GROUP_TO_PHONE_GROUPID + "=" + groupId, null, null, null, null, null);
Cursor mCursor = mDb.query(true, DATABASE_GROUP_TO_PHONE_TABLE,
new String[] { KEY_GROUP_TO_PHONE_PHONEID },
KEY_GROUP_TO_PHONE_GROUPID + "=" + groupId, null, null, null,
null, null);
Cursor userCursor = null;
int phoneIdIdx = mCursor.getColumnIndex(KEY_GROUP_TO_PHONE_PHONEID);
if (mCursor != null) {
userCursor = mCtx.getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data._ID +" IN "+ cursorToStringList(mCursor, phoneIdIdx),
userCursor = mCtx.getContentResolver()
.query(Data.CONTENT_URI,
new String[] { Data._ID, Data.MIMETYPE,
Phone.NUMBER, Phone.TYPE, Phone.LABEL,
Contacts.DISPLAY_NAME },
Data._ID + " IN "
+ cursorToStringList(mCursor, phoneIdIdx),
null, Contacts.DISPLAY_NAME);
}
mCursor.close();
return userCursor;
}
public long addPhoneToGroup(long groupId, long phoneId) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_GROUP_TO_PHONE_GROUPID, groupId);
@ -197,7 +210,9 @@ public class GroupsDbAdapter {
}
public boolean removePhoneToGroup(long groupId, long phoneId) {
return mDb.delete(DATABASE_GROUP_TO_PHONE_TABLE, KEY_GROUP_TO_PHONE_GROUPID + "=" + groupId+ " AND "+ KEY_GROUP_TO_PHONE_PHONEID + "=" + phoneId, null) > 0;
return mDb.delete(DATABASE_GROUP_TO_PHONE_TABLE,
KEY_GROUP_TO_PHONE_GROUPID + "=" + groupId + " AND "
+ KEY_GROUP_TO_PHONE_PHONEID + "=" + phoneId, null) > 0;
}
public String cursorToStringList(Cursor cursor, int columnIdx) {

View File

@ -1,6 +1,5 @@
package com.hectorone.multismssender;
import android.app.ListActivity;
import android.content.Context;
import android.database.Cursor;
@ -16,34 +15,38 @@ public class ListEntryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
Long mDeliveryId;
public static final int REFRESH_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entry_list);
Bundle extras = getIntent().getExtras();
mDeliveryId = extras != null ? extras.getLong(SelectDeliveryActivity.PARAM_DELIVERY_ID): null;
mDeliveryId = extras != null ? extras
.getLong(SelectDeliveryActivity.PARAM_DELIVERY_ID) : null;
//mDbHelper = new DeliveryDbAdapter(this);
//mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
public void fillData() {
Cursor deliveryCursor = getContentResolver().query(DeliveryDbAdapter.CONTENT_DELIVERY_URI, null, DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID+" = " + mDeliveryId, null, null);
//Cursor deliveryCursor = mDbHelper.fetchAllEntry(mDeliveryId);
Cursor deliveryCursor = getContentResolver().query(
DeliveryDbAdapter.CONTENT_DELIVERY_URI,
null,
DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID + " = "
+ mDeliveryId, null, null);
startManagingCursor(deliveryCursor);
String[] from = new String[]{DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME, DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER };
String[] from = new String[] {
DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME,
DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER };
int[] to = new int[] { R.id.name, R.id.number };
EntryCursorAdapter notes =
new EntryCursorAdapter(this, R.layout.entry_row, deliveryCursor, from, to);
EntryCursorAdapter notes = new EntryCursorAdapter(this,
R.layout.entry_row, deliveryCursor, from, to);
setListAdapter(notes);
}
@ -52,7 +55,6 @@ public class ListEntryActivity extends ListActivity {
super.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
super.onDestroy();
@ -84,12 +86,10 @@ public class ListEntryActivity extends ListActivity {
super(context, layout, c, from, to);
// TODO this.getCursor()
this.c = c;
deliveredIdx = c.getColumnIndex(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED);
deliveredIdx = c
.getColumnIndex(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
@ -107,6 +107,4 @@ public class ListEntryActivity extends ListActivity {
}
}
}

View File

@ -5,7 +5,6 @@ import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
public class MessageReceiver extends BroadcastReceiver{
public static final String MESSAGE_RECEIVED = "com.hectorone.multismssender.SMS_RECEIVED";
@ -17,7 +16,7 @@ public class MessageReceiver extends BroadcastReceiver{
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
Log.d(DEBUG_TAG, "SMS_RECEIVED");
//Log.d(DEBUG_TAG, "SMS_RECEIVED");
Uri entryURI = intent.getData();
if (entryURI != null){
@ -26,20 +25,6 @@ public class MessageReceiver extends BroadcastReceiver{
context.getContentResolver().update(entryURI, values, null, null);
}
/*String entryStr = entryURI.getLastPathSegment();
entryId = Long.parseLong(entryStr);*/
//byte[] pdu = (byte[]) intent.getByteArrayExtra("pdu");
//SmsMessage message = SmsMessage.createFromPdu(pdu);
//int status = message.getStatus();
/*if(entryId != null) {
DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(context);
mDbHelper.open();
mDbHelper.setEntryDelivered(entryId);
mDbHelper.close();
}*/
}
}

View File

@ -72,56 +72,70 @@ public class MultiSmsSender extends Activity {
final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
int type = msg.getData().getInt("ORIGIN");
switch (type) {
case DIALOG_PROGRESS: {
int total = msg.getData().getInt("total");
//Log.d(DEBUG_TAG, "========= total is "+total);
mSendingDialog.setProgress(total);
}
break;
case DIALOG_PROGRESS_CANCEL: {
mSendingDialog.cancel();
}
break;
case DIALOG_FINISHED: {
//dismissDialog(SENDING_DIALOG_KEY);
int total = msg.getData().getInt("total");
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
new AlertDialog.Builder(MultiSmsSender.this)
.setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
}).setMessage(
total + " "
+ getResources().getString(R.string.message_sent))
.show();
})
.setMessage(
total
+ " "
+ getResources().getString(
R.string.message_sent)).show();
break;
}
case DIALOG_NONUMBER: {
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
new AlertDialog.Builder(MultiSmsSender.this)
.setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog,
int which) {
dialog.dismiss();
}
}).setMessage(
getResources().getString(R.string.enter_number)).show();
})
.setMessage(
getResources().getString(R.string.enter_number))
.show();
break;
}
case DIALOG_MANYMESSAGE: {
new AlertDialog.Builder(MultiSmsSender.this)
.setMessage(getResources().getString(R.string.warning_many_message))
.setMessage(
getResources().getString(
R.string.warning_many_message))
.setCancelable(false)
.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
synchronized (MultiSmsSender.this) {
MultiSmsSender.this.notify();
mManyMessageContinue = true;
@ -129,32 +143,39 @@ public class MultiSmsSender extends Activity {
dialog.dismiss();
}
})
.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
.setNegativeButton(
getResources().getString(R.string.cancel),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
synchronized (MultiSmsSender.this) {
MultiSmsSender.this.notify();
mManyMessageContinue = false;
}
dialog.dismiss();
}
})
.show();
}).show();
break;
}
case DIALOG_STARTWAIT: {
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
new AlertDialog.Builder(MultiSmsSender.this)
.setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog,
int which) {
synchronized (MultiSmsSender.this) {
MultiSmsSender.this.notify();
}
dialog.dismiss();
}
}).setMessage(getResources().getString(R.string.more_message)).show();
})
.setMessage(
getResources().getString(R.string.more_message))
.show();
break;
}
@ -168,7 +189,6 @@ public class MultiSmsSender extends Activity {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mAddButton = (Button) findViewById(R.id.contacts);
mAddGroupButton = (Button) findViewById(R.id.groups);
mSend = (Button) findViewById(R.id.send);
@ -179,7 +199,6 @@ public class MultiSmsSender extends Activity {
mContacts.setImeOptions(EditorInfo.IME_ACTION_NEXT);
// mEditor.setImeOptions(EditorInfo.IME_ACTION_DONE);
mAddButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
@ -193,21 +212,19 @@ public class MultiSmsSender extends Activity {
}
});
mSend.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(SENDING_DIALOG_KEY);
mThreadSender = new MessageSenderThread(mHandler);
mThreadSender.start();
//sendMessage();
}
});
}
public void selectNumbers() {
//startActivityForResult(new Intent(Intent.ACTION_PICK, People.CONTENT_URI), 0);
// startActivityForResult(new Intent(Intent.ACTION_PICK,
// People.CONTENT_URI), 0);
Intent i = new Intent(this, PhoneNumberSelection.class);
String rawNumbers = mContacts.getText().toString();
String[] numbers = rawNumbers.split(",");
@ -215,8 +232,6 @@ public class MultiSmsSender extends Activity {
startActivityForResult(i, ACTIVITY_EDIT);
}
private class MessageSenderThread extends Thread {
Handler mHandler;
@ -224,14 +239,15 @@ public class MultiSmsSender extends Activity {
public MessageSenderThread(Handler h) {
mHandler = h;
}
public synchronized void run() {
super.run();
sendMessage(mHandler);
}
}
public void sendMessage(Handler handler) {
//DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(this);
SmsManager manager = SmsManager.getDefault();
String message = mEditor.getText().toString();
@ -253,23 +269,20 @@ public class MultiSmsSender extends Activity {
ArrayList<String> messages = manager.divideMessage(message);
int messageCount = messages.size();
if (haveDeliveryReports) {
ContentValues values = new ContentValues(2);
values.put(DeliveryDbAdapter.KEY_MESSAGE_NAME, message.substring(0, Math.min(30, message
.length())).replace('\n', ' '));
values.put(DeliveryDbAdapter.KEY_MESSAGE_DATE, DateFormat.getDateInstance().format(new Date()));
messageId = Long.parseLong(getContentResolver().insert(DeliveryDbAdapter.CONTENT_MESSAGE_URI, values).getPathSegments().get(1));
/*
mDbHelper.open();
deliveryId = mDbHelper.createMessage(message.substring(0, Math.min(30, message
.length())).replace('\n', ' '), DateFormat.getDateInstance()
.format(new Date()));
mDbHelper.close();*/
values.put(DeliveryDbAdapter.KEY_MESSAGE_NAME,
message.substring(0, Math.min(30, message.length()))
.replace('\n', ' '));
values.put(DeliveryDbAdapter.KEY_MESSAGE_DATE, DateFormat
.getDateInstance().format(new Date()));
messageId = Long.parseLong(getContentResolver()
.insert(DeliveryDbAdapter.CONTENT_MESSAGE_URI, values)
.getPathSegments().get(1));
}
// Check if numbers are correct and prepare deliveryId
for (int i = 0; i < size; i++) {
String newN = numbers[i].trim();
@ -280,25 +293,23 @@ public class MultiSmsSender extends Activity {
phoneNumberConform.add(newN);
if (haveDeliveryReports) {
ContentValues values = new ContentValues(3);
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME, nameFromNumber(getContentResolver(), newN));
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER, newN);
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID, messageId);
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME,
nameFromNumber(getContentResolver(), newN));
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER,
newN);
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID,
messageId);
long entryId = Long.parseLong(getContentResolver().insert(DeliveryDbAdapter.CONTENT_DELIVERY_URI, values).getPathSegments().get(1));
long entryId = Long.parseLong(getContentResolver()
.insert(DeliveryDbAdapter.CONTENT_DELIVERY_URI,
values).getPathSegments().get(1));
deliveryIdMap.put(newN, entryId);
/*
mDbHelper.open();
long entryId = mDbHelper.createEntry(nameFromNumber(getContentResolver(), newN), newN, messageId);
deliveryIdMap.put(newN,entryId);
mDbHelper.close();*/
}
}
}
}
numbers = new String[size];
numbers = phoneNumberConform.toArray(numbers);
size = phoneNumberConform.size();
@ -316,7 +327,6 @@ public class MultiSmsSender extends Activity {
}
}
}
if (mManyMessageContinue) {
@ -340,7 +350,6 @@ public class MultiSmsSender extends Activity {
for (int i = message_sent; i < chunk_max; i++) {
message_sent++;
String newN = numbers[i];
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", DIALOG_PROGRESS);
@ -369,15 +378,17 @@ public class MultiSmsSender extends Activity {
// "entry is "+entryId+" to number"+newN);
for (int j = 0; j < messageCount; j++) {
if (j == (messageCount - 1)) {
Uri entryURI = Uri.withAppendedPath(
DeliveryDbAdapter.CONTENT_DELIVERY_URI, ""
+ entryId);
Uri entryURI = Uri
.withAppendedPath(
DeliveryDbAdapter.CONTENT_DELIVERY_URI,
"" + entryId);
Intent intent = new Intent(
MessageReceiver.MESSAGE_RECEIVED,
entryURI, this, MessageReceiver.class);
entryURI, this,
MessageReceiver.class);
deliveryIntents.add(PendingIntent.getBroadcast(
this, 0, intent, 0));
deliveryIntents.add(PendingIntent
.getBroadcast(this, 0, intent, 0));
} else {
deliveryIntents.add(null);
}
@ -401,14 +412,14 @@ public class MultiSmsSender extends Activity {
}
displayDialog(handler, DIALOG_PROGRESS_CANCEL, null);
} else {
displayDialog(handler, DIALOG_NONUMBER, null);
}
}
private void displayDialog(Handler handler, int dialogId, HashMap<String, Integer> params) {
private void displayDialog(Handler handler, int dialogId,
HashMap<String, Integer> params) {
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", dialogId);
@ -521,17 +532,17 @@ public class MultiSmsSender extends Activity {
// *********************** HELPER ****************************************
public String nameFromNumber(ContentResolver resolver, String number) {
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
Uri.encode(number));
Cursor c = null;
try {
c = resolver.query(uri, new String[]{PhoneLookup.DISPLAY_NAME},null, null, null);
c = resolver.query(uri, new String[] { PhoneLookup.DISPLAY_NAME },
null, null, null);
} catch (Exception e) {
return "";
}
if (c != null) {
c.moveToFirst();
if (c.isFirst()) {

View File

@ -21,9 +21,7 @@ import android.widget.LinearLayout;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
public class PhoneNumberSelection extends ListActivity
{
public class PhoneNumberSelection extends ListActivity {
PhoneDataListAdapter mAdpater;
HashSet<String> mSelectedSet;
@ -31,19 +29,19 @@ public class PhoneNumberSelection extends ListActivity
private static final int SELECT_ALL_ID = Menu.FIRST + 1;
private static final int DESELECT_ALL_ID = Menu.FIRST + 2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.number_list);
String[] selected;
selected = savedInstanceState != null ? savedInstanceState.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
selected = savedInstanceState != null ? savedInstanceState
.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST) : null;
if (selected == null) {
Bundle extras = getIntent().getExtras();
selected = extras != null ? extras.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
selected = extras != null ? extras
.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST) : null;
}
mSelectedSet = new HashSet<String>();
@ -59,33 +57,33 @@ public class PhoneNumberSelection extends ListActivity
Intent i = new Intent();
String[] numbers = new String[mSelectedSet.size()];
mSelectedSet.toArray(numbers);
Bundle bundle = new Bundle();
bundle.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST, numbers);
Bundle bundle = new Bundle();
bundle.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST,
numbers);
bundle.putBoolean(MultiSmsSender.PARAM_FLUSH, true);
i.putExtras(bundle);
setResult(RESULT_OK, i);
finish();
}
});
}
private void fillData() {
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
null, Contacts.DISPLAY_NAME);
Cursor c = getContentResolver().query(
Data.CONTENT_URI,
new String[] { Data._ID, Data.MIMETYPE, Phone.NUMBER,
Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME },
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
Contacts.DISPLAY_NAME);
startManagingCursor(c);
mAdpater = new PhoneDataListAdapter(this, R.layout.number_row, c, new String[] {
Contacts.DISPLAY_NAME, Phone.NUMBER
}, new int[] {R.id.name, R.id.phone}, mSelectedSet);
mAdpater = new PhoneDataListAdapter(this, R.layout.number_row, c,
new String[] { Contacts.DISPLAY_NAME, Phone.NUMBER },
new int[] { R.id.name, R.id.phone }, mSelectedSet);
setListAdapter(mAdpater);
}
@ -106,13 +104,17 @@ public class PhoneNumberSelection extends ListActivity
return true;
case SELECT_ALL_ID:
/*Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, Phones.NAME);
int numberIdx = c.getColumnIndex(Phones.NUMBER);
/*
* Cursor c = getContentResolver().query(Phones.CONTENT_URI, null,
* null, null, Phones.NAME); int numberIdx =
* c.getColumnIndex(Phones.NUMBER);
*/
Cursor c = getContentResolver().query(Data.CONTENT_URI,
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
null, null);
Cursor c = getContentResolver().query(
Data.CONTENT_URI,
new String[] { Data._ID, Data.MIMETYPE, Phone.NUMBER,
Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME },
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
null);
int numberIdx = c.getColumnIndex(Phone.NUMBER);
startManagingCursor(c);
c.moveToFirst();
@ -130,30 +132,12 @@ public class PhoneNumberSelection extends ListActivity
return super.onMenuItemSelected(featureId, item);
}
public void display_group_list() {
Intent i = new Intent(this, SelectGroupActivity.class);
startActivityForResult(i, MultiSmsSender.ACTIVITY_ADD_GROUP);
}
/*@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
l.getItemAtPosition(position);
}*/
/*@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST, (String[] )mAdpater.selected.toArray());
}
@Override
protected void onPause() {
super.onPause();
}*/
public class PhoneDataListAdapter extends SimpleCursorAdapter {
public PhoneDataListAdapter(Context context, int layout, Cursor c,
@ -161,23 +145,25 @@ public class PhoneNumberSelection extends ListActivity
super(context, layout, c, from, to);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
LinearLayout background = (LinearLayout)v.findViewById(R.id.row_background);
String contactNumber = ((TextView)v.findViewById(R.id.phone)).getText().toString();
LinearLayout background = (LinearLayout) v
.findViewById(R.id.row_background);
String contactNumber = ((TextView) v.findViewById(R.id.phone))
.getText().toString();
CheckBox checkbox = (CheckBox) v.findViewById(R.id.CheckBox);
checkbox.setOnClickListener(new addNumberToSelectedClickListener(contactNumber));
checkbox.setOnClickListener(new addNumberToSelectedClickListener(
contactNumber));
checkbox.setChecked(mSelectedSet.contains(contactNumber));
background.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
CheckBox checkbox = (CheckBox) v
.findViewById(R.id.CheckBox);
checkbox.performClick();
}
@ -207,10 +193,12 @@ public class PhoneNumberSelection extends ListActivity
}
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (intent != null) {
String [] numbers = intent.getExtras().getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST);
String[] numbers = intent.getExtras().getStringArray(
MultiSmsSender.PARAM_NUMBERS_LIST);
for (int i = 0; i < numbers.length; i++) {
mSelectedSet.add(numbers[i]);

View File

@ -1,6 +1,5 @@
package com.hectorone.multismssender;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
@ -16,7 +15,6 @@ import android.widget.SimpleCursorAdapter;
public class SelectDeliveryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
public static final int DELETE_ID = Menu.FIRST;
public static final int DELETE_ALL_ID = Menu.FIRST + 1;
@ -24,7 +22,6 @@ public class SelectDeliveryActivity extends ListActivity {
public static final String PARAM_DELIVERY_ID = "param_delivery_id";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -33,26 +30,26 @@ public class SelectDeliveryActivity extends ListActivity {
registerForContextMenu(getListView());
}
protected void onDestroy() {
super.onDestroy();
}
public void fillData() {
Cursor deliveryCursor = getContentResolver().query(DeliveryDbAdapter.CONTENT_MESSAGE_URI, null, null, null, null);
Cursor deliveryCursor = getContentResolver().query(
DeliveryDbAdapter.CONTENT_MESSAGE_URI, null, null, null, null);
startManagingCursor(deliveryCursor);
String[] from = new String[]{DeliveryDbAdapter.KEY_MESSAGE_DATE, DeliveryDbAdapter.KEY_MESSAGE_NAME };
String[] from = new String[] { DeliveryDbAdapter.KEY_MESSAGE_DATE,
DeliveryDbAdapter.KEY_MESSAGE_NAME };
int[] to = new int[] { R.id.date, R.id.name };
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.delivery_row, deliveryCursor, from, to);
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.delivery_row, deliveryCursor, from, to);
setListAdapter(notes);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
@ -68,13 +65,14 @@ public class SelectDeliveryActivity extends ListActivity {
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI, DeliveryDbAdapter.KEY_MESSAGE_ROWID+ "="+ info.id, null);
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
DeliveryDbAdapter.KEY_MESSAGE_ROWID + "=" + info.id, null);
fillData();
return true;
}
@ -85,7 +83,8 @@ public class SelectDeliveryActivity extends ListActivity {
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case DELETE_ALL_ID:
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI, null, null);
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
null, null);
fillData();
return true;
}

View File

@ -1,14 +1,10 @@
package com.hectorone.multismssender;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
@ -18,7 +14,6 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class SelectGroupActivity extends ListActivity {
GroupsDbAdapter mDbHelper;
@ -32,7 +27,7 @@ public class SelectGroupActivity extends ListActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
Log.d("SelectGroup", "***Create");
//Log.d("SelectGroup", "***Create");
super.onCreate(savedInstanceState);
setContentView(R.layout.group_list);
mDbHelper = new GroupsDbAdapter(this);
@ -42,18 +37,17 @@ public class SelectGroupActivity extends ListActivity{
}
protected void onStart() {
Log.d("SelectGroup", "***onStart");
//Log.d("SelectGroup", "***onStart");
mDbHelper.open();
super.onStart();
}
protected void onStop() {
Log.d("SelectGroup", "***onStop");
//Log.d("SelectGroup", "***onStop");
mDbHelper.close();
super.onStop();
}
public void fillData() {
Cursor groupsCursor = mDbHelper.fetchAllGroups();
startManagingCursor(groupsCursor);
@ -62,8 +56,8 @@ public class SelectGroupActivity extends ListActivity{
int[] to = new int[] { R.id.groupNameTextView };
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.group_row, groupsCursor, from, to);
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
R.layout.group_row, groupsCursor, from, to);
setListAdapter(notes);
}
@ -109,12 +103,14 @@ public class SelectGroupActivity extends ListActivity{
public boolean onContextItemSelected(MenuItem item) {
switch (item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
.getMenuInfo();
mDbHelper.deleteGroup(info.id);
fillData();
return true;
case EDIT_ID:
AdapterContextMenuInfo infoEdit = (AdapterContextMenuInfo) item.getMenuInfo();
AdapterContextMenuInfo infoEdit = (AdapterContextMenuInfo) item
.getMenuInfo();
editGroup(infoEdit.id);
return true;
}