Code cleaning and reformating
This commit is contained in:
parent
95bb2d1651
commit
f516231b9c
@ -17,83 +17,84 @@ import android.provider.UserDictionary.Words;
|
||||
import android.text.TextUtils;
|
||||
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 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");
|
||||
|
||||
private static final int ENTRIES = 1;
|
||||
private static final int ENTRY_ID = 2;
|
||||
private static final int MESSAGES = 3;
|
||||
private static final int MESSAGES_ID = 4;
|
||||
private static final int MESSAGES_ID = 4;
|
||||
|
||||
private static final UriMatcher uriMatcher;
|
||||
static{
|
||||
static {
|
||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "delivery" , ENTRIES);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "delivery", ENTRIES);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "delivery/#", ENTRY_ID);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "message" , MESSAGES);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "message/#" , MESSAGES_ID);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "message", MESSAGES);
|
||||
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";
|
||||
|
||||
public static final String KEY_MESSAGE_ROWID = "_id";
|
||||
public static final String KEY_MESSAGE_NAME = "name";
|
||||
public static final String KEY_MESSAGE_DATE = "date";
|
||||
|
||||
private static final String TAG = "deliveryDbAdapter";
|
||||
private static final String TAG = "deliveryDbAdapter";
|
||||
private DeliveryDbHelper mDbHelper;
|
||||
//private SQLiteDatabase mDb;
|
||||
// private SQLiteDatabase mDb;
|
||||
|
||||
/**
|
||||
* Database creation sql statement
|
||||
*/
|
||||
|
||||
public static final String DATABASE_NAME = "delivery";
|
||||
public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
|
||||
public static final String DATABASE_MESSAGE_TABLE = "message";
|
||||
public static final String DATABASE_NAME = "delivery";
|
||||
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,"
|
||||
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
|
||||
+ KEY_DELIVERY_ENTRY_MESSAGE_ID + " integer);";
|
||||
+ 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);";
|
||||
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);";
|
||||
|
||||
public static final int DATABASE_VERSION = 4;
|
||||
|
||||
public static final int DATABASE_VERSION = 4;
|
||||
|
||||
private static HashMap<String, String> sDeliveryProjectionMap;
|
||||
private static HashMap<String, String> sMessageProjectionMap;
|
||||
|
||||
|
||||
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);
|
||||
|
||||
sMessageProjectionMap.put(KEY_MESSAGE_ROWID , KEY_MESSAGE_ROWID);
|
||||
sMessageProjectionMap.put(KEY_MESSAGE_NAME , KEY_MESSAGE_NAME);
|
||||
sMessageProjectionMap.put(KEY_MESSAGE_DATE , KEY_MESSAGE_DATE);
|
||||
}
|
||||
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);
|
||||
|
||||
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 {
|
||||
|
||||
@ -119,113 +120,120 @@ public class DeliveryDbAdapter extends ContentProvider {
|
||||
}
|
||||
}
|
||||
|
||||
// *********************** Content Provider ****************************************
|
||||
|
||||
|
||||
// *********************** Content Provider ****************************************
|
||||
|
||||
@Override
|
||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
int count;
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
int count;
|
||||
|
||||
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;
|
||||
}
|
||||
case MESSAGES:
|
||||
count = db.delete(DATABASE_MESSAGE_TABLE, selection, selectionArgs);
|
||||
|
||||
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;
|
||||
}
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
}
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getType(Uri uri) {
|
||||
switch (uriMatcher.match(uri)){
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ENTRIES:
|
||||
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".entry";
|
||||
case ENTRY_ID:
|
||||
return "vnd.android.cursor.item/vnd."+ PROVIDER_NAME + ".entry";
|
||||
case ENTRY_ID:
|
||||
return "vnd.android.cursor.item/vnd." + PROVIDER_NAME + ".entry";
|
||||
case MESSAGES:
|
||||
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".message";
|
||||
case MESSAGES_ID:
|
||||
return "vnd.android.cursor.item/vnd."+ PROVIDER_NAME + ".message";
|
||||
case MESSAGES_ID:
|
||||
return "vnd.android.cursor.item/vnd." + PROVIDER_NAME + ".message";
|
||||
default:
|
||||
throw new IllegalArgumentException("Unsupported URI: " + uri);
|
||||
}
|
||||
throw new IllegalArgumentException("Unsupported URI: " + uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Uri insert(Uri uri, ContentValues values) {
|
||||
ContentValues initialValues;
|
||||
if (values != null) {
|
||||
if (values != null) {
|
||||
initialValues = new ContentValues(values);
|
||||
} else {
|
||||
initialValues = new ContentValues();
|
||||
}
|
||||
}
|
||||
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ENTRIES:{
|
||||
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NAME) == false) {
|
||||
throw new SQLException(KEY_DELIVERY_ENTRY_NAME+ " must be specified");
|
||||
case ENTRIES: {
|
||||
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NAME) == false) {
|
||||
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");
|
||||
}
|
||||
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_MESSAGE_ID) == false) {
|
||||
throw new SQLException(KEY_DELIVERY_ENTRY_MESSAGE_ID
|
||||
+ " must be specified");
|
||||
}
|
||||
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NUMBER) == false) {
|
||||
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");
|
||||
}
|
||||
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;
|
||||
}
|
||||
throw new SQLException("Failed to insert row into " + uri);
|
||||
|
||||
|
||||
}
|
||||
|
||||
case MESSAGES:
|
||||
{
|
||||
if (initialValues.containsKey(KEY_MESSAGE_NAME) == false) {
|
||||
throw new SQLException(KEY_MESSAGE_NAME+ " must be specified");
|
||||
|
||||
case MESSAGES: {
|
||||
if (initialValues.containsKey(KEY_MESSAGE_NAME) == false) {
|
||||
throw new SQLException(KEY_MESSAGE_NAME + " must be specified");
|
||||
}
|
||||
if (initialValues.containsKey(KEY_MESSAGE_DATE) == false) {
|
||||
throw new SQLException(KEY_MESSAGE_DATE + " must be specified");
|
||||
}
|
||||
if (initialValues.containsKey(KEY_MESSAGE_DATE) == false) {
|
||||
throw new SQLException(KEY_MESSAGE_DATE+ " must be specified");
|
||||
}
|
||||
|
||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||
long rowId = db.insert(DATABASE_MESSAGE_TABLE,null, initialValues);
|
||||
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;
|
||||
}
|
||||
@ -234,63 +242,64 @@ public class DeliveryDbAdapter extends ContentProvider {
|
||||
}
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
mDbHelper = new DeliveryDbHelper(getContext());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String selection,
|
||||
String[] selectionArgs, String sortOrder) {
|
||||
|
||||
|
||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||
|
||||
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case ENTRIES:
|
||||
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
|
||||
qb.setProjectionMap(sDeliveryProjectionMap);
|
||||
|
||||
|
||||
break;
|
||||
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:
|
||||
qb.setTables(DATABASE_MESSAGE_TABLE);
|
||||
qb.setProjectionMap(sMessageProjectionMap);
|
||||
|
||||
|
||||
break;
|
||||
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:
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
}
|
||||
|
||||
//Run the query
|
||||
|
||||
// Run the query
|
||||
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
||||
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
|
||||
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
|
||||
c.setNotificationUri(getContext().getContentResolver(), uri);
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int update(Uri uri, ContentValues values, String selection,
|
||||
String[] selectionArgs) {
|
||||
@ -299,36 +308,41 @@ 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;
|
||||
}
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||
|
||||
}
|
||||
getContext().getContentResolver().notifyChange(uri, null);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -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,44 +32,48 @@ 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 = {};
|
||||
|
||||
|
||||
mDb = new GroupsDbAdapter(this);
|
||||
mDb.open();
|
||||
|
||||
|
||||
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);
|
||||
numbers.moveToFirst();
|
||||
int phoneNumIdx = numbers.getColumnIndex(Phone.NUMBER);
|
||||
mSelected = new String[numbers.getCount()];
|
||||
for(int i = 0; i < numbers.getCount(); i++) {
|
||||
for (int i = 0; i < numbers.getCount(); i++) {
|
||||
mSelected[i] = numbers.getString(phoneNumIdx);
|
||||
numbers.moveToNext();
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
@ -86,45 +89,45 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
private void createGroup() {
|
||||
if (mGid == null) {
|
||||
if (mGid == null) {
|
||||
String name = mGroupNameText.getText().toString();
|
||||
if(name.equals("")) {
|
||||
if (name.equals("")) {
|
||||
name = getResources().getString(R.string.noName);
|
||||
}
|
||||
mGid = mDb.createGroup(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void reNameGroup() {
|
||||
if (mGid != null) {
|
||||
if (mGid != null) {
|
||||
String name = mGroupNameText.getText().toString();
|
||||
if(name.equals("")) {
|
||||
if (name.equals("")) {
|
||||
name = getResources().getString(R.string.noName);
|
||||
}
|
||||
mDb.updateGroup(mGid, name);
|
||||
}
|
||||
}
|
||||
|
||||
public class GroupDataListAdapter extends SimpleCursorAdapter{
|
||||
public class GroupDataListAdapter extends SimpleCursorAdapter {
|
||||
|
||||
public HashSet<String> selected;
|
||||
int nameidx;
|
||||
@ -135,11 +138,11 @@ public class GroupEditActivity extends ListActivity {
|
||||
public GroupDataListAdapter(Context context, int layout, Cursor c,
|
||||
String[] from, int[] to, String[] rawSelected) {
|
||||
super(context, layout, c, from, to);
|
||||
nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
|
||||
nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
|
||||
numberidx = c.getColumnIndex(Phone.NUMBER);
|
||||
idIdx = c.getColumnIndex(Data._ID);
|
||||
mContext = context;
|
||||
selected = new HashSet<String>();
|
||||
idIdx = c.getColumnIndex(Data._ID);
|
||||
mContext = context;
|
||||
selected = new HashSet<String>();
|
||||
for (int i = 0; i < rawSelected.length; i++) {
|
||||
selected.add(rawSelected[i].trim());
|
||||
}
|
||||
@ -149,56 +152,54 @@ 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);
|
||||
|
||||
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
|
||||
|
||||
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);
|
||||
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class addNumberToGroupClickListener implements OnClickListener{
|
||||
|
||||
private class addNumberToGroupClickListener implements OnClickListener {
|
||||
|
||||
Long mId;
|
||||
|
||||
|
||||
|
||||
public addNumberToGroupClickListener(Long id) {
|
||||
super();
|
||||
this.mId = id;
|
||||
}
|
||||
|
||||
|
||||
public void onClick(View v) {
|
||||
CheckBox cBox = (CheckBox)v;
|
||||
CheckBox cBox = (CheckBox) v;
|
||||
createGroup();
|
||||
if(cBox.isChecked()) {
|
||||
if (cBox.isChecked()) {
|
||||
mDb.addPhoneToGroup(mGid, mId);
|
||||
}else {
|
||||
} else {
|
||||
mDb.removePhoneToGroup(mGid, mId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
|
||||
package com.hectorone.multismssender;
|
||||
|
||||
import android.content.ContentValues;
|
||||
@ -14,203 +13,219 @@ 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";
|
||||
|
||||
public static final String KEY_GROUP_NAME = "name";
|
||||
public static final String KEY_GROUP_ROWID = "_id";
|
||||
public static final String KEY_GROUP_TO_PHONE_ROWID = "_id";
|
||||
public static final String KEY_GROUP_TO_PHONE_GROUPID = "gid";
|
||||
public static final String KEY_GROUP_TO_PHONE_PHONEID = "pid";
|
||||
|
||||
public static final String KEY_GROUP_TO_PHONE_ROWID = "_id";
|
||||
public static final String KEY_GROUP_TO_PHONE_GROUPID = "gid";
|
||||
public static final String KEY_GROUP_TO_PHONE_PHONEID = "pid";
|
||||
|
||||
private static final String TAG = "groupsDbAdapter";
|
||||
private GroupDbHelper mDbHelper;
|
||||
private SQLiteDatabase mDb;
|
||||
|
||||
/**
|
||||
* Database creation sql statement
|
||||
*/
|
||||
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, "
|
||||
+ "gid integer not null, pid integer not null);";
|
||||
private static final String TAG = "groupsDbAdapter";
|
||||
private GroupDbHelper mDbHelper;
|
||||
private SQLiteDatabase mDb;
|
||||
|
||||
private static final String DATABASE_NAME = "dataGroup";
|
||||
private static final String DATABASE_GROUP_TABLE = "groups";
|
||||
private static final String DATABASE_GROUP_TO_PHONE_TABLE = "group_TO_PHONE";
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
/**
|
||||
* Database creation sql statement
|
||||
*/
|
||||
private static final String DATABASE_GROUP_CREATE = "create table groups (_id integer primary key autoincrement, "
|
||||
+ "name text not null);";
|
||||
|
||||
private final Context mCtx;
|
||||
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 class GroupDbHelper extends SQLiteOpenHelper {
|
||||
private static final String DATABASE_NAME = "dataGroup";
|
||||
private static final String DATABASE_GROUP_TABLE = "groups";
|
||||
private static final String DATABASE_GROUP_TO_PHONE_TABLE = "group_TO_PHONE";
|
||||
private static final int DATABASE_VERSION = 4;
|
||||
|
||||
GroupDbHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
private final Context mCtx;
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
db.execSQL(DATABASE_GROUP_CREATE);
|
||||
db.execSQL(DATABASE_GROUP_TO_PHONE_CREATE);
|
||||
}
|
||||
private static class GroupDbHelper extends SQLiteOpenHelper {
|
||||
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
db.execSQL("DROP TABLE IF EXISTS groups");
|
||||
db.execSQL("DROP TABLE IF EXISTS group_TO_PHONE");
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
GroupDbHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor - takes the context to allow the database to be
|
||||
* opened/created
|
||||
*
|
||||
* @param ctx the Context within which to work
|
||||
*/
|
||||
public GroupsDbAdapter(Context ctx) {
|
||||
this.mCtx = ctx;
|
||||
}
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
|
||||
/**
|
||||
* Open the groups database. If it cannot be opened, try to create a new
|
||||
* instance of the database. If it cannot be created, throw an exception to
|
||||
* signal the failure
|
||||
*
|
||||
* @return this (self reference, allowing this to be chained in an
|
||||
* initialization call)
|
||||
* @throws SQLException if the database could be neither opened or created
|
||||
*/
|
||||
public GroupsDbAdapter open() throws SQLException {
|
||||
mDbHelper = new GroupDbHelper(mCtx);
|
||||
mDb = mDbHelper.getWritableDatabase();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void close() {
|
||||
mDbHelper.close();
|
||||
}
|
||||
db.execSQL(DATABASE_GROUP_CREATE);
|
||||
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 "
|
||||
+ newVersion + ", which will destroy all old data");
|
||||
db.execSQL("DROP TABLE IF EXISTS groups");
|
||||
db.execSQL("DROP TABLE IF EXISTS group_TO_PHONE");
|
||||
onCreate(db);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public long createGroup(String name) {
|
||||
ContentValues initialValues = new ContentValues();
|
||||
initialValues.put(KEY_GROUP_NAME, name);
|
||||
/**
|
||||
* Constructor - takes the context to allow the database to be
|
||||
* opened/created
|
||||
*
|
||||
* @param ctx
|
||||
* the Context within which to work
|
||||
*/
|
||||
public GroupsDbAdapter(Context ctx) {
|
||||
this.mCtx = ctx;
|
||||
}
|
||||
|
||||
return mDb.insert(DATABASE_GROUP_TABLE, null, initialValues);
|
||||
}
|
||||
/**
|
||||
* Open the groups database. If it cannot be opened, try to create a new
|
||||
* instance of the database. If it cannot be created, throw an exception to
|
||||
* signal the failure
|
||||
*
|
||||
* @return this (self reference, allowing this to be chained in an
|
||||
* initialization call)
|
||||
* @throws SQLException
|
||||
* if the database could be neither opened or created
|
||||
*/
|
||||
public GroupsDbAdapter open() throws SQLException {
|
||||
mDbHelper = new GroupDbHelper(mCtx);
|
||||
mDb = mDbHelper.getWritableDatabase();
|
||||
|
||||
/**
|
||||
* Delete the group with the given rowId
|
||||
*
|
||||
* @param rowId id of group to delete
|
||||
* @return true if deleted, false otherwise
|
||||
*/
|
||||
public boolean deleteGroup(long rowId) {
|
||||
return this;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
}
|
||||
public void close() {
|
||||
mDbHelper.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cursor over the list of all groups in the database
|
||||
*
|
||||
* @return Cursor over all groups
|
||||
*/
|
||||
public Cursor fetchAllGroups() {
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public long createGroup(String name) {
|
||||
ContentValues initialValues = new ContentValues();
|
||||
initialValues.put(KEY_GROUP_NAME, name);
|
||||
|
||||
return mDb.query(DATABASE_GROUP_TABLE, new String[] {KEY_GROUP_ROWID, KEY_GROUP_NAME}, null, null, null, null, KEY_GROUP_NAME);
|
||||
}
|
||||
return mDb.insert(DATABASE_GROUP_TABLE, null, initialValues);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Cursor positioned at the group that matches the given rowId
|
||||
*
|
||||
* @param rowId id of group to retrieve
|
||||
* @return Cursor positioned to matching group, if found
|
||||
* @throws SQLException if group could not be found/retrieved
|
||||
*/
|
||||
public Cursor fetchGroup(long rowId) throws SQLException {
|
||||
/**
|
||||
* Delete the group with the given rowId
|
||||
*
|
||||
* @param rowId
|
||||
* id of group to delete
|
||||
* @return true if deleted, false otherwise
|
||||
*/
|
||||
public boolean deleteGroup(long rowId) {
|
||||
|
||||
Cursor mCursor =
|
||||
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;
|
||||
|
||||
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();
|
||||
}
|
||||
return mCursor;
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Return a Cursor over the list of all groups in the database
|
||||
*
|
||||
* @return Cursor over all groups
|
||||
*/
|
||||
public Cursor fetchAllGroups() {
|
||||
|
||||
/**
|
||||
* @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.query(DATABASE_GROUP_TABLE, new String[] { KEY_GROUP_ROWID,
|
||||
KEY_GROUP_NAME }, null, null, null, null, KEY_GROUP_NAME);
|
||||
}
|
||||
|
||||
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 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),
|
||||
null, Contacts.DISPLAY_NAME);
|
||||
}
|
||||
mCursor.close();
|
||||
return userCursor;
|
||||
}
|
||||
/**
|
||||
* Return a Cursor positioned at the group that matches the given rowId
|
||||
*
|
||||
* @param rowId
|
||||
* id of group to retrieve
|
||||
* @return Cursor positioned to matching group, if found
|
||||
* @throws SQLException
|
||||
* if group could not be found/retrieved
|
||||
*/
|
||||
public Cursor fetchGroup(long rowId) throws SQLException {
|
||||
|
||||
|
||||
public long addPhoneToGroup(long groupId, long phoneId ) {
|
||||
ContentValues initialValues = new ContentValues();
|
||||
initialValues.put(KEY_GROUP_TO_PHONE_GROUPID, groupId);
|
||||
initialValues.put(KEY_GROUP_TO_PHONE_PHONEID, phoneId);
|
||||
Cursor mCursor =
|
||||
|
||||
return mDb.insert(DATABASE_GROUP_TO_PHONE_TABLE, null, initialValues);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String cursorToStringList(Cursor cursor, int columnIdx) {
|
||||
cursor.moveToFirst();
|
||||
String list = "( ";
|
||||
while(!cursor.isAfterLast()) {
|
||||
list += cursor.getString(columnIdx);
|
||||
if(!cursor.isLast()) {
|
||||
list += " , ";
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
list +=" )";
|
||||
return list;
|
||||
}
|
||||
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();
|
||||
}
|
||||
return mCursor;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
|
||||
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 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),
|
||||
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);
|
||||
initialValues.put(KEY_GROUP_TO_PHONE_PHONEID, phoneId);
|
||||
|
||||
return mDb.insert(DATABASE_GROUP_TO_PHONE_TABLE, null, initialValues);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public String cursorToStringList(Cursor cursor, int columnIdx) {
|
||||
cursor.moveToFirst();
|
||||
String list = "( ";
|
||||
while (!cursor.isAfterLast()) {
|
||||
list += cursor.getString(columnIdx);
|
||||
if (!cursor.isLast()) {
|
||||
list += " , ";
|
||||
}
|
||||
cursor.moveToNext();
|
||||
}
|
||||
list += " )";
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.hectorone.multismssender;
|
||||
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
@ -16,97 +15,96 @@ 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;
|
||||
|
||||
//mDbHelper = new DeliveryDbAdapter(this);
|
||||
//mDbHelper.open();
|
||||
mDeliveryId = extras != null ? extras
|
||||
.getLong(SelectDeliveryActivity.PARAM_DELIVERY_ID) : null;
|
||||
|
||||
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};
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
super.onCreateOptionsMenu(menu);
|
||||
menu.add(0, REFRESH_ID,0, R.string.refresh);
|
||||
menu.add(0, REFRESH_ID, 0, R.string.refresh);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
switch(item.getItemId()) {
|
||||
switch (item.getItemId()) {
|
||||
case REFRESH_ID:
|
||||
fillData();
|
||||
return true;
|
||||
}
|
||||
return super.onContextItemSelected(item);
|
||||
}
|
||||
|
||||
private class EntryCursorAdapter extends SimpleCursorAdapter{
|
||||
|
||||
private class EntryCursorAdapter extends SimpleCursorAdapter {
|
||||
Cursor c;
|
||||
int deliveredIdx;
|
||||
|
||||
public EntryCursorAdapter(Context context, int layout, Cursor c,
|
||||
String[] from, int[] to) {
|
||||
super(context, layout, c, from, to);
|
||||
//TODO this.getCursor()
|
||||
// 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);
|
||||
ImageView image = (ImageView)v.findViewById(R.id.delivered);
|
||||
|
||||
ImageView image = (ImageView) v.findViewById(R.id.delivered);
|
||||
|
||||
c.moveToPosition(position);
|
||||
int delivered = c.getInt(deliveredIdx);
|
||||
if(delivered != 0) {
|
||||
if (delivered != 0) {
|
||||
image.setImageResource(R.drawable.btn_check_buttonless_on);
|
||||
}else {
|
||||
} else {
|
||||
image.setImageResource(R.drawable.btn_check_buttonless_off);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,19 +5,18 @@ 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";
|
||||
public static final String MESSAGE_RECEIVED = "com.hectorone.multismssender.SMS_RECEIVED";
|
||||
public static final String ANDROID_MESSAGE_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
|
||||
public static final String DEBUG_TAG="-------MessageReceiver--------";
|
||||
public static final String DEBUG_TAG = "-------MessageReceiver--------";
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
|
||||
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();
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -42,21 +42,21 @@ public class MultiSmsSender extends Activity {
|
||||
|
||||
private ProgressDialog mSendingDialog;
|
||||
|
||||
public static final int ACTIVITY_EDIT = 0;
|
||||
public static final int ACTIVITY_EDIT = 0;
|
||||
public static final int ACTIVITY_ADD_GROUP = 1;
|
||||
public static final int ACTIVITY_DELIVERY = 2;
|
||||
public static final int ACTIVITY_DELIVERY = 2;
|
||||
|
||||
private static final int INSERT_ID = Menu.FIRST;
|
||||
private static final int INSERT_ID = Menu.FIRST;
|
||||
|
||||
public static final int MANY_MESSAGE = 50;
|
||||
public static final int MANY_MESSAGE = 50;
|
||||
|
||||
private static final int DIALOG_PROGRESS = 0;
|
||||
private static final int DIALOG_FINISHED = 1;
|
||||
private static final int DIALOG_NONUMBER = 2;
|
||||
private static final int DIALOG_MANYMESSAGE = 3;
|
||||
private static final int DIALOG_STARTWAIT = 4;
|
||||