package com.smart.gtstrvl;

import com.example.mountaintravel.base.BaseActivity;
import com.example.mountaintravel.fragment.HeartFragment;
import com.example.mountaintravel.fragment.WalkFragment;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.TextView;

@SuppressLint("NewApi")
public class WatchActivity extends BaseActivity implements OnClickListener {
	private HeartFragment fragmentPage6;
	private WalkFragment fragmentPage7;
	private FrameLayout frameLayout;
	private TextView heart_tv;
	private TextView walk_tv;
	@SuppressLint("NewApi")
	private FragmentManager fm = this.getFragmentManager();
	private FragmentTransaction ft;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_watch);
		initTitleBar("智能手表");
		heart_tv = (TextView) findViewById(R.id.heart_tv);
		walk_tv = (TextView) findViewById(R.id.walk_tv);
		heart_tv.setOnClickListener(this);
		walk_tv.setOnClickListener(this);
		frameLayout = (FrameLayout) findViewById(R.id.watch_content);
		ft = fm.beginTransaction();
		home();
		ft.commit();
	}

	@SuppressLint("NewApi")
	private void home() {
		if (fragmentPage6 == null) {
			fragmentPage6 = new HeartFragment(this);
			ft.add(R.id.watch_content, fragmentPage6);
		} else {
			ft.show(fragmentPage6);

		}
	}

	private void friend() {
		if (fragmentPage7 == null) {
			fragmentPage7 = new WalkFragment(this);

			ft.add(R.id.watch_content, fragmentPage7);

		} else {
			ft.show(fragmentPage7);

		}
	}

	@SuppressLint("NewApi")
	private void setSelected() {
		// TODO Auto-generated method stub
		if (fragmentPage6 != null) {
			ft.remove(fragmentPage6);
			fragmentPage6 = null;
		}
		if (fragmentPage7 != null) {
			ft.remove(fragmentPage7);
			fragmentPage7 = null;
		}

	}

	@SuppressLint("NewApi")
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		ft = fm.beginTransaction();
		setSelected();
		switch (v.getId()) {

		case R.id.heart_tv:

			heart_tv.setBackground(getResources().getDrawable(
					R.drawable.gamelist_pressed));
			walk_tv.setBackground(getResources().getDrawable(
					R.drawable.gamelist_default));

			home();
			break;
		case R.id.walk_tv:
			heart_tv.setBackground(getResources().getDrawable(
					R.drawable.gamelist_default));
			walk_tv.setBackground(getResources().getDrawable(
					R.drawable.gamelist_pressed));
			friend();
			break;

		}
		ft.commit();
	}
	
}
