From 6c373b51e5dadcc40babecdb460d646b5354fab7 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Tue, 26 Jan 2010 15:46:26 +0100 Subject: [PATCH] Delivery intents *Should* be working but... ?? Implements a mySMSManger to use cupcake or newer version of SMSManager --- AndroidManifest.xml | 6 +++- res/values-fr/strings.xml | 1 + .../openwide/android/DeliveryDbAdapter.java | 8 ++--- .../openwide/android/ListEntryActivity.java | 22 ++++++++++++ src/com/openwide/android/MessageReceiver.java | 8 +++-- src/com/openwide/android/MultiSmsSender.java | 4 +-- src/com/openwide/android/MySMSManager.java | 34 +++++++++++++++++++ .../openwide/android/MySMSManagerCupcake.java | 29 ++++++++++++++++ .../openwide/android/MySMSManagerOther.java | 30 ++++++++++++++++ 9 files changed, 131 insertions(+), 11 deletions(-) create mode 100644 src/com/openwide/android/MySMSManager.java create mode 100644 src/com/openwide/android/MySMSManagerCupcake.java create mode 100644 src/com/openwide/android/MySMSManagerOther.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6e6e66d..43b8d0f 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -14,7 +14,11 @@ - + + + + + Supprimer Ajouter un groupe Accusé de récéption + Aucun accusé de récéption Accusé de récéption Créer un group Supprimer ce groupe diff --git a/src/com/openwide/android/DeliveryDbAdapter.java b/src/com/openwide/android/DeliveryDbAdapter.java index 731fc91..718c4c6 100644 --- a/src/com/openwide/android/DeliveryDbAdapter.java +++ b/src/com/openwide/android/DeliveryDbAdapter.java @@ -6,6 +6,7 @@ import android.database.Cursor; import android.database.SQLException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; +import android.net.Uri; import android.provider.Contacts.Phones; import android.util.Log; @@ -236,13 +237,12 @@ public class DeliveryDbAdapter { public String nameFromNumber(String number) { - //TODO - //Cursor c1 = mCtx.getContentResolver().query(Phones.CONTENT_URI, new String[] { Phones.NUMBER }, null, null, null); - Cursor c = mCtx.getContentResolver().query(Phones.CONTENT_URI, new String[] { Phones.NAME }, Phones.NUMBER +"="+number, null, null); + Uri contactUri = Uri.withAppendedPath(Phones.CONTENT_FILTER_URL, Uri.encode(number)); + Cursor c = mCtx.getContentResolver().query(contactUri, new String[] { Phones.DISPLAY_NAME }, null, null, null); if(c != null) { c.moveToFirst(); if(c.isFirst()) { - return c.getString(c.getColumnIndex(Phones.NAME)); + return c.getString(c.getColumnIndex(Phones.DISPLAY_NAME)); }else { return ""; } diff --git a/src/com/openwide/android/ListEntryActivity.java b/src/com/openwide/android/ListEntryActivity.java index 95447e3..6846e7e 100644 --- a/src/com/openwide/android/ListEntryActivity.java +++ b/src/com/openwide/android/ListEntryActivity.java @@ -4,6 +4,8 @@ import android.app.ListActivity; import android.content.Context; import android.database.Cursor; import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; @@ -12,6 +14,7 @@ import android.widget.SimpleCursorAdapter; public class ListEntryActivity extends ListActivity { DeliveryDbAdapter mDbHelper; Long mDeliveryId; + public static final int REFRESH_ID = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -53,6 +56,23 @@ public class ListEntryActivity extends ListActivity { super.onDestroy(); } + @Override + public boolean onCreateOptionsMenu(Menu menu) { + super.onCreateOptionsMenu(menu); + menu.add(0, REFRESH_ID,0, R.string.refresh); + return true; + } + + @Override + public boolean onContextItemSelected(MenuItem item) { + switch(item.getItemId()) { + case REFRESH_ID: + fillData(); + return true; + } + return super.onContextItemSelected(item); + } + private class EntryCursorAdapter extends SimpleCursorAdapter{ Cursor c; int deliveredIdx; @@ -83,5 +103,7 @@ public class ListEntryActivity extends ListActivity { return v; } } + + } diff --git a/src/com/openwide/android/MessageReceiver.java b/src/com/openwide/android/MessageReceiver.java index fe8220e..a00555d 100644 --- a/src/com/openwide/android/MessageReceiver.java +++ b/src/com/openwide/android/MessageReceiver.java @@ -4,16 +4,21 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.Bundle; +import android.util.Log; 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) { + Log.d("------------------", "WORKING :)!!!!"); if (MESSAGE_RECEIVED.equals(intent.getAction())) { Long entryId; Bundle extras = intent.getExtras(); entryId = extras != null ? extras.getLong(MultiSmsSender.PARAM_ENTRY_ID): null; + //byte[] pdu = (byte[]) intent.getByteArrayExtra("pdu"); + //SmsMessage message = SmsMessage.createFromPdu(pdu); + //int status = message.getStatus(); DeliveryDbAdapter mDbHelper = new DeliveryDbAdapter(context); mDbHelper.open(); mDbHelper.setEntryDelivered(entryId); @@ -21,9 +26,6 @@ public class MessageReceiver extends BroadcastReceiver{ } } - - - } diff --git a/src/com/openwide/android/MultiSmsSender.java b/src/com/openwide/android/MultiSmsSender.java index 41f1511..d00aefe 100644 --- a/src/com/openwide/android/MultiSmsSender.java +++ b/src/com/openwide/android/MultiSmsSender.java @@ -10,12 +10,10 @@ 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; import android.telephony.PhoneNumberUtils; -import android.telephony.gsm.SmsManager; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -89,7 +87,7 @@ public class MultiSmsSender extends Activity { } public void sendMessage() { - SmsManager manager = SmsManager.getDefault(); + MySMSManager manager = MySMSManager.getInstance(); String message = mEditor.getText().toString(); String[] numbers = mContacts.getText().toString().split(","); HashSet allreadySend = new HashSet(); diff --git a/src/com/openwide/android/MySMSManager.java b/src/com/openwide/android/MySMSManager.java new file mode 100644 index 0000000..2133340 --- /dev/null +++ b/src/com/openwide/android/MySMSManager.java @@ -0,0 +1,34 @@ +package com.openwide.android; + +import java.util.ArrayList; + +import android.app.PendingIntent; +import android.os.Build; + +public abstract class MySMSManager { + private static MySMSManager sInstance; + + public static MySMSManager getInstance() { + if(sInstance == null) { + String className; + int sdkVersion = Integer.parseInt(Build.VERSION.SDK); + if (sdkVersion < Build.VERSION_CODES.DONUT) { + className = "com.openwide.android.MySMSManagerCupcake"; + } else { + className = "com.openwide.android.MySMSManagerOther"; + } + try { + Class clazz = + Class.forName(className).asSubclass(MySMSManager.class); + sInstance = clazz.newInstance(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + return sInstance; + } + + public abstract ArrayList divideMessage(String text); + public abstract void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList parts, ArrayList sentIntents, ArrayList deliveryIntents ); + +} diff --git a/src/com/openwide/android/MySMSManagerCupcake.java b/src/com/openwide/android/MySMSManagerCupcake.java new file mode 100644 index 0000000..3db1ec8 --- /dev/null +++ b/src/com/openwide/android/MySMSManagerCupcake.java @@ -0,0 +1,29 @@ +package com.openwide.android; + +import java.util.ArrayList; + +import android.app.PendingIntent; +import android.telephony.gsm.SmsManager; + + +@SuppressWarnings("deprecation") +public class MySMSManagerCupcake extends MySMSManager { + + SmsManager mManager; + public MySMSManagerCupcake() { + mManager = SmsManager.getDefault(); + } + + + @Override + public ArrayList divideMessage(String text) { + + return mManager.divideMessage(text); + } + + public void sendMultipartTextMessage(String destinationAddress, String scAddress, ArrayList parts, ArrayList sentIntents, ArrayList deliveryIntents ) { + mManager.sendMultipartTextMessage(destinationAddress, scAddress, parts, sentIntents, deliveryIntents); + } + + +} diff --git a/src/com/openwide/android/MySMSManagerOther.java b/src/com/openwide/android/MySMSManagerOther.java new file mode 100644 index 0000000..da540c7 --- /dev/null +++ b/src/com/openwide/android/MySMSManagerOther.java @@ -0,0 +1,30 @@ +package com.openwide.android; + +import java.util.ArrayList; + +import android.app.PendingIntent; +import android.telephony.SmsManager; + +public class MySMSManagerOther extends MySMSManager { + + SmsManager mManager; + public MySMSManagerOther() { + mManager = SmsManager.getDefault(); + } + + @Override + public ArrayList divideMessage(String text) { + + return mManager.divideMessage(text); + } + + @Override + public void sendMultipartTextMessage(String destinationAddress, + String scAddress, ArrayList parts, + ArrayList sentIntents, + ArrayList deliveryIntents) { + mManager.sendMultipartTextMessage(destinationAddress, scAddress, parts, sentIntents, deliveryIntents); + + } + +}