package com.sogouchat.search; import java.util.Vector; import com.sogouchat.smsmms.Sms; import com.sogouchat.util.DateFormatHelper; import android.R.string; import android.content.Context; import android.graphics.Color; import android.text.TextUtils.TruncateAt; import android.util.TypedValue; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; import android.widget.BaseAdapter; import android.widget.LinearLayout; import android.widget.TextView; public class SearchMessageAdapter extends BaseAdapter { private Context context; private Vector<Sms> sVector; private String strKey; public SearchMessageAdapter(Context context,Vector<Sms> list,String strKey){ this.context = context; sVector = list; this.strKey = strKey; } public int getCount() { // TODO Auto-generated method stub return sVector.size(); } public Object getItem(int arg0) { // TODO Auto-generated method stub return sVector.get(arg0); } public long getItemId(int arg0) { // TODO Auto-generated method stub return 0; } public View getView(int arg0, View arg1, ViewGroup arg2) { // TODO Auto-generated method stub Sms sms = (Sms)getItem(arg0); if (sms!=null) { return GetView(sms, context,strKey); } return null; } public static View GetView(Sms sms,Context context,String strKey){ LinearLayout layout = new LinearLayout(context); layout.setOrientation(LinearLayout.VERTICAL); LinearLayout layoutUp = new LinearLayout(context); layoutUp.setOrientation(LinearLayout.HORIZONTAL); LinearLayout.LayoutParams LP_TEXT = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1); TextView textName = new TextView(context); TextView textDate = new TextView(context); textDate.setLayoutParams(LP_TEXT); textName.setLayoutParams(LP_TEXT); String strDate = DateFormatHelper.FormatDate(sms.tmDate); textDate.setText(strDate); textName.setText(sms.name); textName.setSingleLine(); textName.setEllipsize(TruncateAt.END); textName.setTextColor(Color.BLACK); textName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); textDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); textDate.setGravity(Gravity.RIGHT); textDate.setTextColor(Color.BLUE); layoutUp.addView(textName); layoutUp.addView(textDate); LinearLayout layoutDown = new LinearLayout(context); layoutUp.setOrientation(LinearLayout.HORIZONTAL); TextView textSms = new TextView(context); CharSequence strBody = HitTextHelper.GetHitText(sms.smsbody,strKey); textSms.setText(strBody); textSms.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12); textSms.setTextColor(Color.GRAY); textSms.setEllipsize(TruncateAt.END); textSms.setMaxLines(2); layoutDown.addView(textSms); layout.addView(layoutUp); layout.addView(layoutDown); layout.setPadding(30,8, 30, 8); return layout; } public void notifyChange(String strText) { // TODO Auto-generated method stub strKey = strText; notifyDataSetChanged(); } }