package com.android.example.uis;

import java.lang.reflect.Method;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.MenuItem;

public class IndexActivity extends FragmentActivity implements ActionBar.TabListener{
    
	private Fragment1 mFragment1 = new Fragment1();
	private Fragment2 mFragment2 = new Fragment2();
	private Fragment3 mFragment3 = new Fragment3();
	
	private static final int TAB_INDEX_COUNT = 3;
	
	private static final int TAB_INDEX_ONE = 0;
	private static final int TAB_INDEX_TWO = 1;
	private static final int TAB_INDEX_THREE = 2;
	
	private ViewPager mViewPager;
	private ViewPagerAdapter mViewPagerAdapter;
	
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        setUpActionBar();
        setUpViewPager();
        setUpTabs();
        ActivityCollector.addActivity(this);
    }
    
    private void setUpActionBar() {
    	final ActionBar actionBar = getActionBar();
    	actionBar.setHomeButtonEnabled(true);
    	actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    	actionBar.setDisplayShowTitleEnabled(false);
    	actionBar.setDisplayShowHomeEnabled(true);
    	
    	
    	
    	
    	try {  
            Method setHasEmbeddedTabsMethod = actionBar.getClass().getDeclaredMethod(  
                    "setHasEmbeddedTabs", boolean.class);  
            setHasEmbeddedTabsMethod.setAccessible(true);  
            setHasEmbeddedTabsMethod.invoke(actionBar, true);  
        } catch (Exception ignore) {  
        }  
    	
    	
    	Resources r = getResources();
    	Drawable myDrawable = r.getDrawable(R.drawable.logo2);
//    	actionBar.setBackgroundDrawable(myDra/wable);
    	actionBar.setLogo(myDrawable);
    	
    }
    

    @Override
	public boolean onMenuItemSelected(int featureId, MenuItem item) {
    	Log.d("--------start-----", "onMenuItemSelected");
    	 switch (item.getItemId()) {  
    	    case android.R.id.home:  
    	    	Log.d("--------------", "onMenuItemSelected");
//    	        Toast.makeText(this, "onMenuItemSelected", Toast.LENGTH_SHORT).show();  
    	    	Intent intent = new Intent(this, SettingActivity.class);
    	    	startActivity(intent);
    	    	finish();
    	    	return true;
    	    default:  
    	    	return super.onMenuItemSelected(featureId, item);
    	 }
	} 
    /**
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Log.d("--------start-----", "onOptionsItemSelected");
		 switch (item.getItemId()) {  
		    case android.R.id.home:  
		    	Log.d("--------------", "onOptionsItemSelected");
		        Toast.makeText(this, "onOptionsItemSelected", Toast.LENGTH_SHORT).show();  
		        return true;  
		    default:  
		return super.onOptionsItemSelected(item);
		 }
	}
*/
	private void setUpViewPager() {
    	mViewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    	
    	mViewPager = (ViewPager)findViewById(R.id.pager);
    	mViewPager.setAdapter(mViewPagerAdapter);
    	mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
    		@Override
    		public void onPageSelected(int position) {
    			final ActionBar actionBar = getActionBar();
    			actionBar.setSelectedNavigationItem(position);
    		}
    		
    		@Override
    		public void onPageScrollStateChanged(int state) {
    			switch(state) {
    				case ViewPager.SCROLL_STATE_IDLE:
    					//TODO
    					break;
    				case ViewPager.SCROLL_STATE_DRAGGING:
    					//TODO
    					break;
    				case ViewPager.SCROLL_STATE_SETTLING:
    					//TODO
    					break;
    				default:
    					//TODO
    					break;
    			}
    		}
    	});
    }
    
    private void setUpTabs() {
    	final ActionBar actionBar = getActionBar();
    	for (int i = 0; i < mViewPagerAdapter.getCount(); ++i) {
    		actionBar.addTab(actionBar.newTab()
    				.setText(mViewPagerAdapter.getPageTitle(i))
    				.setTabListener(this));
    	}
    	
    }
    
    
    public class ViewPagerAdapter extends FragmentPagerAdapter {

		public ViewPagerAdapter(FragmentManager fm) {
			super(fm);
			// TODO Auto-generated constructor stub
		}

		@Override
		public Fragment getItem(int position) {
			// TODO Auto-generated method stub
			switch (position) {
				case TAB_INDEX_ONE:
					return mFragment1;
				case TAB_INDEX_TWO:
					return mFragment2;
				case TAB_INDEX_THREE:
					return mFragment3;
			}
			throw new IllegalStateException("No fragment at position " + position);
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return TAB_INDEX_COUNT;
		}
    	
		@Override
		public CharSequence getPageTitle(int position) {
			String tabLabel = null;
			switch (position) {
				case TAB_INDEX_ONE:
					tabLabel = getString(R.string.tab_1);
					break;
				case TAB_INDEX_TWO:
					tabLabel = getString(R.string.tab_2);
					break;
				case TAB_INDEX_THREE:
					tabLabel = getString(R.string.tab_3);
					break;
			}
			return tabLabel;
		}
    }

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		mViewPager.setCurrentItem(tab.getPosition());
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
		ActivityCollector.removeActivity(this);
	}
}
@@ -5082,46 +5082,8 @@
 ) %7B%0A
-%09%09%09// TODO Auto-generated method stub%0A
 %09%09%09r
@@ -6012,8 +6012,9 @@
 s);%0A%09%7D%0A%7D
+%0A

Update IndexActivity.java