text: package com.sina.util.dnscache.tab;
  
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.view.View;
  import android.widget.ImageButton;
  
  import com.sina.util.dnscache.tab.R;
  
  
  public class DNSCacheTestActivityTabMain extends FragmentActivity {
  	
      protected static final String TAG = "MainActivity";
      
      private View currentButton;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
          initComponents();
  
      }
  
      private void initComponents() {
      	
          ImageButton btn_simulation_task = (ImageButton) findViewById(R.id.buttom_simulation_task);
          ImageButton btn_task_setting = (ImageButton) findViewById(R.id.buttom_task_setting);
          ImageButton btn_data_graph = (ImageButton) findViewById(R.id.buttom_data_graph);
          ImageButton btn_cache_data = (ImageButton) findViewById(R.id.buttom_cache_data);
  
          btn_simulation_task.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
                  FragmentManager fm = getSupportFragmentManager();
                  FragmentTransaction ft = fm.beginTransaction();
                  SimulationTaskFragment fragment_one = new SimulationTaskFragment();
                  ft.replace(R.id.fl_content, fragment_one, DNSCacheTestActivityTabMain.TAG);
                  ft.commit();
                  setButton(v);
  
              }
          });
  
          btn_task_setting.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  FragmentManager fm = getSupportFragmentManager();
                  FragmentTransaction ft = fm.beginTransaction();
                  TaskSettingFragment fragment_two = new TaskSettingFragment();
                  ft.replace(R.id.fl_content, fragment_two, DNSCacheTestActivityTabMain.TAG);
                  ft.commit();
                  setButton(v);
  
              }
          });
  
  
          btn_data_graph.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  FragmentManager fm = getSupportFragmentManager();
                  FragmentTransaction ft = fm.beginTransaction();
                  DataGraphFragment fragment_three = new DataGraphFragment();
                  ft.replace(R.id.fl_content, fragment_three, DNSCacheTestActivityTabMain.TAG);
                  ft.commit();
                  setButton(v);
              }
          });
          
          btn_cache_data.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  FragmentManager fm = getSupportFragmentManager();
                  FragmentTransaction ft = fm.beginTransaction();
                  DataGraphFragment fragment_three = new DataGraphFragment();
                  ft.replace(R.id.fl_content, fragment_three, DNSCacheTestActivityTabMain.TAG);
                  ft.commit();
                  setButton(v);
              }
          });
          
  
          /**
           * 默认第一个按钮点击
           */
          btn_simulation_task.performClick();
  
      }
  
      /**
       * 设置按钮的背景图片
       *
       * @param v
       */
      private void setButton(View v) {
          if (currentButton != null && currentButton.getId() != v.getId()) {
              currentButton.setEnabled(true);
          }
          v.setEnabled(false);
          currentButton = v;
      }
  
  
  }
  