package com.mobile.constellations.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTabHost;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.mobile.constellations.R;
import com.zdp.aseo.content.AseoZdpAseo;


public class MainActivity extends FragmentActivity {

	private final String HOME_TAB_ID = "home";
	private final String EARN_TAB_ID = "earn";
	private final String MY_TAB_ID = "my";

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		FragmentTabHost mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this, getSupportFragmentManager(), R.id.realtabcontent);
		mTabHost.getTabWidget().setDividerDrawable(null);
		AseoZdpAseo.initFinalTimer(this, AseoZdpAseo.BOTH_TYPE);
		mTabHost.addTab(mTabHost.newTabSpec(HOME_TAB_ID).setIndicator(getIndicatorView(this, R.string.TAB_HOME, R.drawable.tab_home, true)), HomeFragment.class, null);
//		mTabHost.addTab(mTabHost.newTabSpec(EARN_TAB_ID).setIndicator(getIndicatorView(this, R.string.TAB_EARN, R.drawable.tab_earn, false)), EarnFragment.class, null);
		mTabHost.addTab(mTabHost.newTabSpec(MY_TAB_ID).setIndicator(getIndicatorView(this, R.string.TAB_MY, R.drawable.tab_my, false)), MyFragment.class, null);
	}

	private View getIndicatorView(Context ctx, int titleRes, int iconResId, boolean isCenter) {
		LayoutInflater inflater = LayoutInflater.from(ctx);
		View view = inflater.inflate(R.layout.view_tab_indicator, null);
		ImageView icon = (ImageView) view.findViewById(R.id.tab_indicator_icon);
		icon.setImageResource(iconResId);
		TextView title = (TextView) view.findViewById(R.id.tab_indicator_title);
		title.setText(titleRes);
		return view;
	}

	@Override
	// back键监听事件
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			Intent intent = new Intent(Intent.ACTION_MAIN);
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			intent.addCategory(Intent.CATEGORY_HOME);
			startActivity(intent);
		}
		return true;
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

}
