package com.tcl.factory.view;

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

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

import com.tcl.customerapi.R;
import com.tcl.factory.bsp.TV;
import com.tcl.factory.bsp.TVDefine;
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 FrontPanelKeyTest extends Activity {
	private String TAG = this.getClass().getName();
	
	public static FrontPanelKeyTest _Instance = null;
	public RelativeLayout backGroundColor=null;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		//���밴�����ģʽʱ�˳�menuhelp,�����ܵ�ѹ���㵼�°����жϴ���,�ڵ���menuhelp������½�����
	    Intent intent_hideMenuhelp = new Intent("com.tcl.m.MenuBroadcastReceiver");//zhifeng.huang 
	    intent_hideMenuhelp.putExtra("key", "hide"); 
	    sendBroadcast(intent_hideMenuhelp);

		this.setContentView(R.layout.fac_warmup);
		backGroundColor=(RelativeLayout)findViewById(R.id.backgroud_layout);
		
		backGroundColor.setBackgroundResource(R.color.cyan_color);

		_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){
			if(TV.readS(TVDefine.KeyCodeTest))
			{
				setBackGroundColor(keyCode);//for frontkey test 
				return true;
			}
		}
		
		return true;
	}

	public void setBackGroundColor(int keyCode) {
		int colorId = R.color.transparent;
		Debug.v(TAG , "[KeyCodeTestsetBackGroundColor]");
//		if((keyCode&0xff00) == 0x0) {
//			switch (keyCode&0xff) {
//			case KeyMap.KEYCODE_POWER:
//				colorId = R.color.red_color;
//				break;
//			case KeyMap.KEYCODE_HOME:
//				colorId = R.color.green_color;
//				break;
//			case KeyMap.KEYCODE_CH_DOWN://
//				colorId = R.color.black_color;
//				break;
//			case KeyMap.KEYCODE_VOL_DEC:
//				colorId = R.color.blue_color;
//				break;
//			case KeyMap.KEYCODE_VOL_ADD:
//				colorId = R.color.white_color;
//				break;
//			case KeyMap.KEYCODE_CH_UP:
//				colorId = R.color.gray_color;
//				break;
//			case KeyMap.KEYCODE_ENTER:
//				colorId = R.color.pink_color;
//				break;
//			default:
//				colorId = R.color.transparent;
//			}
//		}
//		else //�����ʽģʽֻ��Ӧ��尴??
		if((keyCode&0xff00) == 0x7f00) {
			switch (keyCode&0xff) {
			case KeyMap.KEYCODE_DPAD_UP:
				colorId = R.color.gray_color;
				break;
			case KeyMap.KEYCODE_DPAD_DOWN:
				colorId = R.color.black_color;
				break;
			case KeyMap.KEYCODE_DPAD_RIGHT:
				colorId = R.color.white_color;
				break;
			case KeyMap.KEYCODE_DPAD_LEFT:
				colorId = R.color.yellow_color;
				break;
			case KeyMap.KEYCODE_DPAD_CENTER:
				colorId = R.color.pink_color;
				break;
			case KeyMap.KEYCODE_POWER:
				colorId = R.color.red_color;
				break;
			case KeyMap.KEYCODE_HOME:
			case KeyEvent.KEYCODE_MENU:
				colorId = R.color.green_color;
				break;
			default:
				colorId = R.color.transparent;
			}
			backGroundColor.setBackgroundResource(colorId);
			backGroundColor.setVisibility(View.VISIBLE);
		}
	}
}