DeliveryReportListItem.java revision 0f236f55349f070ac94e12cca963847173393da8
1/*
2 * Copyright (C) 2008 Esmertec AG.
3 * Copyright (C) 2008 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mms.ui;
19
20import com.android.mms.R;
21import com.android.mms.util.ContactNameCache;
22
23import android.content.Context;
24import android.util.AttributeSet;
25import android.widget.ImageView;
26import android.widget.LinearLayout;
27import android.widget.TextView;
28
29/**
30 * This class displays the status for a single recipient of a message.  It is used in
31 * the ListView of DeliveryReportActivity.
32 */
33public class DeliveryReportListItem extends LinearLayout {
34    private TextView mRecipientView;
35    private TextView mStatusView;
36    private ImageView mIconView;
37
38    DeliveryReportListItem(Context context) {
39        super(context);
40    }
41
42    @Override
43    protected void onFinishInflate() {
44        super.onFinishInflate();
45
46        mRecipientView = (TextView) findViewById(R.id.recipient);
47        mStatusView = (TextView) findViewById(R.id.status);
48        mIconView = (ImageView) findViewById(R.id.icon);
49    }
50
51    public DeliveryReportListItem(Context context, AttributeSet attrs) {
52        super(context, attrs);
53    }
54
55    public final void bind(String recipient, String status) {
56        ContactNameCache cache = ContactNameCache.getInstance();
57        Context context = getContext();
58        // Recipient
59        mRecipientView.setText(cache.getContactName(context, recipient));
60
61        // Status text
62        mStatusView.setText(cache.getContactName(context, status));
63
64        // Status icon
65        String receivedStr = context.getString(R.string.status_received);
66        String failedStr = context.getString(R.string.status_failed);
67        String pendingStr = context.getString(R.string.status_pending);
68        String rejectStr = context.getString(R.string.status_rejected);
69
70        if (status.compareTo(receivedStr) == 0) {
71            mIconView.setImageResource(R.drawable.ic_sms_mms_delivered);
72        } else if (status.compareTo(failedStr) == 0) {
73            mIconView.setImageResource(R.drawable.ic_sms_mms_not_delivered);
74        } else if (status.compareTo(pendingStr) == 0) {
75            mIconView.setImageResource(R.drawable.ic_sms_mms_pending);
76        } else if (status.compareTo(rejectStr) == 0) {
77            // FIXME: need replace ic_sms_mms_not_delivered by a rejected icon.
78            mIconView.setImageResource(R.drawable.ic_sms_mms_not_delivered);
79        } else {
80            // No status report or unknown
81        }
82    }
83}
84