diff --git a/res/values-fr/strings.xml b/res/values-fr/strings.xml
index c725333..73d7d54 100644
--- a/res/values-fr/strings.xml
+++ b/res/values-fr/strings.xml
@@ -5,6 +5,7 @@
Ajouter
Contacts
Ok
+ Annuler
Pas de contacts!!
Pas de groupes!!
Envoie d\'un message...
@@ -27,4 +28,5 @@
DeSelectionner tout
Message(s) envoyé(s)
Entrez un numero ou utilisez l\'icone de contact
+ 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 ?'
diff --git a/res/values/strings.xml b/res/values/strings.xml
index deb6d5e..3fbacf7 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -5,6 +5,7 @@
Add
Contacts
Ok
+ Cancel
No Contacts!!
No Groups!!
Sending message...
@@ -27,4 +28,5 @@
Deselect all
Message(s) sent
Enter a phone number or use the contact icon
+ 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 ?
diff --git a/src/com/openwide/android/MultiSmsSender.java b/src/com/openwide/android/MultiSmsSender.java
index 112f132..b600b9b 100644
--- a/src/com/openwide/android/MultiSmsSender.java
+++ b/src/com/openwide/android/MultiSmsSender.java
@@ -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 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 deliveryIntents = new ArrayList(messageCount);
- ArrayList 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 deliveryIntents = new ArrayList(messageCount);
+ ArrayList 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();