Back to project page MySms.
The source code is released under:
Apache License
If you think the Android project MySms listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.henningta.mysms; // ww w .j av a2s . c om import android.content.Context; import android.os.Build; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import java.util.ArrayList; import java.util.Collection; /** * Custom adapter for messages */ public class MessageAdapter extends ArrayAdapter<Message> { private LayoutInflater inflater; private int resourceId; public MessageAdapter(Context context, int resourceId, ArrayList<Message> objects) { super(context, resourceId, objects); this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); this.resourceId = resourceId; } @Override public View getView(int position, View convertView, ViewGroup parent) { ItemHolder holder; if (convertView == null) { // create new holder = new ItemHolder(); convertView = inflater.inflate(resourceId, parent, false); holder.incomingMessage = (TextView)convertView.findViewById(R.id.message_text_left); holder.incomingTime = (TextView)convertView.findViewById(R.id.message_time_left); holder.outgoingMessage = (TextView)convertView.findViewById(R.id.message_text_right); holder.outgoingTime = (TextView)convertView.findViewById(R.id.message_time_right); holder.imgDeliveryStatus = (ImageView)convertView.findViewById(R.id.img_delivered_status); convertView.setTag(holder); } else { // recycle holder = (ItemHolder)convertView.getTag(); } Message message = this.getItem(position); String s = message.getText(); long time = message.getTime(); String formattedTime = ""; if (time == 0 || time == Settings.NOT_SET) { holder.incomingTime.setVisibility(View.GONE); holder.outgoingTime.setVisibility(View.GONE); } else { formattedTime = Settings.formatTime(time); } // default background convertView.setBackgroundResource(R.drawable.message_selector_outgoing); String statusText; if (message.getStatus() == Message.STATUS_SENDING) { statusText = "Sending..."; } else if (message.getStatus() == Message.STATUS_FAILED) { statusText = "Failed."; } else { statusText = formattedTime; } // format message based on whether it was sent or received if (message.getStatus() == Message.STATUS_RECEIVED) { convertView.setBackgroundResource(R.drawable.message_selector_incoming); holder.incomingMessage.setText(s); holder.outgoingMessage.setText(""); holder.incomingTime.setText(statusText); holder.outgoingTime.setText(""); holder.imgDeliveryStatus.setImageResource(android.R.color.transparent); } else { holder.incomingMessage.setText(""); holder.outgoingMessage.setText(s); holder.incomingTime.setText(""); holder.outgoingTime.setText(statusText); if (message.getStatus() == Message.STATUS_DELIVERED) { holder.imgDeliveryStatus.setImageResource(R.color.delivery_green); } else { holder.imgDeliveryStatus.setImageResource(R.color.delivery_red); } } return convertView; } @Override public void addAll(Collection<? extends Message> items) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) { for (Message item : items) { this.add(item); } } else { super.addAll(items); } } class ItemHolder { TextView incomingMessage; TextView incomingTime; TextView outgoingMessage; TextView outgoingTime; ImageView imgDeliveryStatus; } }