package com.example.source;

import android.os.Bundle;
import android.app.Activity;
import android.app.TvManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.*;




public class MainActivity extends Activity implements OnClickListener {

	
	
	
	private Button mybutton ;
	private Button mybutton2 ;
	private Button mybutton3 ;
	private Button mybutton4 ;
	private Button mybutton5 ;
	
	private TvManager myTvManager;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		myTvManager = (TvManager)MainActivity.this.getSystemService(Context.TV_SERVICE);
		
		Button mybutton = (Button)findViewById(R.id.button1);
		Button mybutton2 = (Button)findViewById(R.id.button2);
		Button mybutton3 = (Button)findViewById(R.id.button3);
		Button mybutton4 = (Button)findViewById(R.id.button4);
		Button mybutton5 = (Button)findViewById(R.id.button5);
		mybutton2.setOnClickListener(this);
		mybutton3.setOnClickListener(this);
		mybutton4.setOnClickListener(this);
		mybutton5.setOnClickListener(this);
		mybutton.setOnClickListener( new OnClickListener() {	
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				startTSB_TV();
				Log.d("yushuo"," onClick(View arg0) {");
					
				myTvManager.setSource(TvManager.SOURCE_DTV1);
				
			}
		});
	
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

	@Override
	public void onClick(View arg0) {
		// TODO Auto-generated method stub
		Log.d("yushuo"," onClick(View arg+"+arg0);
		startTSB_TV();
		switch (arg0.getId()) {
		case R.id.button2:
			
			Log.d("yushuo"," R.id.button2");
			myTvManager.setSource(TvManager.SOURCE_DTV2);
			break;
		case R.id.button3:
			Log.d("yushuo"," R.id.button3");
		myTvManager.setSource(TvManager.SOURCE_HDMI1);	
				break;
	
	case R.id.button4:
		Log.d("yushuo"," R.id.button4");
		myTvManager.setSource(TvManager.SOURCE_PLAYBACK);
		break;
	
	case R.id.button5:
		Log.d("yushuo"," R.id.button5");
		myTvManager.setSource(TvManager.SOURCE_ATV1);
	break;


		default:
			break;
		}
		
	}
	public void startTSB_TV() {
		Log.d("yuanqi", "========================startTSB_TV");
        Intent intentTV = new Intent();
        ComponentName tsbTvName = new ComponentName("com.tsb.tv", "com.tsb.tv.Tv_strategy");
        intentTV.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intentTV.setComponent(tsbTvName);
        startActivity(intentTV);
    }    

}
