package com.usai.apex;

//import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
//import android.app.Fragment;
//import android.app.FragmentTransaction;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;
import android.view.Menu;
import android.widget.TabHost;

public class ApexActivity extends FragmentActivity /*implements OnTabChangeListener*/
{

	TabHost mTabHost;
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_apex);
		setupTabs();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu)
	{
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.apex, menu);
		return true;
	}
    private void setupTabs() {
        mTabHost = (TabHost) this.findViewById(R.id.tabhost);
        
        mTabHost.setup();
//        // 生成底部自定义样式的按钮
//        String[] title = new String[] { "Login", "Not login" };
//        int[] tabIds = new int[] { R.id.tab1, R.id.tab2 };
        mTabHost.addTab(mTabHost.newTabSpec("Login").setIndicator("Login").setContent(R.id.tab1));
//        mTabHost.addTab(mTabHost.newTabSpec("Direct Tracking").setIndicator("Direct Tracking").setContent(R.id.tab2));
        mTabHost.addTab(mTabHost.newTabSpec("Service Location").setIndicator("Service Location").setContent(R.id.tab3));
        
		//FragmentManager manager = this.getFragmentManager();
	   
	    // Instantiate a new fragment.
	    Fragment loginFragment = new LoginFragment();
	    Fragment dtFragement = new DirectTrackingFragment();
	    Fragment slFragment=  new ServiceLocationFragment();
	    // Add the fragment to the activity, pushing this transaction
	    // on to the back stack.
	    
	    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
	    ft.replace(R.id.tab1, loginFragment);
	    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	    ft.addToBackStack("Login");
	    
//	    ft.replace(R.id.tab2, dtFragement);
//	    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
//	    ft.addToBackStack("Tracking");

	    ft.replace(R.id.tab3, (Fragment)slFragment);
	    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
	    ft.addToBackStack("Location");
	    
	    ft.commit();

//		if (manager.findFragmentByTag(tabId) == null)
//		{
//			FragmentTransaction trans = manager.beginTransaction();
//			trans.replace(contentViewID, frag, tabId);
//			trans.commit();
//		}
//        for (int i = 0; i < title.length; i++) {
//            Button button = new Button(this);
//            button.setText(title[i]);
//            button.setBackgroundDrawable(this.getResources().getDrawable(
//                    R.drawable.tab_lable));  //自定义按钮样式
//            mTabHost.addTab(mTabHost.newTabSpec(title[i]).setIndicator(button)
//                    .setContent(tabIds[i]));
//        }

    //    mTabHost.setOnTabChangedListener(this);
    }

//	@Override
//	public void onTabChanged(String tabId)
//	{
		// TODO Auto-generated method stub
//        Fragment frag = null;
//        int contentViewID = 0;
//        if (tabId.equals("Login")) {
//            frag = new LoginFragment(); //自定义继承Fragment的UI，放了一个简单的显示文本标题的控件。
//            contentViewID = R.id.tab1;
//        } else if (tabId.equals("Not login")) {
//            frag = new DirectTrackingFragment();
//            contentViewID = R.id.tab2;
//        }
//        if (frag == null)
//            return;
//
//        FragmentManager manager = this.getFragmentManager();
//
//        if (manager.findFragmentByTag(tabId) == null) {
//            FragmentTransaction trans = manager.beginTransaction();
//            trans.replace(contentViewID, frag, tabId);
//            trans.commit();
//        }		
//	}
//	public class LoginFragment extends Fragment implements OnClickListener{
//	    @Override
//	    public View onCreateView(LayoutInflater inflater, ViewGroup container,
//	                    Bundle savedInstanceState) {
//	        View view = inflater.inflate(R.layout.activity_login, null);
//	        Button btn = (Button)view.findViewById(R.id.sign_in_button);
//	        btn.setOnClickListener(this);
//	        return view;
//	    }
//
//		@Override
//		public void onClick(View v)
//		{
//			// TODO Auto-generated method stub
//			
//		}
//	}
}
