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.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
public class DeliveryDbAdapter extends ContentProvider {
|
public class DeliveryDbAdapter extends ContentProvider {
|
||||||
|
|
||||||
|
public static final String PROVIDER_NAME = "com.hectorone.multismssender.provider";
|
||||||
public static final String PROVIDER_NAME ="com.hectorone.multismssender.provider";
|
public static final Uri CONTENT_DELIVERY_URI = Uri.parse("content://"
|
||||||
public static final Uri CONTENT_DELIVERY_URI = Uri.parse("content://" + PROVIDER_NAME + "/delivery");
|
+ PROVIDER_NAME + "/delivery");
|
||||||
public static final Uri CONTENT_MESSAGE_URI = Uri.parse("content://" + PROVIDER_NAME + "/message");
|
public static final Uri CONTENT_MESSAGE_URI = Uri.parse("content://"
|
||||||
|
+ PROVIDER_NAME + "/message");
|
||||||
|
|
||||||
private static final int ENTRIES = 1;
|
private static final int ENTRIES = 1;
|
||||||
private static final int ENTRY_ID = 2;
|
private static final int ENTRY_ID = 2;
|
||||||
private static final int MESSAGES = 3;
|
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;
|
private static final UriMatcher uriMatcher;
|
||||||
static{
|
static {
|
||||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
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, "delivery/#", ENTRY_ID);
|
||||||
uriMatcher.addURI(PROVIDER_NAME, "message" , MESSAGES);
|
uriMatcher.addURI(PROVIDER_NAME, "message", MESSAGES);
|
||||||
uriMatcher.addURI(PROVIDER_NAME, "message/#" , MESSAGES_ID);
|
uriMatcher.addURI(PROVIDER_NAME, "message/#", MESSAGES_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final String KEY_DELIVERY_ENTRY_ROWID = "_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_NAME = "name";
|
||||||
public static final String KEY_DELIVERY_ENTRY_NUMBER = "number";
|
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_DELIVERED = "delivered";
|
||||||
public static final String KEY_DELIVERY_ENTRY_MESSAGE_ID = "message_id";
|
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";
|
private static final String TAG = "deliveryDbAdapter";
|
||||||
public static final String KEY_MESSAGE_NAME = "name";
|
|
||||||
public static final String KEY_MESSAGE_DATE = "date";
|
|
||||||
|
|
||||||
private static final String TAG = "deliveryDbAdapter";
|
|
||||||
private DeliveryDbHelper mDbHelper;
|
private DeliveryDbHelper mDbHelper;
|
||||||
//private SQLiteDatabase mDb;
|
// private SQLiteDatabase mDb;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database creation sql statement
|
* Database creation sql statement
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "delivery";
|
public static final String DATABASE_NAME = "delivery";
|
||||||
public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
|
public static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
|
||||||
public static final String DATABASE_MESSAGE_TABLE = "message";
|
public static final String DATABASE_MESSAGE_TABLE = "message";
|
||||||
public static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table "
|
public static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table "
|
||||||
+ DATABASE_DELIVERY_ENTRY_TABLE
|
+ DATABASE_DELIVERY_ENTRY_TABLE + " (" + KEY_DELIVERY_ENTRY_ROWID
|
||||||
+ " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, "
|
+ " integer primary key autoincrement, " + KEY_DELIVERY_ENTRY_NAME
|
||||||
+ KEY_DELIVERY_ENTRY_NAME + " text not null,"
|
+ " text not null," + KEY_DELIVERY_ENTRY_NUMBER + " text not null,"
|
||||||
+ KEY_DELIVERY_ENTRY_NUMBER + " text not null,"
|
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
|
||||||
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
|
+ KEY_DELIVERY_ENTRY_MESSAGE_ID + " integer);";
|
||||||
+ KEY_DELIVERY_ENTRY_MESSAGE_ID + " integer);";
|
|
||||||
|
|
||||||
public static final String DATABASE_DELIVERY_CREATE = "create table "
|
public static final String DATABASE_DELIVERY_CREATE = "create table "
|
||||||
+ DATABASE_MESSAGE_TABLE
|
+ DATABASE_MESSAGE_TABLE + " (" + KEY_MESSAGE_ROWID
|
||||||
+ " (" + KEY_MESSAGE_ROWID + " integer primary key autoincrement, "
|
+ " integer primary key autoincrement, " + KEY_MESSAGE_NAME
|
||||||
+ KEY_MESSAGE_NAME + " text not null,"
|
+ " text not null," + KEY_MESSAGE_DATE + " 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> sDeliveryProjectionMap;
|
||||||
private static HashMap<String, String> sMessageProjectionMap;
|
private static HashMap<String, String> sMessageProjectionMap;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
sDeliveryProjectionMap = new HashMap<String, String>();
|
sDeliveryProjectionMap = new HashMap<String, String>();
|
||||||
sMessageProjectionMap = new HashMap<String, String>();
|
sMessageProjectionMap = new HashMap<String, String>();
|
||||||
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_ROWID , KEY_DELIVERY_ENTRY_ROWID);
|
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_ROWID,
|
||||||
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NAME , KEY_DELIVERY_ENTRY_NAME);
|
KEY_DELIVERY_ENTRY_ROWID);
|
||||||
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NUMBER , KEY_DELIVERY_ENTRY_NUMBER);
|
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NAME,
|
||||||
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_DELIVERED , KEY_DELIVERY_ENTRY_DELIVERED);
|
KEY_DELIVERY_ENTRY_NAME);
|
||||||
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_MESSAGE_ID, KEY_DELIVERY_ENTRY_MESSAGE_ID);
|
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_NUMBER,
|
||||||
|
KEY_DELIVERY_ENTRY_NUMBER);
|
||||||
sMessageProjectionMap.put(KEY_MESSAGE_ROWID , KEY_MESSAGE_ROWID);
|
sDeliveryProjectionMap.put(KEY_DELIVERY_ENTRY_DELIVERED,
|
||||||
sMessageProjectionMap.put(KEY_MESSAGE_NAME , KEY_MESSAGE_NAME);
|
KEY_DELIVERY_ENTRY_DELIVERED);
|
||||||
sMessageProjectionMap.put(KEY_MESSAGE_DATE , KEY_MESSAGE_DATE);
|
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 {
|
private static class DeliveryDbHelper extends SQLiteOpenHelper {
|
||||||
|
|
||||||
@ -119,113 +120,120 @@ public class DeliveryDbAdapter extends ContentProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// *********************** Content Provider ****************************************
|
||||||
|
|
||||||
|
|
||||||
// *********************** Content Provider ****************************************
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
public int delete(Uri uri, String selection, String[] selectionArgs) {
|
||||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
switch (uriMatcher.match(uri)) {
|
switch (uriMatcher.match(uri)) {
|
||||||
case ENTRIES:
|
case ENTRIES:
|
||||||
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, selection, selectionArgs);
|
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, selection,
|
||||||
|
selectionArgs);
|
||||||
break;
|
break;
|
||||||
case ENTRY_ID:
|
case ENTRY_ID: {
|
||||||
{
|
|
||||||
String id = uri.getPathSegments().get(1);
|
String id = uri.getPathSegments().get(1);
|
||||||
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_DELIVERY_ENTRY_ROWID + "=" + id
|
count = db.delete(
|
||||||
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
|
DATABASE_DELIVERY_ENTRY_TABLE,
|
||||||
|
KEY_DELIVERY_ENTRY_ROWID
|
||||||
|
+ "="
|
||||||
|
+ id
|
||||||
|
+ (!TextUtils.isEmpty(selection) ? " AND ("
|
||||||
|
+ selection + ')' : ""), selectionArgs);
|
||||||
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGES:
|
case MESSAGES:
|
||||||
count = db.delete(DATABASE_MESSAGE_TABLE, selection, selectionArgs);
|
count = db.delete(DATABASE_MESSAGE_TABLE, selection, selectionArgs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MESSAGES_ID:
|
case MESSAGES_ID: {
|
||||||
{
|
|
||||||
String id = uri.getPathSegments().get(1);
|
String id = uri.getPathSegments().get(1);
|
||||||
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_MESSAGE_ROWID + "=" + id
|
count = db.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_MESSAGE_ROWID
|
||||||
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
|
+ "="
|
||||||
|
+ id
|
||||||
|
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
|
||||||
|
+ ')' : ""), selectionArgs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
|
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getType(Uri uri) {
|
public String getType(Uri uri) {
|
||||||
switch (uriMatcher.match(uri)){
|
switch (uriMatcher.match(uri)) {
|
||||||
case ENTRIES:
|
case ENTRIES:
|
||||||
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".entry";
|
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".entry";
|
||||||
case ENTRY_ID:
|
case ENTRY_ID:
|
||||||
return "vnd.android.cursor.item/vnd."+ PROVIDER_NAME + ".entry";
|
return "vnd.android.cursor.item/vnd." + PROVIDER_NAME + ".entry";
|
||||||
case MESSAGES:
|
case MESSAGES:
|
||||||
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".message";
|
return "vnd.android.cursor.dir/vnd." + PROVIDER_NAME + ".message";
|
||||||
case MESSAGES_ID:
|
case MESSAGES_ID:
|
||||||
return "vnd.android.cursor.item/vnd."+ PROVIDER_NAME + ".message";
|
return "vnd.android.cursor.item/vnd." + PROVIDER_NAME + ".message";
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unsupported URI: " + uri);
|
throw new IllegalArgumentException("Unsupported URI: " + uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Uri insert(Uri uri, ContentValues values) {
|
public Uri insert(Uri uri, ContentValues values) {
|
||||||
ContentValues initialValues;
|
ContentValues initialValues;
|
||||||
if (values != null) {
|
if (values != null) {
|
||||||
initialValues = new ContentValues(values);
|
initialValues = new ContentValues(values);
|
||||||
} else {
|
} else {
|
||||||
initialValues = new ContentValues();
|
initialValues = new ContentValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (uriMatcher.match(uri)) {
|
switch (uriMatcher.match(uri)) {
|
||||||
case ENTRIES:{
|
case ENTRIES: {
|
||||||
if (initialValues.containsKey(KEY_DELIVERY_ENTRY_NAME) == false) {
|
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");
|
||||||
|
}
|
||||||
|
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);
|
initialValues.put(KEY_DELIVERY_ENTRY_DELIVERED, 0);
|
||||||
|
|
||||||
SQLiteDatabase db = mDbHelper.getWritableDatabase();
|
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) {
|
if (rowId > 0) {
|
||||||
Uri newUri = ContentUris.withAppendedId( CONTENT_DELIVERY_URI, rowId);
|
Uri newUri = ContentUris.withAppendedId(CONTENT_DELIVERY_URI,
|
||||||
|
rowId);
|
||||||
getContext().getContentResolver().notifyChange(newUri, null);
|
getContext().getContentResolver().notifyChange(newUri, null);
|
||||||
return newUri;
|
return newUri;
|
||||||
}
|
}
|
||||||
throw new SQLException("Failed to insert row into " + uri);
|
throw new SQLException("Failed to insert row into " + uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case MESSAGES:
|
case MESSAGES: {
|
||||||
{
|
if (initialValues.containsKey(KEY_MESSAGE_NAME) == false) {
|
||||||
if (initialValues.containsKey(KEY_MESSAGE_NAME) == false) {
|
throw new SQLException(KEY_MESSAGE_NAME + " must be specified");
|
||||||
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();
|
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) {
|
if (rowId > 0) {
|
||||||
Uri newUri = ContentUris.withAppendedId( CONTENT_MESSAGE_URI, rowId);
|
Uri newUri = ContentUris.withAppendedId(CONTENT_MESSAGE_URI,
|
||||||
|
rowId);
|
||||||
getContext().getContentResolver().notifyChange(newUri, null);
|
getContext().getContentResolver().notifyChange(newUri, null);
|
||||||
return newUri;
|
return newUri;
|
||||||
}
|
}
|
||||||
@ -234,63 +242,64 @@ public class DeliveryDbAdapter extends ContentProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreate() {
|
public boolean onCreate() {
|
||||||
mDbHelper = new DeliveryDbHelper(getContext());
|
mDbHelper = new DeliveryDbHelper(getContext());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Cursor query(Uri uri, String[] projection, String selection,
|
public Cursor query(Uri uri, String[] projection, String selection,
|
||||||
String[] selectionArgs, String sortOrder) {
|
String[] selectionArgs, String sortOrder) {
|
||||||
|
|
||||||
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
|
||||||
|
|
||||||
switch (uriMatcher.match(uri)) {
|
switch (uriMatcher.match(uri)) {
|
||||||
case ENTRIES:
|
case ENTRIES:
|
||||||
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
|
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
|
||||||
qb.setProjectionMap(sDeliveryProjectionMap);
|
qb.setProjectionMap(sDeliveryProjectionMap);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case ENTRY_ID:
|
case ENTRY_ID:
|
||||||
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
|
qb.setTables(DATABASE_DELIVERY_ENTRY_TABLE);
|
||||||
qb.setProjectionMap(sDeliveryProjectionMap);
|
qb.setProjectionMap(sDeliveryProjectionMap);
|
||||||
qb.appendWhere(KEY_DELIVERY_ENTRY_ROWID + "=" + uri.getPathSegments().get(1));
|
qb.appendWhere(KEY_DELIVERY_ENTRY_ROWID + "="
|
||||||
|
+ uri.getPathSegments().get(1));
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MESSAGES:
|
case MESSAGES:
|
||||||
qb.setTables(DATABASE_MESSAGE_TABLE);
|
qb.setTables(DATABASE_MESSAGE_TABLE);
|
||||||
qb.setProjectionMap(sMessageProjectionMap);
|
qb.setProjectionMap(sMessageProjectionMap);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MESSAGES_ID:
|
case MESSAGES_ID:
|
||||||
qb.setTables(DATABASE_MESSAGE_TABLE);
|
qb.setTables(DATABASE_MESSAGE_TABLE);
|
||||||
qb.setProjectionMap(sMessageProjectionMap);
|
qb.setProjectionMap(sMessageProjectionMap);
|
||||||
qb.appendWhere(KEY_MESSAGE_ROWID + "=" + uri.getPathSegments().get(1));
|
qb.appendWhere(KEY_MESSAGE_ROWID + "="
|
||||||
|
+ uri.getPathSegments().get(1));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Run the query
|
// Run the query
|
||||||
SQLiteDatabase db = mDbHelper.getReadableDatabase();
|
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);
|
c.setNotificationUri(getContext().getContentResolver(), uri);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(Uri uri, ContentValues values, String selection,
|
public int update(Uri uri, ContentValues values, String selection,
|
||||||
String[] selectionArgs) {
|
String[] selectionArgs) {
|
||||||
@ -299,36 +308,41 @@ public class DeliveryDbAdapter extends ContentProvider {
|
|||||||
|
|
||||||
switch (uriMatcher.match(uri)) {
|
switch (uriMatcher.match(uri)) {
|
||||||
case ENTRIES:
|
case ENTRIES:
|
||||||
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, selection, selectionArgs);
|
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, selection,
|
||||||
|
selectionArgs);
|
||||||
break;
|
break;
|
||||||
case ENTRY_ID:
|
case ENTRY_ID: {
|
||||||
{
|
|
||||||
String id = uri.getPathSegments().get(1);
|
String id = uri.getPathSegments().get(1);
|
||||||
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, Words._ID + "=" + id
|
count = db.update(DATABASE_DELIVERY_ENTRY_TABLE, values, Words._ID
|
||||||
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
|
+ "="
|
||||||
|
+ id
|
||||||
|
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
|
||||||
|
+ ')' : ""), selectionArgs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MESSAGES:
|
case MESSAGES:
|
||||||
count = db.update(DATABASE_MESSAGE_TABLE, values, selection, selectionArgs);
|
count = db.update(DATABASE_MESSAGE_TABLE, values, selection,
|
||||||
|
selectionArgs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case MESSAGES_ID:
|
case MESSAGES_ID: {
|
||||||
{
|
|
||||||
String id = uri.getPathSegments().get(1);
|
String id = uri.getPathSegments().get(1);
|
||||||
count = db.update(DATABASE_MESSAGE_TABLE, values, Words._ID + "=" + id
|
count = db.update(DATABASE_MESSAGE_TABLE, values, Words._ID
|
||||||
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : ""), selectionArgs);
|
+ "="
|
||||||
|
+ id
|
||||||
|
+ (!TextUtils.isEmpty(selection) ? " AND (" + selection
|
||||||
|
+ ')' : ""), selectionArgs);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown URI " + uri);
|
throw new IllegalArgumentException("Unknown URI " + uri);
|
||||||
|
|
||||||
}
|
}
|
||||||
getContext().getContentResolver().notifyChange(uri, null);
|
getContext().getContentResolver().notifyChange(uri, null);
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import android.os.Bundle;
|
|||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.provider.ContactsContract.Contacts;
|
import android.provider.ContactsContract.Contacts;
|
||||||
import android.provider.ContactsContract.Data;
|
import android.provider.ContactsContract.Data;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@ -33,44 +32,48 @@ public class GroupEditActivity extends ListActivity {
|
|||||||
setContentView(R.layout.edit_group_list);
|
setContentView(R.layout.edit_group_list);
|
||||||
mGroupNameText = (EditText) findViewById(R.id.groupName);
|
mGroupNameText = (EditText) findViewById(R.id.groupName);
|
||||||
|
|
||||||
//Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null, null, Phones.NAME);
|
// Cursor c = getContentResolver().query(Phones.CONTENT_URI, null, null,
|
||||||
Cursor c = getContentResolver().query(Data.CONTENT_URI,
|
// null, Phones.NAME);
|
||||||
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
|
Cursor c = getContentResolver().query(
|
||||||
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
|
Data.CONTENT_URI,
|
||||||
null, Contacts.DISPLAY_NAME);
|
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);
|
startManagingCursor(c);
|
||||||
|
|
||||||
String[] mSelected = {};
|
String[] mSelected = {};
|
||||||
|
|
||||||
mDb = new GroupsDbAdapter(this);
|
mDb = new GroupsDbAdapter(this);
|
||||||
mDb.open();
|
mDb.open();
|
||||||
|
|
||||||
Long groupId;
|
Long groupId;
|
||||||
Bundle extras = getIntent().getExtras();
|
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) {
|
if (groupId != null) {
|
||||||
Cursor groupNameCursor = mDb.fetchGroup(groupId);
|
Cursor groupNameCursor = mDb.fetchGroup(groupId);
|
||||||
startManagingCursor(groupNameCursor);
|
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);
|
mGroupNameText.setText(groupName);
|
||||||
Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
|
Cursor numbers = mDb.fetchPhonesFromGroup(groupId);
|
||||||
startManagingCursor(numbers);
|
startManagingCursor(numbers);
|
||||||
numbers.moveToFirst();
|
numbers.moveToFirst();
|
||||||
int phoneNumIdx = numbers.getColumnIndex(Phone.NUMBER);
|
int phoneNumIdx = numbers.getColumnIndex(Phone.NUMBER);
|
||||||
mSelected = new String[numbers.getCount()];
|
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);
|
mSelected[i] = numbers.getString(phoneNumIdx);
|
||||||
numbers.moveToNext();
|
numbers.moveToNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
mGid = groupId;
|
mGid = groupId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c, new String[] {
|
mAdpater = new GroupDataListAdapter(this, R.layout.number_row, c,
|
||||||
Contacts.DISPLAY_NAME, Phone.NUMBER
|
new String[] { Contacts.DISPLAY_NAME, Phone.NUMBER },
|
||||||
}, new int[] {R.id.name, R.id.phone}, mSelected);
|
new int[] { R.id.name, R.id.phone }, mSelected);
|
||||||
setListAdapter(mAdpater);
|
setListAdapter(mAdpater);
|
||||||
|
|
||||||
Button ok = (Button) findViewById(R.id.okGroups);
|
Button ok = (Button) findViewById(R.id.okGroups);
|
||||||
@ -86,45 +89,45 @@ public class GroupEditActivity extends ListActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
Log.d("GroupEdit","---onStart");
|
//Log.d("GroupEdit", "---onStart");
|
||||||
mDb.open();
|
mDb.open();
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
Log.d("GroupEdit","---onResume");
|
//Log.d("GroupEdit", "---onResume");
|
||||||
super.onResume();
|
super.onResume();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d("GroupEdit","---OnStop");
|
//Log.d("GroupEdit", "---OnStop");
|
||||||
mDb.close();
|
mDb.close();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createGroup() {
|
private void createGroup() {
|
||||||
if (mGid == null) {
|
if (mGid == null) {
|
||||||
String name = mGroupNameText.getText().toString();
|
String name = mGroupNameText.getText().toString();
|
||||||
if(name.equals("")) {
|
if (name.equals("")) {
|
||||||
name = getResources().getString(R.string.noName);
|
name = getResources().getString(R.string.noName);
|
||||||
}
|
}
|
||||||
mGid = mDb.createGroup(name);
|
mGid = mDb.createGroup(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void reNameGroup() {
|
private void reNameGroup() {
|
||||||
if (mGid != null) {
|
if (mGid != null) {
|
||||||
String name = mGroupNameText.getText().toString();
|
String name = mGroupNameText.getText().toString();
|
||||||
if(name.equals("")) {
|
if (name.equals("")) {
|
||||||
name = getResources().getString(R.string.noName);
|
name = getResources().getString(R.string.noName);
|
||||||
}
|
}
|
||||||
mDb.updateGroup(mGid, name);
|
mDb.updateGroup(mGid, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GroupDataListAdapter extends SimpleCursorAdapter{
|
public class GroupDataListAdapter extends SimpleCursorAdapter {
|
||||||
|
|
||||||
public HashSet<String> selected;
|
public HashSet<String> selected;
|
||||||
int nameidx;
|
int nameidx;
|
||||||
@ -135,11 +138,11 @@ public class GroupEditActivity extends ListActivity {
|
|||||||
public GroupDataListAdapter(Context context, int layout, Cursor c,
|
public GroupDataListAdapter(Context context, int layout, Cursor c,
|
||||||
String[] from, int[] to, String[] rawSelected) {
|
String[] from, int[] to, String[] rawSelected) {
|
||||||
super(context, layout, c, from, to);
|
super(context, layout, c, from, to);
|
||||||
nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
|
nameidx = c.getColumnIndex(Contacts.DISPLAY_NAME);
|
||||||
numberidx = c.getColumnIndex(Phone.NUMBER);
|
numberidx = c.getColumnIndex(Phone.NUMBER);
|
||||||
idIdx = c.getColumnIndex(Data._ID);
|
idIdx = c.getColumnIndex(Data._ID);
|
||||||
mContext = context;
|
mContext = context;
|
||||||
selected = new HashSet<String>();
|
selected = new HashSet<String>();
|
||||||
for (int i = 0; i < rawSelected.length; i++) {
|
for (int i = 0; i < rawSelected.length; i++) {
|
||||||
selected.add(rawSelected[i].trim());
|
selected.add(rawSelected[i].trim());
|
||||||
}
|
}
|
||||||
@ -149,56 +152,54 @@ public class GroupEditActivity extends ListActivity {
|
|||||||
Cursor c = getCursor();
|
Cursor c = getCursor();
|
||||||
startManagingCursor(c);
|
startManagingCursor(c);
|
||||||
c.moveToPosition(position);
|
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.setOnClickListener(new addNumberToGroupClickListener(id));
|
||||||
checkbox.setChecked(selected.contains(contactNumber));
|
checkbox.setChecked(selected.contains(contactNumber));
|
||||||
|
|
||||||
|
|
||||||
background.setOnClickListener(new OnClickListener() {
|
background.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
|
CheckBox checkbox = (CheckBox) v
|
||||||
|
.findViewById(R.id.CheckBox);
|
||||||
checkbox.performClick();
|
checkbox.performClick();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return v;
|
return v;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class addNumberToGroupClickListener implements OnClickListener{
|
private class addNumberToGroupClickListener implements OnClickListener {
|
||||||
|
|
||||||
Long mId;
|
Long mId;
|
||||||
|
|
||||||
|
|
||||||
public addNumberToGroupClickListener(Long id) {
|
public addNumberToGroupClickListener(Long id) {
|
||||||
super();
|
super();
|
||||||
this.mId = id;
|
this.mId = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CheckBox cBox = (CheckBox)v;
|
CheckBox cBox = (CheckBox) v;
|
||||||
createGroup();
|
createGroup();
|
||||||
if(cBox.isChecked()) {
|
if (cBox.isChecked()) {
|
||||||
mDb.addPhoneToGroup(mGid, mId);
|
mDb.addPhoneToGroup(mGid, mId);
|
||||||
}else {
|
} else {
|
||||||
mDb.removePhoneToGroup(mGid, mId);
|
mDb.removePhoneToGroup(mGid, mId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package com.hectorone.multismssender;
|
package com.hectorone.multismssender;
|
||||||
|
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
@ -14,203 +13,219 @@ import android.util.Log;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple groups database access helper class. Defines the basic CRUD operations
|
* 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
|
* for the group add example, and gives the ability to list all groups as well
|
||||||
* retrieve or modify a specific group.
|
* as retrieve or modify a specific group.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class GroupsDbAdapter {
|
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_TO_PHONE_ROWID = "_id";
|
||||||
public static final String KEY_GROUP_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";
|
private static final String TAG = "groupsDbAdapter";
|
||||||
public static final String KEY_GROUP_TO_PHONE_GROUPID = "gid";
|
private GroupDbHelper mDbHelper;
|
||||||
public static final String KEY_GROUP_TO_PHONE_PHONEID = "pid";
|
private SQLiteDatabase mDb;
|
||||||
|
|
||||||
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 DATABASE_NAME = "dataGroup";
|
/**
|
||||||
private static final String DATABASE_GROUP_TABLE = "groups";
|
* Database creation sql statement
|
||||||
private static final String DATABASE_GROUP_TO_PHONE_TABLE = "group_TO_PHONE";
|
*/
|
||||||
private static final int DATABASE_VERSION = 4;
|
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) {
|
private final Context mCtx;
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
private static class GroupDbHelper extends SQLiteOpenHelper {
|
||||||
public void onCreate(SQLiteDatabase db) {
|
|
||||||
|
|
||||||
db.execSQL(DATABASE_GROUP_CREATE);
|
|
||||||
db.execSQL(DATABASE_GROUP_TO_PHONE_CREATE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
GroupDbHelper(Context context) {
|
||||||
@Override
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Constructor - takes the context to allow the database to be
|
public void onCreate(SQLiteDatabase db) {
|
||||||
* opened/created
|
|
||||||
*
|
|
||||||
* @param ctx the Context within which to work
|
|
||||||
*/
|
|
||||||
public GroupsDbAdapter(Context ctx) {
|
|
||||||
this.mCtx = ctx;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
db.execSQL(DATABASE_GROUP_CREATE);
|
||||||
* Open the groups database. If it cannot be opened, try to create a new
|
db.execSQL(DATABASE_GROUP_TO_PHONE_CREATE);
|
||||||
* 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@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
|
* Constructor - takes the context to allow the database to be
|
||||||
* successfully created return the new rowId for that group, otherwise return
|
* opened/created
|
||||||
* a -1 to indicate failure.
|
*
|
||||||
*
|
* @param ctx
|
||||||
* @param name the name of the group
|
* the Context within which to work
|
||||||
*/
|
*/
|
||||||
public long createGroup(String name) {
|
public GroupsDbAdapter(Context ctx) {
|
||||||
ContentValues initialValues = new ContentValues();
|
this.mCtx = ctx;
|
||||||
initialValues.put(KEY_GROUP_NAME, name);
|
}
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
/**
|
return this;
|
||||||
* 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 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
|
* 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
|
||||||
* @return Cursor over all groups
|
* indicate failure.
|
||||||
*/
|
*
|
||||||
public Cursor fetchAllGroups() {
|
* @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
|
* Delete the group with the given rowId
|
||||||
*
|
*
|
||||||
* @param rowId id of group to retrieve
|
* @param rowId
|
||||||
* @return Cursor positioned to matching group, if found
|
* id of group to delete
|
||||||
* @throws SQLException if group could not be found/retrieved
|
* @return true if deleted, false otherwise
|
||||||
*/
|
*/
|
||||||
public Cursor fetchGroup(long rowId) throws SQLException {
|
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() {
|
||||||
|
|
||||||
/**
|
return mDb.query(DATABASE_GROUP_TABLE, new String[] { KEY_GROUP_ROWID,
|
||||||
* @param rowId id of group to update
|
KEY_GROUP_NAME }, null, null, null, null, KEY_GROUP_NAME);
|
||||||
* @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 a Cursor positioned at the group that matches the given rowId
|
||||||
|
*
|
||||||
|
* @param rowId
|
||||||
public Cursor fetchPhonesFromGroup(long groupId) {
|
* id of group to retrieve
|
||||||
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);
|
* @return Cursor positioned to matching group, if found
|
||||||
Cursor userCursor = null;
|
* @throws SQLException
|
||||||
int phoneIdIdx = mCursor.getColumnIndex(KEY_GROUP_TO_PHONE_PHONEID);
|
* if group could not be found/retrieved
|
||||||
if(mCursor != null) {
|
*/
|
||||||
userCursor = mCtx.getContentResolver().query(Data.CONTENT_URI,
|
public Cursor fetchGroup(long rowId) throws SQLException {
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Cursor mCursor =
|
||||||
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);
|
mDb.query(true, DATABASE_GROUP_TABLE, new String[] { KEY_GROUP_ROWID,
|
||||||
}
|
KEY_GROUP_NAME }, KEY_GROUP_ROWID + "=" + rowId, null, null,
|
||||||
|
null, null, null);
|
||||||
public boolean removePhoneToGroup(long groupId, long phoneId) {
|
if (mCursor != null) {
|
||||||
return mDb.delete(DATABASE_GROUP_TO_PHONE_TABLE, KEY_GROUP_TO_PHONE_GROUPID + "=" + groupId+ " AND "+ KEY_GROUP_TO_PHONE_PHONEID + "=" + phoneId, null) > 0;
|
mCursor.moveToFirst();
|
||||||
}
|
}
|
||||||
|
return mCursor;
|
||||||
public String cursorToStringList(Cursor cursor, int columnIdx) {
|
|
||||||
cursor.moveToFirst();
|
}
|
||||||
String list = "( ";
|
|
||||||
while(!cursor.isAfterLast()) {
|
/**
|
||||||
list += cursor.getString(columnIdx);
|
* @param rowId
|
||||||
if(!cursor.isLast()) {
|
* id of group to update
|
||||||
list += " , ";
|
* @param name
|
||||||
}
|
* value to set group name to
|
||||||
cursor.moveToNext();
|
*/
|
||||||
}
|
public boolean updateGroup(long rowId, String name) {
|
||||||
list +=" )";
|
ContentValues args = new ContentValues();
|
||||||
return list;
|
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;
|
package com.hectorone.multismssender;
|
||||||
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -16,97 +15,96 @@ public class ListEntryActivity extends ListActivity {
|
|||||||
DeliveryDbAdapter mDbHelper;
|
DeliveryDbAdapter mDbHelper;
|
||||||
Long mDeliveryId;
|
Long mDeliveryId;
|
||||||
public static final int REFRESH_ID = 0;
|
public static final int REFRESH_ID = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.entry_list);
|
setContentView(R.layout.entry_list);
|
||||||
Bundle extras = getIntent().getExtras();
|
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();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillData() {
|
public void fillData() {
|
||||||
|
|
||||||
Cursor deliveryCursor = getContentResolver().query(DeliveryDbAdapter.CONTENT_DELIVERY_URI, null, DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID+" = " + mDeliveryId, null, null);
|
Cursor deliveryCursor = getContentResolver().query(
|
||||||
//Cursor deliveryCursor = mDbHelper.fetchAllEntry(mDeliveryId);
|
DeliveryDbAdapter.CONTENT_DELIVERY_URI,
|
||||||
|
null,
|
||||||
|
DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID + " = "
|
||||||
|
+ mDeliveryId, null, null);
|
||||||
|
|
||||||
startManagingCursor(deliveryCursor);
|
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 =
|
EntryCursorAdapter notes = new EntryCursorAdapter(this,
|
||||||
new EntryCursorAdapter(this, R.layout.entry_row, deliveryCursor, from, to);
|
R.layout.entry_row, deliveryCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
menu.add(0, REFRESH_ID,0, R.string.refresh);
|
menu.add(0, REFRESH_ID, 0, R.string.refresh);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case REFRESH_ID:
|
case REFRESH_ID:
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class EntryCursorAdapter extends SimpleCursorAdapter{
|
private class EntryCursorAdapter extends SimpleCursorAdapter {
|
||||||
Cursor c;
|
Cursor c;
|
||||||
int deliveredIdx;
|
int deliveredIdx;
|
||||||
|
|
||||||
public EntryCursorAdapter(Context context, int layout, Cursor c,
|
public EntryCursorAdapter(Context context, int layout, Cursor c,
|
||||||
String[] from, int[] to) {
|
String[] from, int[] to) {
|
||||||
super(context, layout, c, from, to);
|
super(context, layout, c, from, to);
|
||||||
//TODO this.getCursor()
|
// TODO this.getCursor()
|
||||||
this.c = c;
|
this.c = c;
|
||||||
deliveredIdx = c.getColumnIndex(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED);
|
deliveredIdx = c
|
||||||
|
.getColumnIndex(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
View v = super.getView(position, convertView, 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);
|
c.moveToPosition(position);
|
||||||
int delivered = c.getInt(deliveredIdx);
|
int delivered = c.getInt(deliveredIdx);
|
||||||
if(delivered != 0) {
|
if (delivered != 0) {
|
||||||
image.setImageResource(R.drawable.btn_check_buttonless_on);
|
image.setImageResource(R.drawable.btn_check_buttonless_on);
|
||||||
}else {
|
} else {
|
||||||
image.setImageResource(R.drawable.btn_check_buttonless_off);
|
image.setImageResource(R.drawable.btn_check_buttonless_off);
|
||||||
}
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,19 +5,18 @@ import android.content.ContentValues;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
public class MessageReceiver extends BroadcastReceiver{
|
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 ANDROID_MESSAGE_RECEIVED = "android.provider.Telephony.SMS_RECEIVED";
|
||||||
public static final String DEBUG_TAG="-------MessageReceiver--------";
|
public static final String DEBUG_TAG = "-------MessageReceiver--------";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
||||||
|
|
||||||
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
|
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
|
||||||
Log.d(DEBUG_TAG, "SMS_RECEIVED");
|
//Log.d(DEBUG_TAG, "SMS_RECEIVED");
|
||||||
|
|
||||||
Uri entryURI = intent.getData();
|
Uri entryURI = intent.getData();
|
||||||
if (entryURI != null){
|
if (entryURI != null){
|
||||||
@ -26,20 +25,6 @@ public class MessageReceiver extends BroadcastReceiver{
|
|||||||
context.getContentResolver().update(entryURI, values, null, null);
|
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;
|
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_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_PROGRESS = 0;
|
||||||
private static final int DIALOG_FINISHED = 1;
|
private static final int DIALOG_FINISHED = 1;
|
||||||
private static final int DIALOG_NONUMBER = 2;
|
private static final int DIALOG_NONUMBER = 2;
|
||||||
private static final int DIALOG_MANYMESSAGE = 3;
|
private static final int DIALOG_MANYMESSAGE = 3;
|
||||||
private static final int DIALOG_STARTWAIT = 4;
|
private static final int DIALOG_STARTWAIT = 4;
|
||||||
private static final int DIALOG_PROGRESS_CANCEL = 5;
|
private static final int DIALOG_PROGRESS_CANCEL = 5;
|
||||||
private static final int SENDING_DIALOG_KEY = 6;
|
private static final int SENDING_DIALOG_KEY = 6;
|
||||||
|
|
||||||
public static final String PARAM_NUMBERS_LIST = "param number list";
|
public static final String PARAM_NUMBERS_LIST = "param number list";
|
||||||
public static final String PARAM_FLUSH = "param flush";
|
public static final String PARAM_FLUSH = "param flush";
|
||||||
@ -72,89 +72,110 @@ public class MultiSmsSender extends Activity {
|
|||||||
final Handler mHandler = new Handler() {
|
final Handler mHandler = new Handler() {
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
int type = msg.getData().getInt("ORIGIN");
|
int type = msg.getData().getInt("ORIGIN");
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case DIALOG_PROGRESS:{
|
case DIALOG_PROGRESS: {
|
||||||
int total = msg.getData().getInt("total");
|
int total = msg.getData().getInt("total");
|
||||||
//Log.d(DEBUG_TAG, "========= total is "+total);
|
|
||||||
mSendingDialog.setProgress(total);
|
mSendingDialog.setProgress(total);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DIALOG_PROGRESS_CANCEL:{
|
|
||||||
|
case DIALOG_PROGRESS_CANCEL: {
|
||||||
mSendingDialog.cancel();
|
mSendingDialog.cancel();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DIALOG_FINISHED:{
|
case DIALOG_FINISHED: {
|
||||||
//dismissDialog(SENDING_DIALOG_KEY);
|
|
||||||
int total = msg.getData().getInt("total");
|
int total = msg.getData().getInt("total");
|
||||||
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
|
|
||||||
getResources().getString(R.string.ok),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
}
|
|
||||||
}).setMessage(
|
|
||||||
total + " "
|
|
||||||
+ getResources().getString(R.string.message_sent))
|
|
||||||
.show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
case DIALOG_NONUMBER:{
|
|
||||||
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
|
|
||||||
getResources().getString(R.string.ok),
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
dialog.dismiss();
|
|
||||||
|
|
||||||
}
|
|
||||||
}).setMessage(
|
|
||||||
getResources().getString(R.string.enter_number)).show();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case DIALOG_MANYMESSAGE:{
|
|
||||||
|
|
||||||
new AlertDialog.Builder(MultiSmsSender.this)
|
new AlertDialog.Builder(MultiSmsSender.this)
|
||||||
.setMessage(getResources().getString(R.string.warning_many_message))
|
.setPositiveButton(
|
||||||
.setCancelable(false)
|
getResources().getString(R.string.ok),
|
||||||
.setPositiveButton(getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
synchronized (MultiSmsSender.this) {
|
public void onClick(DialogInterface dialog,
|
||||||
MultiSmsSender.this.notify();
|
int which) {
|
||||||
mManyMessageContinue = true;
|
dialog.dismiss();
|
||||||
}
|
|
||||||
dialog.dismiss();
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setNegativeButton(getResources().getString(R.string.cancel), new DialogInterface.OnClickListener() {
|
.setMessage(
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
total
|
||||||
synchronized (MultiSmsSender.this) {
|
+ " "
|
||||||
MultiSmsSender.this.notify();
|
+ getResources().getString(
|
||||||
mManyMessageContinue = false;
|
R.string.message_sent)).show();
|
||||||
}
|
break;
|
||||||
dialog.dismiss();
|
}
|
||||||
}
|
|
||||||
})
|
case DIALOG_NONUMBER: {
|
||||||
.show();
|
new AlertDialog.Builder(MultiSmsSender.this)
|
||||||
|
.setPositiveButton(
|
||||||
|
getResources().getString(R.string.ok),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int which) {
|
||||||
|
dialog.dismiss();
|
||||||
|
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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))
|
||||||
|
.setCancelable(false)
|
||||||
|
.setPositiveButton(
|
||||||
|
getResources().getString(R.string.ok),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog,
|
||||||
|
int id) {
|
||||||
|
synchronized (MultiSmsSender.this) {
|
||||||
|
MultiSmsSender.this.notify();
|
||||||
|
mManyMessageContinue = true;
|
||||||
|
}
|
||||||
|
dialog.dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.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();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case DIALOG_STARTWAIT:{
|
case DIALOG_STARTWAIT: {
|
||||||
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
|
new AlertDialog.Builder(MultiSmsSender.this)
|
||||||
getResources().getString(R.string.ok),
|
.setPositiveButton(
|
||||||
new DialogInterface.OnClickListener() {
|
getResources().getString(R.string.ok),
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog,
|
||||||
synchronized (MultiSmsSender.this) {
|
int which) {
|
||||||
MultiSmsSender.this.notify();
|
synchronized (MultiSmsSender.this) {
|
||||||
}
|
MultiSmsSender.this.notify();
|
||||||
dialog.dismiss();
|
}
|
||||||
|
dialog.dismiss();
|
||||||
|
|
||||||
}
|
}
|
||||||
}).setMessage(getResources().getString(R.string.more_message)).show();
|
})
|
||||||
|
.setMessage(
|
||||||
|
getResources().getString(R.string.more_message))
|
||||||
|
.show();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -168,17 +189,15 @@ public class MultiSmsSender extends Activity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.main);
|
setContentView(R.layout.main);
|
||||||
|
|
||||||
|
mAddButton = (Button) findViewById(R.id.contacts);
|
||||||
mAddButton = (Button) findViewById(R.id.contacts);
|
mAddGroupButton = (Button) findViewById(R.id.groups);
|
||||||
mAddGroupButton = (Button)findViewById(R.id.groups);
|
mSend = (Button) findViewById(R.id.send);
|
||||||
mSend = (Button) findViewById(R.id.send);
|
mContacts = (TextView) findViewById(R.id.numbers);
|
||||||
mContacts = (TextView) findViewById(R.id.numbers);
|
mEditor = (TextView) findViewById(R.id.editor);
|
||||||
mEditor = (TextView) findViewById(R.id.editor);
|
mDeliveryCheckBox = (CheckBox) findViewById(R.id.deliveryCheckBox);
|
||||||
mDeliveryCheckBox = (CheckBox) findViewById(R.id.deliveryCheckBox);
|
|
||||||
|
|
||||||
mContacts.setImeOptions(EditorInfo.IME_ACTION_NEXT);
|
mContacts.setImeOptions(EditorInfo.IME_ACTION_NEXT);
|
||||||
// mEditor.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
// mEditor.setImeOptions(EditorInfo.IME_ACTION_DONE);
|
||||||
|
|
||||||
|
|
||||||
mAddButton.setOnClickListener(new OnClickListener() {
|
mAddButton.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@ -186,13 +205,12 @@ public class MultiSmsSender extends Activity {
|
|||||||
selectNumbers();
|
selectNumbers();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
mAddGroupButton.setOnClickListener(new OnClickListener() {
|
mAddGroupButton.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
display_group_list();
|
display_group_list();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
mSend.setOnClickListener(new OnClickListener() {
|
mSend.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@ -200,14 +218,13 @@ public class MultiSmsSender extends Activity {
|
|||||||
showDialog(SENDING_DIALOG_KEY);
|
showDialog(SENDING_DIALOG_KEY);
|
||||||
mThreadSender = new MessageSenderThread(mHandler);
|
mThreadSender = new MessageSenderThread(mHandler);
|
||||||
mThreadSender.start();
|
mThreadSender.start();
|
||||||
//sendMessage();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectNumbers() {
|
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);
|
Intent i = new Intent(this, PhoneNumberSelection.class);
|
||||||
String rawNumbers = mContacts.getText().toString();
|
String rawNumbers = mContacts.getText().toString();
|
||||||
String[] numbers = rawNumbers.split(",");
|
String[] numbers = rawNumbers.split(",");
|
||||||
@ -215,28 +232,27 @@ public class MultiSmsSender extends Activity {
|
|||||||
startActivityForResult(i, ACTIVITY_EDIT);
|
startActivityForResult(i, ACTIVITY_EDIT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class MessageSenderThread extends Thread {
|
||||||
|
|
||||||
private class MessageSenderThread extends Thread{
|
|
||||||
|
|
||||||
Handler mHandler;
|
Handler mHandler;
|
||||||
|
|
||||||
public MessageSenderThread( Handler h) {
|
public MessageSenderThread(Handler h) {
|
||||||
mHandler = h;
|
mHandler = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized void run() {
|
public synchronized void run() {
|
||||||
super.run();
|
super.run();
|
||||||
sendMessage(mHandler);
|
sendMessage(mHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void sendMessage(Handler handler) {
|
|
||||||
//DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(this);
|
public void sendMessage(Handler handler) {
|
||||||
|
|
||||||
SmsManager manager = SmsManager.getDefault();
|
SmsManager manager = SmsManager.getDefault();
|
||||||
String message = mEditor.getText().toString();
|
String message = mEditor.getText().toString();
|
||||||
HashMap<String, Long> deliveryIdMap = new HashMap<String, Long>();
|
HashMap<String, Long> deliveryIdMap = new HashMap<String, Long>();
|
||||||
mManyMessageContinue = true;
|
mManyMessageContinue = true;
|
||||||
|
|
||||||
if("".equals(message)) {
|
if("".equals(message)) {
|
||||||
{
|
{
|
||||||
@ -245,68 +261,63 @@ public class MultiSmsSender extends Activity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] numbers = mContacts.getText().toString().split(",");
|
String[] numbers = mContacts.getText().toString().split(",");
|
||||||
ArrayList<String> phoneNumberConform = new ArrayList<String>();
|
ArrayList<String> phoneNumberConform = new ArrayList<String>();
|
||||||
int size = numbers.length;
|
int size = numbers.length;
|
||||||
boolean haveDeliveryReports = mDeliveryCheckBox.isChecked();
|
boolean haveDeliveryReports = mDeliveryCheckBox.isChecked();
|
||||||
long messageId = -1;
|
long messageId = -1;
|
||||||
ArrayList<String> messages = manager.divideMessage(message);
|
ArrayList<String> messages = manager.divideMessage(message);
|
||||||
int messageCount = messages.size();
|
int messageCount = messages.size();
|
||||||
|
|
||||||
|
|
||||||
if (haveDeliveryReports) {
|
if (haveDeliveryReports) {
|
||||||
ContentValues values = new ContentValues(2);
|
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
|
||||||
//Check if numbers are correct and prepare deliveryId
|
for (int i = 0; i < size; i++) {
|
||||||
for(int i= 0; i< size; i++) {
|
|
||||||
String newN = numbers[i].trim();
|
String newN = numbers[i].trim();
|
||||||
newN = newN.replace(" ", "");
|
newN = newN.replace(" ", "");
|
||||||
if (!newN.equals("")
|
if (!newN.equals("")
|
||||||
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)
|
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)
|
||||||
&& !phoneNumberConform.contains(newN)) {
|
&& !phoneNumberConform.contains(newN)) {
|
||||||
phoneNumberConform.add(newN);
|
phoneNumberConform.add(newN);
|
||||||
if(haveDeliveryReports) {
|
if (haveDeliveryReports) {
|
||||||
ContentValues values = new ContentValues(3);
|
ContentValues values = new ContentValues(3);
|
||||||
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME, nameFromNumber(getContentResolver(), newN));
|
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME,
|
||||||
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER, newN);
|
nameFromNumber(getContentResolver(), newN));
|
||||||
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID, messageId);
|
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER,
|
||||||
|
newN);
|
||||||
long entryId = Long.parseLong(getContentResolver().insert(DeliveryDbAdapter.CONTENT_DELIVERY_URI, values).getPathSegments().get(1));
|
values.put(DeliveryDbAdapter.KEY_DELIVERY_ENTRY_MESSAGE_ID,
|
||||||
deliveryIdMap.put(newN,entryId);
|
messageId);
|
||||||
/*
|
|
||||||
mDbHelper.open();
|
|
||||||
long entryId = mDbHelper.createEntry(nameFromNumber(getContentResolver(), newN), newN, messageId);
|
|
||||||
deliveryIdMap.put(newN,entryId);
|
|
||||||
mDbHelper.close();*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
long entryId = Long.parseLong(getContentResolver()
|
||||||
|
.insert(DeliveryDbAdapter.CONTENT_DELIVERY_URI,
|
||||||
|
values).getPathSegments().get(1));
|
||||||
|
deliveryIdMap.put(newN, entryId);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
numbers = new String[size];
|
numbers = new String[size];
|
||||||
numbers = phoneNumberConform.toArray(numbers);
|
numbers = phoneNumberConform.toArray(numbers);
|
||||||
size = phoneNumberConform.size();
|
size = phoneNumberConform.size();
|
||||||
|
|
||||||
if (size != 0) {
|
if (size != 0) {
|
||||||
if(size > MANY_MESSAGE){
|
if (size > MANY_MESSAGE) {
|
||||||
{
|
{
|
||||||
displayDialog(handler, DIALOG_MANYMESSAGE,null);
|
displayDialog(handler, DIALOG_MANYMESSAGE, null);
|
||||||
}
|
}
|
||||||
synchronized (MultiSmsSender.this) {
|
synchronized (MultiSmsSender.this) {
|
||||||
try {
|
try {
|
||||||
@ -316,13 +327,12 @@ public class MultiSmsSender extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mManyMessageContinue) {
|
if (mManyMessageContinue) {
|
||||||
|
|
||||||
int message_sent = 0;
|
int message_sent = 0;
|
||||||
int chunk_max = Math.min(MANY_MESSAGE, size);
|
int chunk_max = Math.min(MANY_MESSAGE, size);
|
||||||
do {
|
do {
|
||||||
if (message_sent > 0) {
|
if (message_sent > 0) {
|
||||||
displayDialog(handler, DIALOG_STARTWAIT, null);
|
displayDialog(handler, DIALOG_STARTWAIT, null);
|
||||||
@ -340,16 +350,15 @@ public class MultiSmsSender extends Activity {
|
|||||||
for (int i = message_sent; i < chunk_max; i++) {
|
for (int i = message_sent; i < chunk_max; i++) {
|
||||||
message_sent++;
|
message_sent++;
|
||||||
String newN = numbers[i];
|
String newN = numbers[i];
|
||||||
|
|
||||||
Message msg = handler.obtainMessage();
|
Message msg = handler.obtainMessage();
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putInt("ORIGIN", DIALOG_PROGRESS);
|
b.putInt("ORIGIN", DIALOG_PROGRESS);
|
||||||
b.putInt("total", (i * 100) / size);
|
b.putInt("total", (i * 100) / size);
|
||||||
msg.setData(b);
|
msg.setData(b);
|
||||||
handler.sendMessage(msg);
|
handler.sendMessage(msg);
|
||||||
|
|
||||||
ArrayList<PendingIntent> deliveryIntents = null;
|
ArrayList<PendingIntent> deliveryIntents = null;
|
||||||
ArrayList<PendingIntent> sentIntents = null;
|
ArrayList<PendingIntent> sentIntents = null;
|
||||||
|
|
||||||
if (haveDeliveryReports) {
|
if (haveDeliveryReports) {
|
||||||
deliveryIntents = new ArrayList<PendingIntent>(
|
deliveryIntents = new ArrayList<PendingIntent>(
|
||||||
@ -368,17 +377,19 @@ public class MultiSmsSender extends Activity {
|
|||||||
// Log.d(DEBUG_TAG,
|
// Log.d(DEBUG_TAG,
|
||||||
// "entry is "+entryId+" to number"+newN);
|
// "entry is "+entryId+" to number"+newN);
|
||||||
for (int j = 0; j < messageCount; j++) {
|
for (int j = 0; j < messageCount; j++) {
|
||||||
if (j == (messageCount -1)){
|
if (j == (messageCount - 1)) {
|
||||||
Uri entryURI = Uri.withAppendedPath(
|
Uri entryURI = Uri
|
||||||
DeliveryDbAdapter.CONTENT_DELIVERY_URI, ""
|
.withAppendedPath(
|
||||||
+ entryId);
|
DeliveryDbAdapter.CONTENT_DELIVERY_URI,
|
||||||
|
"" + entryId);
|
||||||
Intent intent = new Intent(
|
Intent intent = new Intent(
|
||||||
MessageReceiver.MESSAGE_RECEIVED,
|
MessageReceiver.MESSAGE_RECEIVED,
|
||||||
entryURI, this, MessageReceiver.class);
|
entryURI, this,
|
||||||
|
MessageReceiver.class);
|
||||||
deliveryIntents.add(PendingIntent.getBroadcast(
|
|
||||||
this, 0, intent, 0));
|
deliveryIntents.add(PendingIntent
|
||||||
}else{
|
.getBroadcast(this, 0, intent, 0));
|
||||||
|
} else {
|
||||||
deliveryIntents.add(null);
|
deliveryIntents.add(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -393,22 +404,22 @@ public class MultiSmsSender extends Activity {
|
|||||||
} while (((size - message_sent) > 0) && appli_running);
|
} while (((size - message_sent) > 0) && appli_running);
|
||||||
|
|
||||||
Message msg = handler.obtainMessage();
|
Message msg = handler.obtainMessage();
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putInt("ORIGIN", DIALOG_FINISHED);
|
b.putInt("ORIGIN", DIALOG_FINISHED);
|
||||||
b.putInt("total", phoneNumberConform.size());
|
b.putInt("total", phoneNumberConform.size());
|
||||||
msg.setData(b);
|
msg.setData(b);
|
||||||
handler.sendMessage(msg);
|
handler.sendMessage(msg);
|
||||||
}
|
}
|
||||||
displayDialog(handler, DIALOG_PROGRESS_CANCEL,null);
|
displayDialog(handler, DIALOG_PROGRESS_CANCEL, null);
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
displayDialog(handler, DIALOG_NONUMBER,null);
|
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();
|
Message msg = handler.obtainMessage();
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
b.putInt("ORIGIN", dialogId);
|
b.putInt("ORIGIN", dialogId);
|
||||||
@ -520,27 +531,27 @@ public class MultiSmsSender extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// *********************** HELPER ****************************************
|
// *********************** HELPER ****************************************
|
||||||
|
|
||||||
|
public String nameFromNumber(ContentResolver resolver, String number) {
|
||||||
public String nameFromNumber(ContentResolver resolver, String number) {
|
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,
|
||||||
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
|
Uri.encode(number));
|
||||||
Cursor c = null;
|
Cursor c = null;
|
||||||
try {
|
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) {
|
} catch (Exception e) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (c != null) {
|
||||||
if(c != null) {
|
c.moveToFirst();
|
||||||
c.moveToFirst();
|
if (c.isFirst()) {
|
||||||
if(c.isFirst()) {
|
return c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));
|
||||||
return c.getString(c.getColumnIndex(PhoneLookup.DISPLAY_NAME));
|
} else {
|
||||||
}else {
|
return "";
|
||||||
return "";
|
}
|
||||||
}
|
}
|
||||||
}
|
return "";
|
||||||
return "";
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,29 +21,27 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
public class PhoneNumberSelection extends ListActivity {
|
||||||
public class PhoneNumberSelection extends ListActivity
|
|
||||||
{
|
|
||||||
PhoneDataListAdapter mAdpater;
|
PhoneDataListAdapter mAdpater;
|
||||||
|
|
||||||
HashSet<String> mSelectedSet;
|
|
||||||
private static final int INSERT_ID = Menu.FIRST;
|
|
||||||
private static final int SELECT_ALL_ID = Menu.FIRST + 1;
|
|
||||||
private static final int DESELECT_ALL_ID = Menu.FIRST + 2;
|
|
||||||
|
|
||||||
|
HashSet<String> mSelectedSet;
|
||||||
|
private static final int INSERT_ID = Menu.FIRST;
|
||||||
|
private static final int SELECT_ALL_ID = Menu.FIRST + 1;
|
||||||
|
private static final int DESELECT_ALL_ID = Menu.FIRST + 2;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.number_list);
|
setContentView(R.layout.number_list);
|
||||||
|
|
||||||
|
|
||||||
String[] selected;
|
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) {
|
if (selected == null) {
|
||||||
Bundle extras = getIntent().getExtras();
|
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>();
|
mSelectedSet = new HashSet<String>();
|
||||||
@ -56,37 +54,37 @@ public class PhoneNumberSelection extends ListActivity
|
|||||||
ok.setOnClickListener(new OnClickListener() {
|
ok.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
String [] numbers = new String[mSelectedSet.size()];
|
String[] numbers = new String[mSelectedSet.size()];
|
||||||
mSelectedSet.toArray(numbers);
|
mSelectedSet.toArray(numbers);
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
bundle.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST, numbers);
|
bundle.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST,
|
||||||
|
numbers);
|
||||||
bundle.putBoolean(MultiSmsSender.PARAM_FLUSH, true);
|
bundle.putBoolean(MultiSmsSender.PARAM_FLUSH, true);
|
||||||
i.putExtras(bundle);
|
i.putExtras(bundle);
|
||||||
|
|
||||||
setResult(RESULT_OK, i);
|
setResult(RESULT_OK, i);
|
||||||
finish();
|
finish();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fillData() {
|
private void fillData() {
|
||||||
|
|
||||||
|
|
||||||
Cursor c = getContentResolver().query(Data.CONTENT_URI,
|
Cursor c = getContentResolver().query(
|
||||||
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
|
Data.CONTENT_URI,
|
||||||
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
|
new String[] { Data._ID, Data.MIMETYPE, Phone.NUMBER,
|
||||||
null, Contacts.DISPLAY_NAME);
|
Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME },
|
||||||
|
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'", null,
|
||||||
|
Contacts.DISPLAY_NAME);
|
||||||
startManagingCursor(c);
|
startManagingCursor(c);
|
||||||
mAdpater = new PhoneDataListAdapter(this, R.layout.number_row, c, new String[] {
|
mAdpater = new PhoneDataListAdapter(this, R.layout.number_row, c,
|
||||||
Contacts.DISPLAY_NAME, Phone.NUMBER
|
new String[] { Contacts.DISPLAY_NAME, Phone.NUMBER },
|
||||||
}, new int[] {R.id.name, R.id.phone}, mSelectedSet);
|
new int[] { R.id.name, R.id.phone }, mSelectedSet);
|
||||||
|
|
||||||
|
|
||||||
setListAdapter(mAdpater);
|
setListAdapter(mAdpater);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,19 +98,23 @@ public class PhoneNumberSelection extends ListActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case INSERT_ID:
|
case INSERT_ID:
|
||||||
display_group_list();
|
display_group_list();
|
||||||
return true;
|
return true;
|
||||||
case SELECT_ALL_ID:
|
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 =
|
||||||
Cursor c = getContentResolver().query(Data.CONTENT_URI,
|
* c.getColumnIndex(Phones.NUMBER);
|
||||||
new String[] {Data._ID, Data.MIMETYPE, Phone.NUMBER, Phone.TYPE, Phone.LABEL, Contacts.DISPLAY_NAME},
|
*/
|
||||||
Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'",
|
Cursor c = getContentResolver().query(
|
||||||
null, null);
|
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);
|
int numberIdx = c.getColumnIndex(Phone.NUMBER);
|
||||||
startManagingCursor(c);
|
startManagingCursor(c);
|
||||||
c.moveToFirst();
|
c.moveToFirst();
|
||||||
@ -126,60 +128,44 @@ public class PhoneNumberSelection extends ListActivity
|
|||||||
mSelectedSet = new HashSet<String>();
|
mSelectedSet = new HashSet<String>();
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void display_group_list() {
|
||||||
public void display_group_list(){
|
|
||||||
|
|
||||||
Intent i = new Intent(this, SelectGroupActivity.class);
|
Intent i = new Intent(this, SelectGroupActivity.class);
|
||||||
startActivityForResult(i, MultiSmsSender.ACTIVITY_ADD_GROUP);
|
startActivityForResult(i, MultiSmsSender.ACTIVITY_ADD_GROUP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*@Override
|
public class PhoneDataListAdapter extends SimpleCursorAdapter {
|
||||||
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,
|
public PhoneDataListAdapter(Context context, int layout, Cursor c,
|
||||||
String[] from, int[] to, HashSet<String> selected) {
|
String[] from, int[] to, HashSet<String> selected) {
|
||||||
super(context, layout, c, from, to);
|
super(context, layout, c, from, to);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
public View getView(int position, View convertView, ViewGroup parent) {
|
||||||
|
|
||||||
View v = super.getView(position, convertView, parent);
|
View v = super.getView(position, convertView, parent);
|
||||||
LinearLayout background = (LinearLayout)v.findViewById(R.id.row_background);
|
LinearLayout background = (LinearLayout) v
|
||||||
String contactNumber = ((TextView)v.findViewById(R.id.phone)).getText().toString();
|
.findViewById(R.id.row_background);
|
||||||
|
String contactNumber = ((TextView) v.findViewById(R.id.phone))
|
||||||
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
|
.getText().toString();
|
||||||
checkbox.setOnClickListener(new addNumberToSelectedClickListener(contactNumber));
|
|
||||||
|
CheckBox checkbox = (CheckBox) v.findViewById(R.id.CheckBox);
|
||||||
|
checkbox.setOnClickListener(new addNumberToSelectedClickListener(
|
||||||
|
contactNumber));
|
||||||
checkbox.setChecked(mSelectedSet.contains(contactNumber));
|
checkbox.setChecked(mSelectedSet.contains(contactNumber));
|
||||||
|
|
||||||
|
|
||||||
background.setOnClickListener(new OnClickListener() {
|
background.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CheckBox checkbox = (CheckBox)v.findViewById(R.id.CheckBox);
|
CheckBox checkbox = (CheckBox) v
|
||||||
|
.findViewById(R.id.CheckBox);
|
||||||
checkbox.performClick();
|
checkbox.performClick();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return v;
|
return v;
|
||||||
@ -187,7 +173,7 @@ public class PhoneNumberSelection extends ListActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class addNumberToSelectedClickListener implements OnClickListener{
|
private class addNumberToSelectedClickListener implements OnClickListener {
|
||||||
|
|
||||||
String contactNumber;
|
String contactNumber;
|
||||||
|
|
||||||
@ -196,24 +182,26 @@ public class PhoneNumberSelection extends ListActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
CheckBox checkBox = (CheckBox)v;
|
CheckBox checkBox = (CheckBox) v;
|
||||||
if(checkBox.isChecked()) {
|
if (checkBox.isChecked()) {
|
||||||
mSelectedSet.add(contactNumber);
|
mSelectedSet.add(contactNumber);
|
||||||
}else {
|
} else {
|
||||||
mSelectedSet.remove(contactNumber);
|
mSelectedSet.remove(contactNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
|
protected void onActivityResult(int requestCode, int resultCode,
|
||||||
|
Intent intent) {
|
||||||
super.onActivityResult(requestCode, resultCode, intent);
|
super.onActivityResult(requestCode, resultCode, intent);
|
||||||
if(intent != null) {
|
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++) {
|
for (int i = 0; i < numbers.length; i++) {
|
||||||
mSelectedSet.add(numbers[i]);
|
mSelectedSet.add(numbers[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fillData();
|
fillData();
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.hectorone.multismssender;
|
package com.hectorone.multismssender;
|
||||||
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
@ -16,14 +15,12 @@ import android.widget.SimpleCursorAdapter;
|
|||||||
|
|
||||||
public class SelectDeliveryActivity extends ListActivity {
|
public class SelectDeliveryActivity extends ListActivity {
|
||||||
|
|
||||||
|
|
||||||
DeliveryDbAdapter mDbHelper;
|
DeliveryDbAdapter mDbHelper;
|
||||||
public static final int DELETE_ID = Menu.FIRST;
|
public static final int DELETE_ID = Menu.FIRST;
|
||||||
public static final int DELETE_ALL_ID = Menu.FIRST + 1;
|
public static final int DELETE_ALL_ID = Menu.FIRST + 1;
|
||||||
public static final int REFRESH_ID = Menu.FIRST + 2;
|
public static final int REFRESH_ID = Menu.FIRST + 2;
|
||||||
|
|
||||||
public static final String PARAM_DELIVERY_ID = "param_delivery_id";
|
|
||||||
|
|
||||||
|
public static final String PARAM_DELIVERY_ID = "param_delivery_id";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@ -32,31 +29,31 @@ public class SelectDeliveryActivity extends ListActivity {
|
|||||||
fillData();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void fillData() {
|
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);
|
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};
|
int[] to = new int[] { R.id.date, R.id.name };
|
||||||
|
|
||||||
SimpleCursorAdapter notes =
|
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
|
||||||
new SimpleCursorAdapter(this, R.layout.delivery_row, deliveryCursor, from, to);
|
R.layout.delivery_row, deliveryCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
menu.add(0, DELETE_ALL_ID,0, R.string.remove_all);
|
menu.add(0, DELETE_ALL_ID, 0, R.string.remove_all);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -67,14 +64,15 @@ public class SelectDeliveryActivity extends ListActivity {
|
|||||||
menu.add(0, DELETE_ID, 0, R.string.remove);
|
menu.add(0, DELETE_ID, 0, R.string.remove);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case DELETE_ID:
|
case DELETE_ID:
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||||
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI, DeliveryDbAdapter.KEY_MESSAGE_ROWID+ "="+ info.id, null);
|
.getMenuInfo();
|
||||||
|
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
|
||||||
|
DeliveryDbAdapter.KEY_MESSAGE_ROWID + "=" + info.id, null);
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -83,15 +81,16 @@ public class SelectDeliveryActivity extends ListActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case DELETE_ALL_ID:
|
case DELETE_ALL_ID:
|
||||||
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI, null, null);
|
getContentResolver().delete(DeliveryDbAdapter.CONTENT_MESSAGE_URI,
|
||||||
|
null, null);
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
protected void onListItemClick(ListView l, View v, int position, long id) {
|
||||||
Intent i = new Intent(this, ListEntryActivity.class);
|
Intent i = new Intent(this, ListEntryActivity.class);
|
||||||
|
@ -1,14 +1,10 @@
|
|||||||
package com.hectorone.multismssender;
|
package com.hectorone.multismssender;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
import android.provider.ContactsContract.CommonDataKinds.Phone;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@ -18,21 +14,20 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SimpleCursorAdapter;
|
import android.widget.SimpleCursorAdapter;
|
||||||
|
|
||||||
|
public class SelectGroupActivity extends ListActivity {
|
||||||
public class SelectGroupActivity extends ListActivity{
|
|
||||||
|
|
||||||
GroupsDbAdapter mDbHelper;
|
GroupsDbAdapter mDbHelper;
|
||||||
public static final int DELETE_ID = Menu.FIRST;
|
public static final int DELETE_ID = Menu.FIRST;
|
||||||
public static final int EDIT_ID = Menu.FIRST + 1;
|
public static final int EDIT_ID = Menu.FIRST + 1;
|
||||||
public static final int CREATE_ID = Menu.FIRST + 2;
|
public static final int CREATE_ID = Menu.FIRST + 2;
|
||||||
|
|
||||||
public static final String PARAM_GROUP_ID = "gid";
|
public static final String PARAM_GROUP_ID = "gid";
|
||||||
|
|
||||||
public static final int ACTIVITY_EDIT_GROUP = 0;
|
public static final int ACTIVITY_EDIT_GROUP = 0;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
Log.d("SelectGroup", "***Create");
|
//Log.d("SelectGroup", "***Create");
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.group_list);
|
setContentView(R.layout.group_list);
|
||||||
mDbHelper = new GroupsDbAdapter(this);
|
mDbHelper = new GroupsDbAdapter(this);
|
||||||
@ -40,37 +35,36 @@ public class SelectGroupActivity extends ListActivity{
|
|||||||
fillData();
|
fillData();
|
||||||
registerForContextMenu(getListView());
|
registerForContextMenu(getListView());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
Log.d("SelectGroup", "***onStart");
|
//Log.d("SelectGroup", "***onStart");
|
||||||
mDbHelper.open();
|
mDbHelper.open();
|
||||||
super.onStart();
|
super.onStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
Log.d("SelectGroup", "***onStop");
|
//Log.d("SelectGroup", "***onStop");
|
||||||
mDbHelper.close();
|
mDbHelper.close();
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void fillData() {
|
public void fillData() {
|
||||||
Cursor groupsCursor = mDbHelper.fetchAllGroups();
|
Cursor groupsCursor = mDbHelper.fetchAllGroups();
|
||||||
startManagingCursor(groupsCursor);
|
startManagingCursor(groupsCursor);
|
||||||
|
|
||||||
String[] from = new String[]{GroupsDbAdapter.KEY_GROUP_NAME};
|
String[] from = new String[] { GroupsDbAdapter.KEY_GROUP_NAME };
|
||||||
|
|
||||||
int[] to = new int[]{R.id.groupNameTextView};
|
int[] to = new int[] { R.id.groupNameTextView };
|
||||||
|
|
||||||
SimpleCursorAdapter notes =
|
SimpleCursorAdapter notes = new SimpleCursorAdapter(this,
|
||||||
new SimpleCursorAdapter(this, R.layout.group_row, groupsCursor, from, to);
|
R.layout.group_row, groupsCursor, from, to);
|
||||||
setListAdapter(notes);
|
setListAdapter(notes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
menu.add(0, CREATE_ID,0, R.string.create_group);
|
menu.add(0, CREATE_ID, 0, R.string.create_group);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +89,7 @@ public class SelectGroupActivity extends ListActivity{
|
|||||||
phonesListCursor.moveToNext();
|
phonesListCursor.moveToNext();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
|
|
||||||
@ -104,17 +98,19 @@ public class SelectGroupActivity extends ListActivity{
|
|||||||
setResult(RESULT_OK, i);
|
setResult(RESULT_OK, i);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case DELETE_ID:
|
case DELETE_ID:
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
|
||||||
|
.getMenuInfo();
|
||||||
mDbHelper.deleteGroup(info.id);
|
mDbHelper.deleteGroup(info.id);
|
||||||
fillData();
|
fillData();
|
||||||
return true;
|
return true;
|
||||||
case EDIT_ID:
|
case EDIT_ID:
|
||||||
AdapterContextMenuInfo infoEdit = (AdapterContextMenuInfo) item.getMenuInfo();
|
AdapterContextMenuInfo infoEdit = (AdapterContextMenuInfo) item
|
||||||
|
.getMenuInfo();
|
||||||
editGroup(infoEdit.id);
|
editGroup(infoEdit.id);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -123,11 +119,11 @@ public class SelectGroupActivity extends ListActivity{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
public boolean onMenuItemSelected(int featureId, MenuItem item) {
|
||||||
switch(item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case CREATE_ID:
|
case CREATE_ID:
|
||||||
editGroup(null);
|
editGroup(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onMenuItemSelected(featureId, item);
|
return super.onMenuItemSelected(featureId, item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user