package com.tcl.factory.view;

//import com.mediatek.tv.common.ConfigType;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.RelativeLayout;

import com.tcl.customerapi.R;
import com.tcl.factory.bsp.TCL;
import com.tcl.factory.def.DEFS;
import com.tcl.factory.def.KeyMap;
import com.tcl.factory.thirdparty.ThirdParty;
import com.tcl.factory.utils.Debug;

public class TestPattern extends Activity {
	private String TAG = this.getClass().getName();
	
	
	public static TestPattern _Instance = null;
	private RelativeLayout backGroundColor=null;
	
	private int pannelTestcolorId = 0;
	private int colorIDIndexTable[]={
		R.drawable.hd_15circle,
		R.color.white_color,
		R.color.white0_2_color,
		R.color.black_color,
		R.color.red_color,
		R.color.green_color,
		R.color.blue_color,
		R.drawable.trianglegrey,
		R.drawable.picpalette
	};

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.fac_warmup);
		backGroundColor=(RelativeLayout)findViewById(R.id.backgroud_layout);

		backGroundColor.setBackgroundResource(R.drawable.hd_15circle);

		_Instance = this;
	}
	@Override
	 public void onAttachedToWindow(){
//		TV.APPKeyGuard(DEFS.Enable);
		super.onAttachedToWindow();
	 }
	
	@Override
	protected void onStart() {
		Debug.v(TAG, "onStart");
		ThirdParty.setNatureLightEnabled(DEFS.Disable);
		ThirdParty.setGraphicBacklight(100);
		ThirdParty.sendMsgToDBC(0);
		super.onStart();
	}
	@Override
	protected void onDestroy() {
		Debug.v(TAG, "onDestroy");
		backGroundColor.setBackgroundResource(R.color.transparent);
		super.onDestroy();
	}
	@Override
	public boolean dispatchKeyEvent(KeyEvent event) {
		Debug.v(TAG , "dispatchKeyEvent : event.getAction() = " + event.getAction() + ", event.getKeyCode() = " + event.getKeyCode());
		int keyCode = event.getKeyCode();
		int cmd_data=(keyCode&0xff00)>>8;
		

		if(event.getAction() == KeyEvent.ACTION_DOWN){
			setBackGroundColor(keyCode);
			return true;
		}
		
		return true;
	}
	public void setBackGroundColor(int keyCode) {
		Debug.v(TAG , "[pannelTestsetBackGroundColor]");
		if((keyCode&0xff00) == 0x0) {
			switch (keyCode&0xff) {
			case KeyMap.KEYCODE_CHDN://
				pannelTestcolorId--;
				break;
			case KeyMap.KEYCODE_CHUP:
				pannelTestcolorId++;
				break;
			}
			
			if(pannelTestcolorId<0)pannelTestcolorId = colorIDIndexTable.length-1;
			else if(pannelTestcolorId >= colorIDIndexTable.length)pannelTestcolorId = 0;
			
			backGroundColor.setBackgroundResource(colorIDIndexTable[pannelTestcolorId]);
		}
	}
	
	public void setTestPatternColor(int colorIDIndexTable_index)
	{
	 
		if(colorIDIndexTable_index < 0 || colorIDIndexTable_index > 8)
			return ;
		
		if(TCL.getTestPatternStatus()  == false)
			return;
		boolean erro=false;
		while(!erro)
		{
		  try
		  {
				backGroundColor.setBackgroundResource(colorIDIndexTable[colorIDIndexTable_index]);
				erro=true;
		  }
		  catch(java.lang.OutOfMemoryError e)
		  {
			   Debug.v(TAG, "OUT OF memery");
		  }
		}
	}
}
