package com.sogouchat.smsmms;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.sogouchat.R;
import com.sogouchat.util.DateFormatHelper;
import android.content.Context;
import android.content.IntentFilter.MalformedMimeTypeException;
import android.graphics.Color;
import android.text.TextUtils.TruncateAt;
import android.text.format.Time;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SmsTotal {
public String sContactName=null;
public String name; //contactsid
public String phoneNumber;
public String smsbody;
public String date;
public long tmDate;
public int threadID;
public int type;
public int nCount;
public int nMmsCount= 0;
public boolean bRead = true;
public Vector<Sms> smsList=new Vector<Sms>();
public Vector<Mms> mmsList = new Vector<Mms>();
public Map<Integer, Mms> mapMms = new HashMap<Integer, Mms>();
public boolean bHasMms = false;
public boolean bHasMmsUnRead=false;
public boolean bHasSmsUnRead=false;
public int nUnReadSmsCount = 0;
public int nUnReadMmsCount = 0;
public int nUnReadCount = 0;
public SmsTotal(String strName,String strPhoneNumber,String strSmsBody,long tmDate,int nType,int nThreadID,int nCount, boolean bRead){
this.bRead = bRead;
name = strName;
phoneNumber = strPhoneNumber;
smsbody = strSmsBody;
this.tmDate = tmDate;
threadID = nThreadID;
type = nType;
date = DateFormatHelper.FormatDate(tmDate);
//date = CreateDateStr(tmDate);
this.nCount = nCount;
if (name!=null) {
ContactsInfo info = ContactsMgr.GetI().GetContactByID(Integer.parseInt(name));
if (info!=null && info.displayName!=null) {
sContactName = info.displayName;
}
else {
info = ContactsMgr.GetI().GetContactByNumber(strPhoneNumber);
if (info!=null && info.displayName!=null) {
sContactName = info.displayName;
}
else {
sContactName =null;
}
}
}else {
ContactsInfo info = ContactsMgr.GetI().GetContactByNumber(strPhoneNumber);
if (info!=null && info.displayName!=null) {
sContactName = info.displayName;
}
else {
sContactName =null;
}
}
}
public void AddMmsCount(int nCount,long tmCur,String strBody, boolean bRead2){
nMmsCount = nCount;
this.nCount += nCount;
if (bRead && !bRead2) {
bRead = bRead2;
}
bHasMms = true;
if (tmCur>tmDate) {
tmDate = tmCur;
//date = CreateDateStr(tmDate);
date = DateFormatHelper.FormatDate(tmDate);
smsbody = strBody;
}
}
public static String CreateDateStr(long tm){
Time tmTime = new Time();
tmTime.set(tm);
return tmTime.format("%Y��%m��%d�� %H:%M");
}
public String GetTrueName(){
String string="";
if (sContactName!=null) {
string = sContactName;
}else {
string =phoneNumber;
}
return string;
}
public String GetName(){
String string="";
if (sContactName!=null) {
string = sContactName;
}else {
string =phoneNumber;
}
string +="(";
string += nCount;
string +=")";
return string;
}
public static int dip2px(Context context, float dpValue) {
final float scale = context.getResources().getDisplayMetrics().density;
return (int) (dpValue * scale + 0.5f);
}
public static View GetViewEx(SmsTotal sms,Context context){
int nPicW = 40;
nPicW = 46;
//RelativeLayout relativeLayout = new RelativeLayout(context);
LinearLayout layout = new LinearLayout(context);
layout.setOrientation(LinearLayout.HORIZONTAL);
String strFristName=null;
if (sms.sContactName!=null && sms.sContactName.length()>0) {
strFristName = sms.sContactName.substring(0,1);
}
LinearLayout.LayoutParams LP_PIC =new LinearLayout.LayoutParams(dip2px(context,nPicW),dip2px(context,nPicW));
LinearLayout.LayoutParams LP_UP = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, dip2px(context,nPicW/2), 1);
LinearLayout.LayoutParams LP_FW = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
if (strFristName==null) {
ImageView imageViewPic = new ImageView(context);
imageViewPic.setLayoutParams(LP_PIC);
imageViewPic.setImageResource(R.drawable.bg_photo_default);
layout.addView(imageViewPic);
} else {
TextView textViewPic = new TextView(context);
textViewPic.setText(strFristName);
textViewPic.setLayoutParams(LP_PIC);
textViewPic.setTextColor(Color.WHITE);
//textViewPic.setTextSize(TypedValue.COMPLEX_UNIT_SP, 30f);
textViewPic.setTextSize(TypedValue.COMPLEX_UNIT_SP, 35f);
textViewPic.setBackgroundResource(R.drawable.bg_aptitude_photo);
textViewPic.setGravity(Gravity.CENTER);
layout.addView(textViewPic);
}
LinearLayout layoutRight = new LinearLayout(context);
layoutRight.setOrientation(LinearLayout.VERTICAL);
layoutRight.setLayoutParams(LP_FW);
LinearLayout layoutUp = new LinearLayout(context);
layoutUp.setOrientation(LinearLayout.HORIZONTAL);
layoutUp.setLayoutParams(LP_FW);
TextView textName = new TextView(context);
textName.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
textName.getPaint().setFakeBoldText(true);
textName.setLayoutParams(LP_UP);
textName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
textName.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
TextView textDate = new TextView(context);
textDate.setGravity(Gravity.RIGHT|Gravity.CENTER_VERTICAL);
textDate.setLayoutParams(LP_UP);
textDate.setTextColor(Color.BLUE);
textDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
textDate.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
TextView textBody = new TextView(context);
textBody.setLayoutParams(LP_UP);
textBody.setGravity(Gravity.LEFT|Gravity.CENTER_VERTICAL);
textBody.setTextColor(Color.argb(231, 88, 88, 88));
textBody.setTextSize(TypedValue.COMPLEX_UNIT_SP, 13);
textBody.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
layoutUp.addView(textName);
layoutUp.addView(textDate);
layoutRight.addView(layoutUp);
layoutRight.addView(textBody);
textName.setText(sms.GetTrueName());
textDate.setText(sms.date);
textBody.setText(sms.smsbody);
textBody.setSingleLine();
textBody.setEllipsize(TruncateAt.END);
layoutRight.setPadding(30, 0, 20, 0);
layout.addView(layoutRight);
int nPad = dip2px(context,10);
layout.setPadding(nPad, nPad,nPad, nPad);
return layout;
//return relativeLayout;
}
public static View GetView(SmsTotal sms,Context context){
if (true) {
return GetViewEx(sms, context);
}
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);
//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());
textName.setSingleLine();
textName.setEllipsize(TruncateAt.END);
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);
//textSms.setLayoutParams(LP_TEXT2);
textSms.setText(sms.smsbody);
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 Mms GetMMsByID(int nID){
return mapMms.get(nID);
}
public void add(Sms mSms) {
// TODO Auto-generated method stub
smsList.add(mSms);
if (mSms.bMms) {
final Mms mms = (Mms) mSms;
mmsList.add(mms);
mapMms.put(mms.nPartID, mms);
}
}
public Mms GetFirstMms(){
if (mmsList.size()>0) {
return mmsList.get(mmsList.size()-1);
}
else {
return null;
}
}
public Mms GetNextMms(int nID){
for (int i = mmsList.size()-1; i >0; i--) {
Mms mms = mmsList.get(i);
if (mms.nPartID==nID) {
if (i>0) {
return mmsList.get(i-1);
}else {
return null;
}
}
}
return null;
}
}