First test for delivery messages

This commit is contained in:
Mathieu Maret 2010-01-22 15:21:33 +01:00
parent 630b48b63e
commit 8fb3252915
19 changed files with 670 additions and 83 deletions

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.openwide.android" android:versionCode="2"
android:versionName="1.0.1">
package="com.openwide.android" android:versionCode="4"
android:versionName="1.0.2">
<application android:label="@string/app_name" android:icon="@drawable/multisms">
<activity android:name=".MultiSmsSender" android:label="@string/app_name">
<intent-filter>
@ -12,10 +12,13 @@
<activity android:name=".PhoneNumberSelection"></activity>
<activity android:name="SelectGroupActivity"></activity>
<activity android:name="GroupEditActivity"></activity>
</application>
<activity android:name="SelectDeliveryActivity"></activity>
<activity android:name="ListEntryActivity"></activity>
</application>
<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4"/>
<supports-screens android:smallScreens="true"
android:anyDensity="true" />
<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:choiceMode="singleChoice" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="@string/nodelivery" />
</LinearLayout>

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:id="@+id/deliveryEntry">
<TextView android:id="@+id/date" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@+id/name" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

12
res/layout/entry_list.xml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:choiceMode="singleChoice" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:text="@string/nodelivery" />
</LinearLayout>

14
res/layout/entry_row.xml Normal file
View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:id="@+id/deliveryEntry">
<TextView android:id="@+id/delivered" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical">
<TextView android:id="@+id/name" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView android:id="@+id/number" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>

View File

@ -2,7 +2,7 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="vertical">
<ListView android:id="@+id/android:list" android:layout_width="wrap_content"
<ListView android:id="@+id/android:list" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:choiceMode="multipleChoice" />
<TextView android:id="@+id/android:empty"
android:layout_width="fill_parent" android:layout_height="wrap_content"

View File

@ -5,26 +5,30 @@
<LinearLayout android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:gravity="center_horizontal"
android:orientation="horizontal" android:layout_width="fill_parent">
<Button android:background="@drawable/ic_launcher_contacts"
android:id="@+id/contacts" android:layout_height="wrap_content"
android:layout_width="wrap_content"></Button>
<EditText android:id="@+id/numbers" android:layout_height="wrap_content"
android:layout_width="fill_parent" android:hint="@string/to"
android:maxLines="2" />
</LinearLayout>
<EditText android:id="@+id/editor" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:autoText="true"
android:capitalize="sentences" android:layout_weight="1"
android:hint="@string/entermessage">
<requestFocus />
</EditText>
<CheckBox android:text="@string/enabledelivery" android:id="@+id/deliveryCheckBox"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true"></CheckBox>
<Button android:text="@string/send" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:id="@+id/send">
</Button>
</LinearLayout>

View File

@ -11,8 +11,14 @@
<string name="wait">Please wait while sending...</string>
<string name="entermessage">Enter your message</string>
<string name="entergroupname">Enter Group Name</string>
<string name="nodelivery">No delivery reports available</string>
<string name="enabledelivery">Enable delivery reports</string>
<string name="to">To</string>
<string name="refresh">Refresh</string>
<string name="remove_all">Remove All</string>
<string name="remove">Remove</string>
<string name="add_group">Add from group</string>
<string name="delivery">Delivery reports</string>
<string name="create_group">Create a new group</string>
<string name="remove_group">Remove this group</string>
<string name="edit_group">Edit this group</string>

View File

@ -7,12 +7,17 @@
<string name="ok">Ok</string>
<string name="nocontacts">Pas de contacts!!</string>
<string name="nogroups">Pas de groupes!!</string>
<string name="sending">Envoie d'un message...</string>
<string name="wait">Veuillez patienter pendant l'envoie...</string>
<string name="sending">Envoie d\'un message...</string>
<string name="wait">Veuillez patienter pendant l\'envoie...</string>
<string name="entermessage">Saisissez votre message</string>
<string name="entergroupname">Nom du groupe</string>
<string name="to">À</string>
<string name="refresh">Rafraichir</string>
<string name="remove_all">Tout supprimer</string>
<string name="remove">Supprimer</string>
<string name="add_group">Ajouter un groupe</string>
<string name="delivery">Accusé de récéption</string>
<string name="enabledelivery">Accusé de récéption</string>
<string name="create_group">Créer un group</string>
<string name="remove_group">Supprimer ce groupe</string>
<string name="edit_group">Editer ce groupe</string>
@ -20,5 +25,5 @@
<string name="select_all">Selectionner tout</string>
<string name="deselect_all">DeSelectionner tout</string>
<string name="message_sent">Message(s) envoyé(s)</string>
<string name="enter_number">Entrez un numero ou utilisez l'icone de contact</string>
<string name="enter_number">Entrez un numero ou utilisez l\'icone de contact</string>
</resources>

View File

@ -1,6 +1,7 @@
package com.openwide.android;
import android.content.Context;
import android.view.View;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -27,6 +28,7 @@ public class ContactRow extends LinearLayout {
mSelectedCheckBox.setText("");
mSelectedCheckBox.setFocusable(false);
this.addView(mSelectedCheckBox, new LayoutParams(LayoutParams.WRAP_CONTENT,
@ -40,7 +42,14 @@ public class ContactRow extends LinearLayout {
this.addView(mInfoLayout, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.FILL_PARENT));
this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mSelectedCheckBox.performClick();
}
});
}
@ -55,7 +64,8 @@ public class ContactRow extends LinearLayout {
public void display(String name, String number, boolean isSelected, long id) {
display( name, number, isSelected);
mId = id;
}
}

View File

@ -0,0 +1,234 @@
package com.openwide.android;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DeliveryDbAdapter {
public static final String KEY_DELIVERY_ENTRY_ROWID = "_id";
public static final String KEY_DELIVERY_ENTRY_NAME = "name";
public static final String KEY_DELIVERY_ENTRY_NUMBER = "number";
public static final String KEY_DELIVERY_ENTRY_DELIVERED = "delivered";
public static final String KEY_DELIVERY_ENTRY_DELIVERY_ID = "delivery_id";
public static final String KEY_DELIVERY_ROWID = "_id";
public static final String KEY_DELIVERY_NAME = "name";
public static final String KEY_DELIVERY_DATE = "date";
private static final String TAG = "deliveryDbAdapter";
private DeliveryDbHelper mDbHelper;
private SQLiteDatabase mDb;
/**
* Database creation sql statement
*/
private static final String DATABASE_NAME = "data";
private static final String DATABASE_DELIVERY_ENTRY_TABLE = "delivery_entry";
private static final String DATABASE_DELIVERY_TABLE = "delivery";
private static final String DATABASE_DELIVERY_ENTRY_CREATE = "create table "
+ DATABASE_DELIVERY_ENTRY_TABLE
+ " ("+KEY_DELIVERY_ENTRY_ROWID+" integer primary key autoincrement, "
+ KEY_DELIVERY_ENTRY_NAME + " text not null,"
+ KEY_DELIVERY_ENTRY_NUMBER + " text not null,"
+ KEY_DELIVERY_ENTRY_DELIVERED + " integer,"
+ KEY_DELIVERY_ENTRY_DELIVERY_ID + " integer);";
private static final String DATABASE_DELIVERY_CREATE = "create table "
+ DATABASE_DELIVERY_TABLE
+ " (" + KEY_DELIVERY_ROWID + " integer primary key autoincrement, "
+ KEY_DELIVERY_NAME + " text not null,"
+ KEY_DELIVERY_DATE + " text not null);";
private static final int DATABASE_VERSION = 2;
private final Context mCtx;
private static class DeliveryDbHelper extends SQLiteOpenHelper {
DeliveryDbHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(DATABASE_DELIVERY_ENTRY_CREATE);
db.execSQL(DATABASE_DELIVERY_CREATE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
+ newVersion + ", which will destroy all old data");
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_DELIVERY_ENTRY_TABLE);
db.execSQL("DROP TABLE IF EXISTS " + DATABASE_DELIVERY_TABLE);
onCreate(db);
}
}
/**
* Constructor - takes the context to allow the database to be
* opened/created
*
* @param ctx
* the Context within which to work
*/
public DeliveryDbAdapter(Context ctx) {
this.mCtx = ctx;
}
/**
* 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 DeliveryDbAdapter open() throws SQLException {
mDbHelper = new DeliveryDbHelper(mCtx);
mDb = mDbHelper.getWritableDatabase();
return this;
}
public void close() {
mDbHelper.close();
}
// ********************************* ENTRY FUNCTION ***********************
/**
* Create a new entry using the name provided. If the entry is
* successfully created return the new rowId for that entry, otherwise return
* a -1 to indicate failure.
*
* @param name the name of the entry
* @param date the date of the entry
* @param deliveryID the deliveryID of the entry
*/
public long createEntry(String name, String number, long deliveryID) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DELIVERY_ENTRY_NAME, name);
initialValues.put(KEY_DELIVERY_ENTRY_NUMBER, number);
initialValues.put(KEY_DELIVERY_ENTRY_DELIVERY_ID, deliveryID);
initialValues.put(KEY_DELIVERY_ENTRY_DELIVERED, 0);
return mDb.insert(DATABASE_DELIVERY_ENTRY_TABLE, null, initialValues);
}
/**
* Delete the entry with the given rowId
*
* @param rowId id of entry to delete
* @return true if deleted, false otherwise
*/
public boolean deleteEntry(long rowId) {
return mDb.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_DELIVERY_ENTRY_ROWID + "=" + rowId, null) > 0 ;
}
/**
* Delete all the entries where the delivery_id is the given deliveryId
*
* @param deliveryId id of the delivery
* @return true if deleted, false otherwise
*/
public boolean deleteAllEntry(long deliveryId) {
return mDb.delete(DATABASE_DELIVERY_ENTRY_TABLE, KEY_DELIVERY_ENTRY_DELIVERY_ID + "=" + deliveryId, null) > 0 ;
}
/**
* Return a Cursor over the list of all entry in the database associated with the given delivery_id
*
* @param deliveryId id of the entry
* @return Cursor over all entries
*/
public Cursor fetchAllEntry(long deliveryId) {
return mDb.query(DATABASE_DELIVERY_ENTRY_TABLE, new String[] {KEY_DELIVERY_ENTRY_ROWID, KEY_DELIVERY_ENTRY_NAME, KEY_DELIVERY_ENTRY_NUMBER, KEY_DELIVERY_ENTRY_DELIVERED}, KEY_DELIVERY_ENTRY_DELIVERY_ID + "=" + deliveryId, null, null, null , KEY_DELIVERY_ENTRY_NAME);
}
/**
* Return a Cursor over the list of all entry in the database associated with the given delivery_id
*
* @param mDeliveryId id of the entry
* @return Cursor over all entries
*/
public Cursor fetchEntry(long entryId) {
Cursor cursor =
mDb.query(true, DATABASE_DELIVERY_ENTRY_TABLE, new String[] {KEY_DELIVERY_ENTRY_ROWID, KEY_DELIVERY_ENTRY_NAME, KEY_DELIVERY_ENTRY_NUMBER, KEY_DELIVERY_ENTRY_DELIVERED}, KEY_DELIVERY_ENTRY_DELIVERY_ID + "=" + entryId, null,
null, null, null, null);
if (cursor != null) {
cursor.moveToFirst();
}
return cursor;
}
public boolean setEntryDelivered(long entryId) {
ContentValues content = new ContentValues(1);
content.put(KEY_DELIVERY_ENTRY_DELIVERED, 1);
return mDb.update(DATABASE_DELIVERY_ENTRY_TABLE, content, KEY_DELIVERY_ENTRY_DELIVERY_ID +"="+entryId , null) > 0;
}
// ************************* DELIVERY *************************************
/**
* Create a new delivery using the name provided. If the delivery is
* successfully created return the new rowId for that delivery, otherwise return
* a -1 to indicate failure.
*
* @param name the name of the delivery
* @param date the date of the delivery
*/
public long createDelivery(String name, String date) {
ContentValues initialValues = new ContentValues();
initialValues.put(KEY_DELIVERY_NAME, name);
initialValues.put(KEY_DELIVERY_DATE, date);
return mDb.insert(DATABASE_DELIVERY_TABLE, null, initialValues);
}
/**
* Delete the delivery with the given rowId and all entry associated
*
* @param rowId id of entry to delete
* @return true if deleted, false otherwise
*/
public boolean deleteDelivery(long rowId) {
return mDb.delete(DATABASE_DELIVERY_TABLE, KEY_DELIVERY_ROWID + "=" + rowId, null) > 0 && deleteAllEntry(rowId) ;
}
/**
* Return a Cursor over the list of all deliveries in the database
*
* @param mDeliveryId id of the delivery
* @return Cursor over all delivery
*/
public Cursor fetchAllDeliveries() {
return mDb.query(DATABASE_DELIVERY_TABLE, new String[] {KEY_DELIVERY_ROWID, KEY_DELIVERY_NAME, KEY_DELIVERY_DATE}, null, null, null, null , KEY_DELIVERY_DATE);
}
}

View File

@ -78,6 +78,11 @@ public class GroupEditActivity extends ListActivity {
});
}
protected void onDestroy() {
mDb.close();
super.onDestroy();
}
private void createGroup() {
if (mGid == null) {
String name = mGroupNameText.getText().toString();

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008 Google Inc.
* Copyright (C) 2008 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
@ -27,13 +27,9 @@ import android.util.Log;
/**
* Simple groups database access helper class. Defines the basic CRUD operations
* for the grouppad 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 as
* retrieve or modify a specific group.
*
* This has been improved from the first version of this tutorial through the
* addition of better error handling and also using returning a Cursor instead
* of using a collection of inner classes (which is less scalable and not
* recommended).
*/
public class GroupsDbAdapter {

View File

@ -0,0 +1,52 @@
package com.openwide.android;
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.widget.SimpleCursorAdapter;
public class ListEntryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
Long mDeliveryId;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.entry_list);
Bundle extras = getIntent().getExtras();
mDeliveryId = extras != null ? extras.getLong(SelectDeliveryActivity.PARAM_DELIVERY_ID): null;
mDbHelper = new DeliveryDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
public void fillData() {
Cursor deliveryCursor = mDbHelper.fetchAllEntry(mDeliveryId);
startManagingCursor(deliveryCursor);
String[] from = new String[]{DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NAME, DeliveryDbAdapter.KEY_DELIVERY_ENTRY_NUMBER, DeliveryDbAdapter.KEY_DELIVERY_ENTRY_DELIVERED };
int[] to = new int[]{R.id.name, R.id.number, R.id.delivered};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.entry_row, deliveryCursor, from, to);
setListAdapter(notes);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
}
@Override
protected void onDestroy() {
mDbHelper.close();
super.onDestroy();
}
}

View File

@ -0,0 +1,29 @@
package com.openwide.android;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
public class MessageReceiver extends BroadcastReceiver{
public static final String MESSAGE_RECEIVED = "com.openwide.android.mutliSmsSend.message_received";
@Override
public void onReceive(Context context, Intent intent) {
if (MESSAGE_RECEIVED.equals(intent.getAction())) {
Long entryId;
Bundle extras = intent.getExtras();
entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null;
DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(context);
mDbHelper.open();
mDbHelper.setEntryDelivered(entryId);
mDbHelper.close();
}
}
}

View File

@ -1,11 +1,16 @@
package com.openwide.android;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
@ -17,6 +22,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;
public class MultiSmsSender extends Activity {
@ -24,25 +30,34 @@ public class MultiSmsSender extends Activity {
private Button mSend;
private TextView mContacts;
private TextView mEditor;
private CheckBox mDeliveryCheckBox;
private DeliveryDbAdapter mDbHelper;
private ProgressDialog mSendingDialog;
public static final int ACTIVITY_EDIT = 0;
public static final int ACTIVITY_ADD_GROUP = 1;
public static final int ACTIVITY_DELIVERY = 2;
private static final int SENDING_DIALOG_KEY = 0;
private static final int INSERT_ID = Menu.FIRST;
public static final String PARAM_NUMBERS_LIST = "param number list";
public static final String PARAM_FLUSH = "param flush";
public static final String PARAM_ENTRY_ID = "entry_id";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mDbHelper = new DeliveryDbAdapter(this);
mDbHelper.open();
mAddButton = (Button) findViewById(R.id.contacts);
mSend = (Button) findViewById(R.id.send);
mContacts = (TextView) findViewById(R.id.numbers);
mEditor = (TextView) findViewById(R.id.editor);
mDeliveryCheckBox = (CheckBox) findViewById(R.id.deliveryCheckBox);
mContacts.setImeOptions(EditorInfo.IME_ACTION_NEXT);
mEditor.setImeOptions(EditorInfo.IME_ACTION_DONE);
@ -79,41 +94,82 @@ public class MultiSmsSender extends Activity {
String[] numbers = mContacts.getText().toString().split(",");
HashSet<String> allreadySend = new HashSet<String>();
int size = numbers.length;
showDialog(SENDING_DIALOG_KEY);
if(numbers.length != 0) {
boolean haveDeliveryReports = mDeliveryCheckBox.isChecked();
long deliveryId = -1;
ArrayList<String> messages = manager.divideMessage(message);
int messageCount = messages.size();
//showDialog(SENDING_DIALOG_KEY);
mSendingDialog = new ProgressDialog(this);
mSendingDialog.setTitle(R.string.sending);
mSendingDialog.setMessage(getResources().getString(R.string.wait));
mSendingDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mSendingDialog.setIndeterminate(true);
mSendingDialog.setCancelable(false);
mSendingDialog.setMax(size);
mSendingDialog.show();
if (haveDeliveryReports) {
deliveryId = mDbHelper.createDelivery(message.substring(0, Math.min(30, message
.length())).replace('\n', ' '), DateFormat.getDateInstance()
.format(new Date()));
}
if (numbers.length != 0) {
for (int i = 0; i < numbers.length; i++) {
String newN = numbers[i].trim();
mSendingDialog.setMax(size);
if (!newN.equals("") && PhoneNumberUtils.isWellFormedSmsAddress(newN)) {
if (!newN.equals("")
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)) {
mSendingDialog.setProgress(i / size);
if (!allreadySend.contains(newN)) {
allreadySend.add(newN);
manager.sendMultipartTextMessage(newN, null, manager.divideMessage(message), null, null);
ArrayList<PendingIntent> sentIntents = null;
if (haveDeliveryReports) {
sentIntents = new ArrayList<PendingIntent>(messageCount);
long entryId = mDbHelper.createEntry("", newN, deliveryId);
for (int j = 0; j < messageCount; j++) {
Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED, null, this, MessageReceiver.class);
intent.putExtra(PARAM_ENTRY_ID, entryId);
sentIntents.add(PendingIntent.getBroadcast(
this, 0, intent , 0));
}
}
manager.sendMultipartTextMessage(newN, null, messages, null, sentIntents);
}
}
}
mSendingDialog.dismiss();
new AlertDialog.Builder(this).setPositiveButton(getResources().getString(R.string.ok),
new AlertDialog.Builder(this).setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setMessage(allreadySend.size()+" "+ getResources().getString(R.string.message_sent)).show();
}else {
new AlertDialog.Builder(this).setPositiveButton(getResources().getString(R.string.ok),
}
}).setMessage(
allreadySend.size() + " "
+ getResources().getString(R.string.message_sent))
.show();
} else {
new AlertDialog.Builder(this).setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setMessage(getResources().getString(R.string.enter_number)).show();
}
}).setMessage(
getResources().getString(R.string.enter_number)).show();
}
}
@ -125,8 +181,10 @@ public class MultiSmsSender extends Activity {
mSendingDialog = new ProgressDialog(this);
mSendingDialog.setTitle(R.string.sending);
mSendingDialog.setMessage(getResources().getString(R.string.wait));
mSendingDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mSendingDialog.setIndeterminate(true);
mSendingDialog.setCancelable(true);
mSendingDialog.setCancelable(false);
return mSendingDialog;
}
}
@ -137,55 +195,84 @@ public class MultiSmsSender extends Activity {
protected void onActivityResult(int requestCode, int resultCode,
Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
if (intent != null) {
String[] numbers = intent.getExtras().getStringArray(
PARAM_NUMBERS_LIST);
String string = "";
HashSet<String> res = new HashSet<String>();
for (int i = 0; i < numbers.length; i++) {
String newN = numbers[i].trim();
if (!newN.equals("")) {
res.add(newN);
switch (requestCode) {
case ACTIVITY_ADD_GROUP:
case ACTIVITY_EDIT:
if (intent != null) {
String[] numbers = intent.getExtras().getStringArray(
PARAM_NUMBERS_LIST);
boolean flush = intent.getExtras().getBoolean(PARAM_FLUSH);
String string = "";
HashSet<String> res = new HashSet<String>();
for (int i = 0; i < numbers.length; i++) {
String newN = numbers[i].trim();
if (!newN.equals("")) {
res.add(newN);
}
}
}
String oldContactsString = mContacts.getText().toString();
String[] oldContacts = oldContactsString.split(",");
for (int i = 0; i < oldContacts.length; i++) {
String newN = oldContacts[i].trim();
if (!newN.equals("")) {
res.add(newN);
if (!flush) {
String oldContactsString = mContacts.getText().toString();
String[] oldContacts = oldContactsString.split(",");
for (int i = 0; i < oldContacts.length; i++) {
String newN = oldContacts[i].trim();
if (!newN.equals("")) {
res.add(newN);
}
}
}
}
for (String number : res) {
string += number + ", ";
}
for (String number : res) {
string += number + ", ";
}
mContacts.setText(string);
mContacts.setText(string);
}
break;
default:
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, INSERT_ID,0, R.string.add_group);
menu.add(0, INSERT_ID, 0, R.string.add_group);
menu.add(0, INSERT_ID + 1, 0, R.string.delivery);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
switch (item.getItemId()) {
case INSERT_ID:
display_group_list();
return true;
}
case INSERT_ID + 1:
display_delivery_list();
return true;
}
return super.onMenuItemSelected(featureId, item);
}
protected void onDestroy() {
mDbHelper.close();
super.onDestroy();
}
public void display_group_list(){
public void display_group_list() {
Intent i = new Intent(this, SelectGroupActivity.class);
startActivityForResult(i, ACTIVITY_ADD_GROUP);
}
public void display_delivery_list() {
Intent i = new Intent(this, SelectDeliveryActivity.class);
startActivityForResult(i, ACTIVITY_DELIVERY);
}
}

View File

@ -15,14 +15,13 @@ import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
public class PhoneNumberSelection extends ListActivity
{
PhoneDataListAdapter mAdpater;
String[] mSelected;
HashSet<String> mSelectedSet;
private static final int INSERT_ID = Menu.FIRST;
private static final int SELECT_ALL_ID = Menu.FIRST + 1;
@ -34,17 +33,17 @@ public class PhoneNumberSelection extends ListActivity
setContentView(R.layout.number_list);
String[] selected;
selected = savedInstanceState != null ? savedInstanceState.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
mSelected = savedInstanceState != null ? savedInstanceState.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
if (mSelected == null) {
if (selected == null) {
Bundle extras = getIntent().getExtras();
mSelected = extras != null ? extras.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
selected = extras != null ? extras.getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST ) : null;
}
mSelectedSet = new HashSet<String>();
for (int i = 0; i < mSelected.length; i++) {
mSelectedSet.add(mSelected[i].trim());
for (int i = 0; i < selected.length; i++) {
mSelectedSet.add(selected[i].trim());
}
fillData();
@ -54,14 +53,16 @@ public class PhoneNumberSelection extends ListActivity
@Override
public void onClick(View v) {
Intent i = new Intent();
String [] numbers = new String[mAdpater.selected.size()];
mAdpater.selected.toArray(numbers);
String [] numbers = new String[mSelectedSet.size()];
mSelectedSet.toArray(numbers);
Bundle bundle = new Bundle();
bundle.putStringArray(MultiSmsSender.PARAM_NUMBERS_LIST, numbers);
bundle.putBoolean(MultiSmsSender.PARAM_FLUSH, true);
i.putExtras(bundle);
setResult(RESULT_OK, i);
finish();
}
});
@ -118,11 +119,11 @@ public class PhoneNumberSelection extends ListActivity
startActivityForResult(i, MultiSmsSender.ACTIVITY_ADD_GROUP);
}
@Override
/*@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
l.getItemAtPosition(position);
}
}*/
/*@Override
protected void onSaveInstanceState(Bundle outState) {
@ -137,7 +138,6 @@ public class PhoneNumberSelection extends ListActivity
public class PhoneDataListAdapter extends SimpleCursorAdapter{
public HashSet<String> selected;
int nameidx;
int numberidx;
Context mContext;
@ -148,7 +148,7 @@ public class PhoneNumberSelection extends ListActivity
nameidx = c.getColumnIndex(Phones.NAME);
numberidx = c.getColumnIndex(Phones.NUMBER);
mContext = context;
this.selected = selected;
}
@ -163,7 +163,7 @@ public class PhoneNumberSelection extends ListActivity
}else {
contact = (ContactRow) convertView;
}
contact.display(name, number, selected.contains(number));
contact.display(name, number, mSelectedSet.contains(number));
contact.mSelectedCheckBox.setOnClickListener(new addNumberToSelectedClickListener(contact));
return contact;
@ -196,12 +196,10 @@ public class PhoneNumberSelection extends ListActivity
if(intent != null) {
String [] numbers = intent.getExtras().getStringArray(MultiSmsSender.PARAM_NUMBERS_LIST);
HashSet<String> mSelectedGlobal = new HashSet<String>();
for (int i = 0; i < numbers.length; i++) {
mSelectedSet.add(numbers[i]);
}
mSelected = new String[mSelectedSet.size()];
mSelectedGlobal.toArray(mSelected);
fillData();
}
}

View File

@ -0,0 +1,103 @@
package com.openwide.android;
import android.app.ListActivity;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class SelectDeliveryActivity extends ListActivity {
DeliveryDbAdapter mDbHelper;
public static final int DELETE_ID = Menu.FIRST;
public static final int DELETE_ALL_ID = Menu.FIRST + 1;
public static final int REFRESH_ID = Menu.FIRST + 2;
public static final String PARAM_DELIVERY_ID = "param_delivery_id";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.delivery_list);
mDbHelper = new DeliveryDbAdapter(this);
mDbHelper.open();
fillData();
registerForContextMenu(getListView());
}
protected void onDestroy() {
mDbHelper.close();
super.onDestroy();
}
public void fillData() {
Cursor deliveryCursor = mDbHelper.fetchAllDeliveries();
startManagingCursor(deliveryCursor);
String[] from = new String[]{DeliveryDbAdapter.KEY_DELIVERY_DATE, DeliveryDbAdapter.KEY_DELIVERY_NAME };
int[] to = new int[]{R.id.date, R.id.name};
SimpleCursorAdapter notes =
new SimpleCursorAdapter(this, R.layout.delivery_row, deliveryCursor, from, to);
setListAdapter(notes);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add(0, DELETE_ALL_ID,0, R.string.remove_all);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
menu.add(0, DELETE_ID, 0, R.string.remove);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case DELETE_ID:
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
mDbHelper.deleteDelivery(info.id);
fillData();
return true;
}
return super.onContextItemSelected(item);
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch(item.getItemId()) {
case DELETE_ALL_ID:
//TODO
return true;
}
return super.onMenuItemSelected(featureId, item);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
Intent i = new Intent(this, ListEntryActivity.class);
i.putExtra(PARAM_DELIVERY_ID, id);
startActivity(i);
super.onListItemClick(l, v, position, id);
}
}

View File

@ -37,6 +37,12 @@ public class SelectGroupActivity extends ListActivity{
fillData();
registerForContextMenu(getListView());
}
protected void onDestroy() {
mDbHelper.close();
super.onDestroy();
}