UI improvement when lots of messages are sent
And the langage associated
This commit is contained in:
parent
b4600cd8ec
commit
d601eb348d
@ -5,6 +5,7 @@
|
|||||||
<string name="add">Ajouter</string>
|
<string name="add">Ajouter</string>
|
||||||
<string name="contacts">Contacts</string>
|
<string name="contacts">Contacts</string>
|
||||||
<string name="ok">Ok</string>
|
<string name="ok">Ok</string>
|
||||||
|
<string name="cancel">Annuler</string>
|
||||||
<string name="nocontacts">Pas de contacts!!</string>
|
<string name="nocontacts">Pas de contacts!!</string>
|
||||||
<string name="nogroups">Pas de groupes!!</string>
|
<string name="nogroups">Pas de groupes!!</string>
|
||||||
<string name="sending">Envoie d\'un message...</string>
|
<string name="sending">Envoie d\'un message...</string>
|
||||||
@ -27,4 +28,5 @@
|
|||||||
<string name="deselect_all">DeSelectionner tout</string>
|
<string name="deselect_all">DeSelectionner tout</string>
|
||||||
<string name="message_sent">Message(s) envoyé(s)</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>
|
||||||
|
<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>
|
</resources>
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<string name="add">Add</string>
|
<string name="add">Add</string>
|
||||||
<string name="contacts">Contacts</string>
|
<string name="contacts">Contacts</string>
|
||||||
<string name="ok">Ok</string>
|
<string name="ok">Ok</string>
|
||||||
|
<string name="cancel">Cancel</string>
|
||||||
<string name="nocontacts">No Contacts!!</string>
|
<string name="nocontacts">No Contacts!!</string>
|
||||||
<string name="nogroups">No Groups!!</string>
|
<string name="nogroups">No Groups!!</string>
|
||||||
<string name="sending">Sending message...</string>
|
<string name="sending">Sending message...</string>
|
||||||
@ -27,4 +28,5 @@
|
|||||||
<string name="deselect_all">Deselect all</string>
|
<string name="deselect_all">Deselect all</string>
|
||||||
<string name="message_sent">Message(s) sent</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="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>
|
</resources>
|
||||||
|
@ -44,9 +44,14 @@ public class MultiSmsSender extends Activity {
|
|||||||
private static final int SENDING_DIALOG_KEY = 0;
|
private static final int SENDING_DIALOG_KEY = 0;
|
||||||
private static final int INSERT_ID = Menu.FIRST;
|
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_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_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_NUMBERS_LIST = "param number list";
|
||||||
public static final String PARAM_FLUSH = "param flush";
|
public static final String PARAM_FLUSH = "param flush";
|
||||||
@ -54,6 +59,9 @@ public class MultiSmsSender extends Activity {
|
|||||||
|
|
||||||
public static final String DEBUG_TAG="MultiSmsSender";
|
public static final String DEBUG_TAG="MultiSmsSender";
|
||||||
|
|
||||||
|
MessageSenderThread mThreadSender;
|
||||||
|
private boolean mManyMessageContinue;
|
||||||
|
|
||||||
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");
|
||||||
@ -64,6 +72,10 @@ public class MultiSmsSender extends Activity {
|
|||||||
mSendingDialog.setProgress(total);
|
mSendingDialog.setProgress(total);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case DIALOG_PROGRESS_CANCEL:{
|
||||||
|
mSendingDialog.cancel();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case DIALOG_FINISHED:{
|
case DIALOG_FINISHED:{
|
||||||
dismissDialog(SENDING_DIALOG_KEY);
|
dismissDialog(SENDING_DIALOG_KEY);
|
||||||
@ -82,7 +94,7 @@ public class MultiSmsSender extends Activity {
|
|||||||
.show();
|
.show();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case DIALOG_NONUMBER:{
|
case DIALOG_NONUMBER:{
|
||||||
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
|
new AlertDialog.Builder(MultiSmsSender.this).setPositiveButton(
|
||||||
getResources().getString(R.string.ok),
|
getResources().getString(R.string.ok),
|
||||||
@ -94,6 +106,49 @@ public class MultiSmsSender extends Activity {
|
|||||||
}
|
}
|
||||||
}).setMessage(
|
}).setMessage(
|
||||||
getResources().getString(R.string.enter_number)).show();
|
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) {
|
public void onClick(View v) {
|
||||||
showDialog(SENDING_DIALOG_KEY);
|
showDialog(SENDING_DIALOG_KEY);
|
||||||
MessageSenderThread sender = new MessageSenderThread(mHandler);
|
mThreadSender = new MessageSenderThread(mHandler);
|
||||||
sender.start();
|
mThreadSender.start();
|
||||||
//sendMessage();
|
//sendMessage();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -154,16 +209,25 @@ public class MultiSmsSender extends Activity {
|
|||||||
public MessageSenderThread( Handler h) {
|
public MessageSenderThread( Handler h) {
|
||||||
mHandler = h;
|
mHandler = h;
|
||||||
}
|
}
|
||||||
public void run() {
|
public synchronized void run() {
|
||||||
|
super.run();
|
||||||
sendMessage(mHandler);
|
sendMessage(mHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
public void sendMessage(Handler handler) {
|
public void sendMessage(Handler handler) {
|
||||||
MySMSManager manager = new MySMSManager();
|
MySMSManager manager = new MySMSManager();
|
||||||
String message = mEditor.getText().toString();
|
String message = mEditor.getText().toString();
|
||||||
|
mManyMessageContinue = false;
|
||||||
|
|
||||||
if("".equals(message)) {
|
if("".equals(message)) {
|
||||||
|
{
|
||||||
|
Message msg = handler.obtainMessage();
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
b.putInt("ORIGIN", DIALOG_PROGRESS_CANCEL);
|
||||||
|
msg.setData(b);
|
||||||
|
handler.sendMessage(msg);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,15 +239,6 @@ public class MultiSmsSender extends Activity {
|
|||||||
ArrayList<String> messages = manager.divideMessage(message);
|
ArrayList<String> messages = manager.divideMessage(message);
|
||||||
int messageCount = messages.size();
|
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) {
|
if (haveDeliveryReports) {
|
||||||
deliveryId = mDbHelper.createDelivery(message.substring(0, Math.min(30, message
|
deliveryId = mDbHelper.createDelivery(message.substring(0, Math.min(30, message
|
||||||
@ -191,50 +246,95 @@ public class MultiSmsSender extends Activity {
|
|||||||
.format(new Date()));
|
.format(new Date()));
|
||||||
|
|
||||||
}
|
}
|
||||||
if (numbers.length != 0) {
|
if (size != 0) {
|
||||||
for (int i = 0; i < numbers.length; i++) {
|
if(size > MANY_MESSAGE){
|
||||||
String newN = numbers[i].trim();
|
{
|
||||||
|
|
||||||
if (!newN.equals("")
|
|
||||||
&& PhoneNumberUtils.isWellFormedSmsAddress(newN)) {
|
|
||||||
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_MANYMESSAGE);
|
||||||
b.putInt("total", (i*100)/size);
|
|
||||||
msg.setData(b);
|
msg.setData(b);
|
||||||
handler.sendMessage(msg);
|
handler.sendMessage(msg);
|
||||||
//mSendingDialog.setProgress( i/ size);
|
}
|
||||||
|
synchronized (MultiSmsSender.this) {
|
||||||
if (!allreadySend.contains(newN)) {
|
try {
|
||||||
allreadySend.add(newN);
|
MultiSmsSender.this.wait();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
ArrayList<PendingIntent> deliveryIntents = new ArrayList<PendingIntent>(messageCount);
|
e.printStackTrace();
|
||||||
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 );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
Message msg = handler.obtainMessage();
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
@ -243,6 +343,9 @@ public class MultiSmsSender extends Activity {
|
|||||||
msg.setData(b);
|
msg.setData(b);
|
||||||
handler.sendMessage(msg);
|
handler.sendMessage(msg);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
Message msg = handler.obtainMessage();
|
Message msg = handler.obtainMessage();
|
||||||
Bundle b = new Bundle();
|
Bundle b = new Bundle();
|
||||||
|
Loading…
Reference in New Issue
Block a user