package com.sogouchat.popnewmsg;
import java.util.Vector;
import com.sogouchat.R;
import com.sogouchat.os.SmsService;
import android.app.TabActivity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.ViewPager.LayoutParams;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabSpec;
import android.widget.Toast;
public class MultiPopTabActivity extends TabActivity implements OnTabChangeListener{
public static String S_TITLE = "s_title";
public static String S_DATE = "s_date";
private PopConversation conversation1;
private PopConversationView popConversationView;
private PopConversationMgr mgr;
private LayoutInflater inflater;
private TabHost mTabHost;
private MessageRecr messageRecr;
class MessageRecr extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if (intent.getAction().equals(SmsService.ACTION_POSTTONEW_MSG)) {
String strNumberNext = intent.getStringExtra(SmsService.SMS_NUMBER);
String strBody = intent.getStringExtra(SmsService.SMS_BODY);
mgr.addNewMessage(strNumberNext, strBody);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
messageRecr = new MessageRecr();
IntentFilter intentFilter = new IntentFilter(SmsService.ACTION_POSTTONEW_MSG);
registerReceiver(messageRecr, intentFilter);
mTabHost = getTabHost();
inflater = LayoutInflater.from(this);
mTabHost.setOnTabChangedListener(this);
PopConversationMgr.GetI().Init(this);
mgr = PopConversationMgr.GetI();
if (getIntent()!=null) {
String strTitle = getIntent().getStringExtra(S_TITLE);
String strDate = getIntent().getStringExtra(S_DATE);
mgr.addNewMessage(strTitle, strDate);
}
// mgr.addNewMessage("10010","hello!");
// mgr.addNewMessage("10010","hi!");
// mgr.addNewMessage("10010","hello!");
// mgr.addNewMessage("10010","hi!");
// //mgr.addNewMessage("10086","hello!10086");
// //mgr.addNewMessage("10075","hello!10075");
// mTabHost.setOnTabChangedListener(this);
//
//
// new Handler().postDelayed(new Runnable() {
// public void run() {
// mgr.addNewMessage("10010","hi!");
// }
// }, 1000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// mgr.addNewMessage("10010","hi!");
// }
// }, 2000);
// new Handler().postDelayed(new Runnable() {
// public void run() {
// mgr.addNewMessage("10086","hi!");
// UpdateCurrent();
// }
// }, 3000);
}
public void onTabChanged(String tabId) {
// TODO Auto-generated method stub
//getTabHost().getTabContentView().
PopConversation popConversation = mgr.findItemByNumber(tabId);
if (popConversation!=null) {
//PopConversationView popConversationView = (PopConversationView)getTabHost().getChildAt(mgr.popConversations.size()).findViewById(R.id.pop_tab_item_layout);
//popConversationView.SetPopConversation(popConversation);
//popConversationView.Update();
for (int i = 0; i < getTabHost().getTabContentView().getChildCount(); i++) {
PopConversationView popConversationView = (PopConversationView)getTabHost().getTabContentView().getChildAt(i).findViewById(R.id.pop_tab_item_layout);
popConversationView.SetPopConversation(popConversation);
}
}
}
public void UpdateCurrent(){
String tabId = mTabHost.getCurrentTabTag();
PopConversation popConversation = mgr.findItemByNumber(tabId);
if (popConversation.strShow.equals(tabId) && popConversation!=null) {
//PopConversationView popConversationView = (PopConversationView)getTabHost().getTabContentView().getChildAt(popConversation.nIndex).findViewById(R.id.pop_tab_item_layout);
//popConversationView.SetPopConversation(popConversation);
for (int i = 0; i < getTabHost().getTabContentView().getChildCount(); i++) {
PopConversationView popConversationView = (PopConversationView)getTabHost().getTabContentView().getChildAt(i).findViewById(R.id.pop_tab_item_layout);
popConversationView.SetPopConversation(popConversation);
}
//popConversationView.Update();
}
}
public void addNewTab(PopConversation popConversation) {
// TODO Auto-generated method stub
View view = inflater.inflate(R.layout.pop_messag_item,getTabHost().getTabContentView());
TabSpec tabSpec = getTabHost().newTabSpec(popConversation.strShow);
tabSpec.setContent(R.id.pop_tab_item_layout);
tabSpec.setIndicator(popConversation.strShow);
popConversationView = (PopConversationView)view.findViewById(R.id.pop_tab_item_layout);
popConversationView.SetPopConversation(popConversation);
getTabHost().addTab(tabSpec);
}
public void Update(PopConversation popConversation2) {
// TODO Auto-generated method stub
String tabId = mTabHost.getCurrentTabTag();
// if (popConversation.strShow.equals(tabId) && popConversation!=null) {
// PopConversationView popConversationView = (PopConversationView)getTabHost().getTabContentView().getChildAt(popConversation.nIndex).findViewById(R.id.pop_tab_item_layout);
// popConversationView.SetPopConversation(popConversation);
// popConversationView.Update();
// }
PopConversation popConversation = mgr.findItemByNumber(tabId);
for (int i = 0; i < getTabHost().getTabContentView().getChildCount(); i++) {
PopConversationView popConversationView = (PopConversationView)getTabHost().getTabContentView().getChildAt(i).findViewById(R.id.pop_tab_item_layout);
popConversationView.SetPopConversation(popConversation);
}
}
public void DeleteTab() {
// TODO Auto-generated method stub
int nCount = mTabHost.getTabContentView().getChildCount();
if (nCount==1) {
this.finish();
}else if(nCount>1) {
mTabHost.setCurrentTab(0);
mTabHost.clearAllTabs();
//mgr.addNewAll();
}
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
unregisterReceiver(messageRecr);
super.onDestroy();
}
}