package com.sogouchat.smsmms; import java.util.HashMap; import java.util.Map; import java.util.Vector; import org.w3c.dom.NodeList; import org.w3c.dom.smil.SMILDocument; import org.w3c.dom.smil.SMILElement; import org.w3c.dom.smil.SMILLayoutElement; import org.w3c.dom.smil.SMILRegionElement; import org.w3c.dom.smil.SMILRootLayoutElement; import com.sogouchat.smil.SmilRegionElementImpl; import com.sogouchat.R; import android.R.integer; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Color; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.support.v4.view.ViewPager.LayoutParams; import android.view.Gravity; import android.view.View; import android.widget.ImageView; import android.widget.ImageView.ScaleType; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; public class Mms extends Sms{ public SMILDocument smil=null; private Vector<MmsPart> parts = new Vector<MmsPart>(); private Map<String, MmsPart> mapParts= new HashMap<String, MmsPart>(); public boolean bLoad = false; public int nPartID = 0; public void Add(MmsPart part){ parts.add(part); mapParts.put(part.name, part); } public MmsPart GetPart(String key){ return mapParts.get(key); } public Mms(String strName, String strPhoneNumber, String strSmsBody, long tmDate, int nType, int nTreadID,int nID) { super(strName, strPhoneNumber, strSmsBody, tmDate, nType, nTreadID,nID); // TODO Auto-generated constructor stub bMms = true; } @Override public View GetView(Context context,String strKey) { // TODO Auto-generated method stub 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 textDate = new TextView(context); textDate.setLayoutParams(LP_TEXT); textDate.setText(date); textDate.setTextColor(Color.GRAY); textDate.setGravity(Gravity.CENTER); layoutUp.addView(textDate); LinearLayout layoutDown = new LinearLayout(context); layoutUp.setOrientation(LinearLayout.HORIZONTAL); if (smil!=null) { SMILLayoutElement smilLayoutElement = smil.getLayout(); LinearLayout layoutSmil = new LinearLayout(context); if (smilLayoutElement!=null) { SMILRootLayoutElement root = smilLayoutElement.getRootLayout(); if (root!=null) { RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams( root.getWidth(),root.getHeight()); RelativeLayout relativeLayoutRoot = new RelativeLayout(context); //relativeLayoutRoot.setLayoutParams(layoutParams); //relativeLayoutRoot.setBackgroundColor(Color.GRAY); layoutSmil.addView(relativeLayoutRoot); //layoutSmil.setPadding(10, 10, 10, 10); NodeList list = smilLayoutElement.getRegions(); int nImageHeight = 0; ImageView curImageView = null; TextView curTextView = null; int nImageTop = 0; int nTextTop = 0; for (int i = 0; i < list.getLength(); i++) { SMILRegionElement regionElement = (SmilRegionElementImpl) list.item(i); if (regionElement.getNodeName()!=null) { if (regionElement.getId().equals("Image")) { ImageView imageView = new ImageView(context); curImageView = imageView; //imageView.set nImageTop = regionElement.getTop(); for (int j = 0; j < parts.size(); j++) { MmsPart part = parts.get(j); if (part.nType == MmsBase.PART_TYPE_IMAGE_BMP || part.nType == MmsBase.PART_TYPE_IMAGE_JPG|| part.nType == MmsBase.PART_TYPE_IMAGE_ALL|| part.nType == MmsBase.PART_TYPE_IMAGE_GIF) { if (part.bitmap!=null) { RelativeLayout.LayoutParams layoutParamsItem = new RelativeLayout.LayoutParams(0,0); layoutParamsItem.width = part.bitmap.getWidth(); layoutParamsItem.height = part.bitmap.getHeight(); imageView.setLayoutParams(layoutParamsItem); //imageView.setScaleType(ScaleType.FIT_XY); imageView.setImageBitmap(part.bitmap); nImageHeight = part.bitmap.getHeight(); } break; } } relativeLayoutRoot.addView(imageView); } else { nTextTop = regionElement.getTop(); TextView textView = new TextView(context); curTextView = textView; textView.setTextColor(Color.BLACK); for (int j = 0; j < parts.size(); j++) { MmsPart part = parts.get(j); if (part.nType == MmsBase.PART_TYPE_TEXT ) { textView.setText(part.text); break; } } relativeLayoutRoot.addView(textView); } } } if (list.getLength()==2) { RelativeLayout.LayoutParams layoutParamsItem = new RelativeLayout.LayoutParams(0,0); layoutParamsItem.width = LayoutParams.MATCH_PARENT; layoutParamsItem.height = LayoutParams.WRAP_CONTENT; if (nTextTop>nImageTop) { layoutParamsItem.topMargin = nImageHeight; curTextView.setLayoutParams(layoutParamsItem); } } } } smil.getBody().getChildNodes(); layoutDown.addView(layoutSmil); if (type == SmsBase.Sms_Type_Inbox) { layoutDown.setPadding(0, 10, 150, 0); layoutSmil.setBackgroundResource(R.drawable.bg_in_rectangle_normal); layoutDown.setGravity(Gravity.LEFT); //textSms.setGravity(Gravity.LEFT); }else if (type == SmsBase.Sms_Type_Failed) { layoutDown.setPadding(150, 10, 0, 0); layoutSmil.setBackgroundResource(R.drawable.bg_out_rectangle_brown_normal); //textSms.setGravity(Gravity.RIGHT); layoutDown.setGravity(Gravity.RIGHT); }else { layoutDown.setPadding(150, 10, 0, 0); layoutSmil.setBackgroundResource(R.drawable.bg_out_rectangle_green_normal); //textSms.setGravity(Gravity.RIGHT); layoutDown.setGravity(Gravity.RIGHT); } } else { final AutoTransTextView textSms = new AutoTransTextView(context); textSms.SetTextByMark(smsbody); layoutDown.addView(textSms); if (type == SmsBase.Sms_Type_Inbox) { layoutDown.setPadding(0, 10, 150, 0); textSms.setBackgroundResource(R.drawable.bg_in_rectangle_normal); layoutDown.setGravity(Gravity.LEFT); //textSms.setGravity(Gravity.LEFT); }else if (type == SmsBase.Sms_Type_Failed) { layoutDown.setPadding(150, 10, 0, 0); textSms.setBackgroundResource(R.drawable.bg_out_rectangle_brown_normal); //textSms.setGravity(Gravity.RIGHT); layoutDown.setGravity(Gravity.RIGHT); }else { layoutDown.setPadding(150, 10, 0, 0); textSms.setBackgroundResource(R.drawable.bg_out_rectangle_green_normal); //textSms.setGravity(Gravity.RIGHT); layoutDown.setGravity(Gravity.RIGHT); } } layout.addView(layoutUp); layout.addView(layoutDown); //return super.GetView(context); return layout; } }