UI improvement when lots of messages are sent

And the langage associated
This commit is contained in:
Mathieu Maret 2010-12-12 02:28:33 +01:00
parent b4600cd8ec
commit d601eb348d
3 changed files with 159 additions and 52 deletions

View File

@ -5,6 +5,7 @@
<string name="add">Ajouter</string>
<string name="contacts">Contacts</string>
<string name="ok">Ok</string>
<string name="cancel">Annuler</string>
<string name="nocontacts">Pas de contacts!!</string>
<string name="nogroups">Pas de groupes!!</string>
<string name="sending">Envoie d\'un message...</string>
@ -27,4 +28,5 @@
<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="warning_many_message">Vous etes sur le point d'envoyer plus de 50 messages d'un coup. Comme cela peut produire une erreur android qui ferait planter l'application, les messages vont etre envoyés par paquet de 50 avec une pause entre chaque paquet. Voulez vous continuer ?'</string>
</resources>

View File

@ -5,6 +5,7 @@
<string name="add">Add</string>
<string name="contacts">Contacts</string>
<string name="ok">Ok</string>
<string name="cancel">Cancel</string>
<string name="nocontacts">No Contacts!!</string>
<string name="nogroups">No Groups!!</string>
<string name="sending">Sending message...</string>
@ -27,4 +28,5 @@
<string name="deselect_all">Deselect all</string>
<string name="message_sent">Message(s) sent</string>
<string name="enter_number">Enter a phone number or use the contact icon</string>
<string name="warning_many_message">You are about to sent more than 50 Messages. As it may produce an Android error that may crash the application, they will be send by chunk of 50 with a pause between each chunk. Do you want to continue ?</string>
</resources>

View File

@ -44,9 +44,14 @@ public class MultiSmsSender extends Activity {
private static final int SENDING_DIALOG_KEY = 0;
private static final int INSERT_ID = Menu.FIRST;
public static final int MANY_MESSAGE = 50;
private static final int DIALOG_PROGRESS = 0;
private static final int DIALOG_FINISHED = 1;
private static final int DIALOG_NONUMBER = 2;
private static final int DIALOG_MANYMESSAGE = 3;
private static final int DIALOG_STARTWAIT = 4;
private static final int DIALOG_PROGRESS_CANCEL = 5;
public static final String PARAM_NUMBERS_LIST = "param number list";
public static final String PARAM_FLUSH = "param flush";
@ -54,6 +59,9 @@ public class MultiSmsSender extends Activity {
public static final String DEBUG_TAG="MultiSmsSender";
MessageSenderThread mThreadSender;
private boolean mManyMessageContinue;
final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
int type = msg.getData().getInt("ORIGIN");
@ -64,6 +72,10 @@ public class MultiSmsSender extends Activity {
mSendingDialog.setProgress(total);
}
break;
case DIALOG_PROGRESS_CANCEL:{
mSendingDialog.cancel();
}
break;
case DIALOG_FINISHED:{
dismissDialog(SENDING_DIALOG_KEY);
@ -82,7 +94,7 @@ public class MultiSmsSender extends Activity {
.show();
break;
}
case DIALOG_NONUMBER:{
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
getResources().getString(R.string.ok),
@ -94,6 +106,49 @@ public class MultiSmsSender extends Activity {
}
}).setMessage(
getResources().getString(R.string.enter_number)).show();
break;
}
case DIALOG_MANYMESSAGE:{
new AlertDialog.Builder(MultiSmsSender.this)
.setMessage("You are about to sent more than 50 Messages. As it may produce Android error that may crash the app, they will be send by chunk of 50 with a pause between each chunk")
.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;
}
case DIALOG_STARTWAIT:{
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
getResources().getString(R.string.ok),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
synchronized (MultiSmsSender.this) {
MultiSmsSender.this.notify();
}
dialog.dismiss();
}
}).setMessage("You are ready to continue for 50 more messages?").show();
break;
}
}
@ -128,8 +183,8 @@ public class MultiSmsSender extends Activity {
public void onClick(View v) {
showDialog(SENDING_DIALOG_KEY);
MessageSenderThread sender = new MessageSenderThread(mHandler);
sender.start();
mThreadSender = new MessageSenderThread(mHandler);
mThreadSender.start();
//sendMessage();
}
@ -154,16 +209,25 @@ public class MultiSmsSender extends Activity {
public MessageSenderThread( Handler h) {
mHandler = h;
}
public void run() {
public synchronized void run() {
super.run();
sendMessage(mHandler);
}
}
public void sendMessage(Handler handler) {
public void sendMessage(Handler handler) {
MySMSManager manager = new MySMSManager();
String message = mEditor.getText().toString();
mManyMessageContinue = false;
if("".equals(message)) {
{
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", DIALOG_PROGRESS_CANCEL);
msg.setData(b);
handler.sendMessage(msg);
}
return;
}
@ -175,15 +239,6 @@ public class MultiSmsSender extends Activity {
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
@ -191,50 +246,95 @@ public class MultiSmsSender extends Activity {
.format(new Date()));
}
if (numbers.length != 0) {
for (int i = 0; i < numbers.length; i++) {
String newN = numbers[i].trim();
if (!newN.equals("")
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)) {
if (size != 0) {
if(size > MANY_MESSAGE){
{
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", DIALOG_PROGRESS);
b.putInt("total", (i*100)/size);
b.putInt("ORIGIN", DIALOG_MANYMESSAGE);
msg.setData(b);
handler.sendMessage(msg);
//mSendingDialog.setProgress( i/ size);
if (!allreadySend.contains(newN)) {
allreadySend.add(newN);
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>(messageCount);
ArrayList<PendingIntent> sentIntents = null;
if (haveDeliveryReports) {
ContentValues values = new ContentValues();
values.put("address", newN);
values.put("body", message);
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId);
Log.d(DEBUG_TAG, "entry is "+entryId);
for (int j = 0; j < messageCount; j++) {
Uri entryURI = Uri.withAppendedPath(EntryContentProvider.CONTENT_URI, ""+entryId);
Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED,entryURI, this, MessageReceiver.class);
//intent.putExtra(PARAM_ENTRY_ID, entryId);
deliveryIntents.add(PendingIntent.getBroadcast(
this, 0, intent, 0));
}
}
manager.sendMultipartTextMessage(newN, null, messages, sentIntents, deliveryIntents );
}
synchronized (MultiSmsSender.this) {
try {
MultiSmsSender.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
if(mManyMessageContinue) {
int message_sent = 0;
int chunk_max = Math.min(MANY_MESSAGE, size);
do {
if(message_sent > 0) {
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", DIALOG_STARTWAIT);
msg.setData(b);
handler.sendMessage(msg);
synchronized (MultiSmsSender.this) {
try {
MultiSmsSender.this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Log.d(DEBUG_TAG, "size is"+size+" message_sent "+message_sent+" max"+chunk_max);
for(int i = message_sent; i < chunk_max; i++) {
message_sent ++;
String newN = numbers[i].trim();
if (!newN.equals("")
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)) {
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
b.putInt("ORIGIN", DIALOG_PROGRESS);
b.putInt("total", (i*100)/size);
msg.setData(b);
handler.sendMessage(msg);
if (!allreadySend.contains(newN)) {
allreadySend.add(newN);
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>(messageCount);
ArrayList<PendingIntent> sentIntents = null;
if (haveDeliveryReports) {
ContentValues values = new ContentValues();
values.put("address", newN);
values.put("body", message);
getContentResolver().insert(Uri.parse("content://sms/sent"), values);
long entryId = mDbHelper.createEntry(mDbHelper.nameFromNumber(newN), newN, deliveryId);
Log.d(DEBUG_TAG, "entry is "+entryId+" to number"+newN);
for (int j = 0; j < messageCount; j++) {
Uri entryURI = Uri.withAppendedPath(EntryContentProvider.CONTENT_URI, ""+entryId);
Intent intent = new Intent(MessageReceiver.MESSAGE_RECEIVED,entryURI, this, MessageReceiver.class);
//intent.putExtra(PARAM_ENTRY_ID, entryId);
deliveryIntents.add(PendingIntent.getBroadcast(
this, 0, intent, 0));
}
}
manager.sendMultipartTextMessage(newN, null, messages, sentIntents, deliveryIntents );
}
}
}
chunk_max = Math.min(message_sent +MANY_MESSAGE, size);
} while ( (size - message_sent) >0);
}
Message msg = handler.obtainMessage();
Bundle b = new Bundle();
@ -243,6 +343,9 @@ public class MultiSmsSender extends Activity {
msg.setData(b);
handler.sendMessage(msg);
} else {
Message msg = handler.obtainMessage();
Bundle b = new Bundle();