FileDocCategorySizeDatePackage
DeliveryReportActivity.javaAPI DocAndroid 1.5 API13028Wed May 06 22:42:46 BST 2009com.android.mms.ui

DeliveryReportActivity

public class DeliveryReportActivity extends android.app.ListActivity
This is the UI for displaying a delivery report: This activity can handle the following parameters from the intent by which it is launched: thread_id long The id of the conversation from which to get the recipients for the report. message_id long The id of the message about which a report should be displayed. message_type String The type of message (Sms or Mms). This is used in conjunction with the message id to retrive the particular message that the report will be about.

Fields Summary
private static final String
LOG_TAG
static final String[]
MMS_REPORT_REQUEST_PROJECTION
static final String[]
MMS_REPORT_STATUS_PROJECTION
static final String[]
SMS_REPORT_STATUS_PROJECTION
static final int
COLUMN_RECIPIENT
static final int
COLUMN_DELIVERY_REPORT
static final int
COLUMN_READ_REPORT
static final int
COLUMN_DELIVERY_STATUS
static final int
COLUMN_READ_STATUS
private long
mMessageId
private String
mMessageType
Constructors Summary
Methods Summary
private longgetMessageId(android.os.Bundle icicle, android.content.Intent intent)

        long msgId = 0L;

        if (icicle != null) {
            msgId = icicle.getLong("message_id");
        }

        if (msgId == 0L) {
            msgId = intent.getLongExtra("message_id", 0L);
        }

        return msgId;
    
private java.lang.StringgetMessageType(android.os.Bundle icicle, android.content.Intent intent)

        String msgType = null;

        if (icicle != null) {
            msgType = icicle.getString("message_type");
        }

        if (msgType == null) {
            msgType = intent.getStringExtra("message_type");
        }

        return msgType;
    
private java.util.ListgetMmsReportItems()

        List<MmsReportRequest> reportReqs = getMmsReportRequests();
        if (null == reportReqs) {
            return null;
        }

        if (reportReqs.size() == 0) {
            return null;
        }

        Map<String, MmsReportStatus> reportStatus = getMmsReportStatus();
        List<DeliveryReportItem> items = new ArrayList<DeliveryReportItem>();
        for (MmsReportRequest reportReq : reportReqs) {
            String statusText = getString(R.string.status_label) + 
                getMmsReportStatusText(reportReq, reportStatus);
            items.add(new DeliveryReportItem(getString(R.string.recipient_label) + 
                    reportReq.getRecipient(), statusText));
        }
        return items;
    
private java.util.ListgetMmsReportRequests()

        Uri uri = Uri.withAppendedPath(Mms.REPORT_REQUEST_URI,
                                       String.valueOf(mMessageId));
        Cursor c = SqliteWrapper.query(this, getContentResolver(), uri,
                      MMS_REPORT_REQUEST_PROJECTION, null, null, null);

        if (c == null) {
            return null;
        }

        try {
            if (c.getCount() <= 0) {
                return null;
            }

            List<MmsReportRequest> reqList = new ArrayList<MmsReportRequest>();
            while (c.moveToNext()) {
                reqList.add(new MmsReportRequest(
                                c.getString(COLUMN_RECIPIENT),
                                c.getInt(COLUMN_DELIVERY_REPORT),
                                c.getInt(COLUMN_READ_REPORT)));
            }
            return reqList;
        } finally {
            c.close();
        }
    
private java.util.MapgetMmsReportStatus()

        Uri uri = Uri.withAppendedPath(Mms.REPORT_STATUS_URI,
                                       String.valueOf(mMessageId));
        Cursor c = SqliteWrapper.query(this, getContentResolver(), uri,
                       MMS_REPORT_STATUS_PROJECTION, null, null, null);

        if (c == null) {
            return null;
        }

        try {
            Map<String, MmsReportStatus> statusMap =
                    new HashMap<String, MmsReportStatus>();

            while (c.moveToNext()) {
                String recipient = c.getString(COLUMN_RECIPIENT);
                recipient = (Mms.isEmailAddress(recipient))?
                                        Mms.extractAddrSpec(recipient):
                                        Recipient.filterPhoneNumber(recipient);
                MmsReportStatus status = new MmsReportStatus(
                                        c.getInt(COLUMN_DELIVERY_STATUS),
                                        c.getInt(COLUMN_READ_STATUS));
                statusMap.put(recipient, status);
            }
            return statusMap;
        } finally {
            c.close();
        }
    
private java.lang.StringgetMmsReportStatusText(com.android.mms.ui.DeliveryReportActivity$MmsReportRequest request, java.util.Map reportStatus)

        if (reportStatus == null) {
            // haven't received any reports.
            return getString(R.string.status_pending);
        }

        String recipient = request.getRecipient();
        recipient = (Mms.isEmailAddress(recipient))?
                Mms.extractAddrSpec(recipient): Recipient.filterPhoneNumber(recipient);
        MmsReportStatus status = queryStatusByRecipient(reportStatus, recipient);
        if (status == null) {
            // haven't received any reports.
            return getString(R.string.status_pending);
        }

        if (request.isReadReportRequested()) {
            if (status.readStatus != 0) {
                switch (status.readStatus) {
                    case PduHeaders.READ_STATUS_READ:
                        return getString(R.string.status_read);
                    case PduHeaders.READ_STATUS__DELETED_WITHOUT_BEING_READ:
                        return getString(R.string.status_unread);
                }
            }
        }

        switch (status.deliveryStatus) {
            case 0: // No delivery report received so far.
                return getString(R.string.status_pending);
            case PduHeaders.STATUS_FORWARDED:
            case PduHeaders.STATUS_RETRIEVED:
                return getString(R.string.status_received);
            case PduHeaders.STATUS_REJECTED:
                return getString(R.string.status_rejected);
            default:
                return getString(R.string.status_failed);
        }
    
private java.util.ListgetReportItems()

        if (mMessageType.equals("sms")) {
            return getSmsReportItems();
        } else {
            return getMmsReportItems();
        }
    
private java.util.ListgetSmsReportItems()

        String selection = "_id = " + mMessageId;
        Cursor c = SqliteWrapper.query(this, getContentResolver(), Sms.CONTENT_URI,
                              SMS_REPORT_STATUS_PROJECTION, selection, null, null);
        if (c == null) {
            return null;
        }

        try {
            if (c.getCount() <= 0) {
                return null;
            }

            List<DeliveryReportItem> items = new ArrayList<DeliveryReportItem>();
            while (c.moveToNext()) {
                items.add(new DeliveryReportItem(
                                getString(R.string.recipient_label) + c.getString(COLUMN_RECIPIENT),
                                getString(R.string.status_label) + 
                                    getSmsStatusText(c.getInt(COLUMN_DELIVERY_STATUS))));
            }
            return items;
        } finally {
            c.close();
        }
    
private java.lang.StringgetSmsStatusText(int status)

        if (status == Sms.STATUS_NONE) {
            // No delivery report requested
            return getString(R.string.status_none);
        } else if (status >= Sms.STATUS_FAILED) {
            // Failure
            return getString(R.string.status_failed);
        } else if (status >= Sms.STATUS_PENDING) {
            // Pending
            return getString(R.string.status_pending);
        } else {
            // Success
            return getString(R.string.status_received);
        }
    
private voidinitListAdapter()

        List<DeliveryReportItem> items = getReportItems();
        if (items == null) {
            items = new ArrayList<DeliveryReportItem>(1);
            items.add(new DeliveryReportItem("", getString(R.string.status_none)));
            Log.w(LOG_TAG, "cursor == null");
        }
        setListAdapter(new DeliveryReportAdapter(this, items));
    
private voidinitListView()

        // Add the header for the list view.
        LayoutInflater inflater = getLayoutInflater();
        View header = inflater.inflate(R.layout.delivery_report_header, null);
        getListView().addHeaderView(header, null, true);
    
protected voidonCreate(android.os.Bundle icicle)


    
        
        super.onCreate(icicle);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.delivery_report_activity);

        Intent intent = getIntent();
        mMessageId = getMessageId(icicle, intent);
        mMessageType = getMessageType(icicle, intent);

        initListView();
        initListAdapter();
    
public voidonResume()

        super.onResume();
        refreshDeliveryReport();
    
private static com.android.mms.ui.DeliveryReportActivity$MmsReportStatusqueryStatusByRecipient(java.util.Map status, java.lang.String recipient)

        Set<String> recipientSet = status.keySet();
        Iterator<String> iterator = recipientSet.iterator();
        while (iterator.hasNext()) {
            String r = iterator.next();
            if (Mms.isEmailAddress(recipient)) {
                if (TextUtils.equals(r, recipient)) {
                    return status.get(r);
                }
            }
            else if (PhoneNumberUtils.compare(r, recipient)) {
                return status.get(r);
            }
        }
        return null;
    
private voidrefreshDeliveryReport()

        ListView list = getListView();
        list.invalidateViews();
        list.requestFocus();