package com.sogouchat.smsmms;
import com.sogouchat.R;
import android.R.integer;
import android.content.Context;
import android.graphics.Color;
import android.text.format.Time;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;
import android.widget.TextView;
public class Sms extends Object{
public Sms(String strName,String strPhoneNumber,String strSmsBody,long tmDate,int nType,int nTreadID,int nID){
name = strName;
phoneNumber = strPhoneNumber;
smsbody = strSmsBody;
this.tmDate = tmDate;
this.threadID = nTreadID;
ID = nID;
type = nType;
date = CreateDateStr(tmDate);
}
public static String CreateDateStr(long tm){
Time tmTime = new Time();
tmTime.set(tm);
return tmTime.format("%Y年%m月%d日 %H:%M");
}
public String GetName(){
String string;
switch (type) {
case SmsBase.Sms_Type_Inbox:
string = "接收";
break;
case SmsBase.Sms_Type_Sent:
string = "发送";
break;
default:
string = "未知";
break;
}
if (name!=null) {
string += name;
string +="(";
string +=phoneNumber;
string +=")";
}else {
string +=phoneNumber;
}
return string;
}
public String name;
public String phoneNumber;
public String smsbody;
public String date;
public long tmDate;
public int threadID;
public int type;
public boolean bMms = false;
public int ID;
public View GetView(Context context, String strSearchKey){
Sms sms = this;
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, 30, 1);
//LinearLayout.LayoutParams LP_TEXT2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,60);
TextView textName = new TextView(context);
TextView textDate = new TextView(context);
textDate.setLayoutParams(LP_TEXT);
textName.setLayoutParams(LP_TEXT);
textDate.setText(sms.date);
textName.setText(sms.GetName());
textDate.setTextColor(Color.GRAY);
textDate.setGravity(Gravity.CENTER);
//layoutUp.addView(textName);
layoutUp.addView(textDate);
LinearLayout layoutDown = new LinearLayout(context);
layoutUp.setOrientation(LinearLayout.HORIZONTAL);
final AutoTransTextView textSms = new AutoTransTextView(context);
//textSms.setLayoutParams(LP_TEXT2);
//textSms.SetTextByMark(sms.smsbody);
textSms.SetTextByMarkAndSearchKey(sms.smsbody,strSearchKey);
layoutDown.addView(textSms);
textSms.setTextColor(Color.BLACK);
layout.addView(layoutUp);
layout.addView(layoutDown);
if (sms.type == SmsBase.Sms_Type_Inbox) {
layoutDown.setPadding(0, 10, 150, 0);
textSms.setBackgroundResource(R.drawable.bg_in_rect_ok);
layoutDown.setGravity(Gravity.LEFT);
//textSms.setGravity(Gravity.LEFT);
}else if (sms.type == SmsBase.Sms_Type_Failed) {
layoutDown.setPadding(150, 10, 0, 0);
textSms.setBackgroundResource(R.drawable.bg_out_rect_fail);
//textSms.setGravity(Gravity.RIGHT);
layoutDown.setGravity(Gravity.RIGHT);
}else {
layoutDown.setPadding(150, 10, 0, 0);
textSms.setBackgroundResource(R.drawable.bg_out_rect_ok);
//textSms.setGravity(Gravity.RIGHT);
layoutDown.setGravity(Gravity.RIGHT);
}
// textSms.setClickable(true);
// textSms.setOnClickListener(new View.OnClickListener() {
//
// public void onClick(View v) {
// // TODO Auto-generated method stub
// textSms.setBackgroundResource(R.drawable.bg_out_rectangle_brown_normal);
// }
// });
return layout;
}
}