package com.tcl.factory.ir;


import java.util.Locale;

import android.app.ActivityManagerNative;
import android.app.IActivityManager;
import android.content.Context;
import android.content.res.Configuration;
import android.os.SystemProperties;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

import com.tcl.deviceinfo.TDeviceInfo;
import com.tcl.factory.bsp.TCL;
import com.tcl.factory.bsp.TV;
import com.tcl.factory.bsp.TVDefine;
import com.tcl.factory.def.DEFS;
import com.tcl.factory.thirdparty.ThirdParty;
import com.tcl.factory.utils.Debug;
import com.tcl.factory.utils.Utils;


public class IRManager {

	private static String TAG = "IRManager";
	private static int CMD_PANELKEY = 0x7f;

	public static void parser(int keyCode)
	{
		
//		if(keyCode == KeyMap.KEYCODE_P_ON) 
//		{ 
//			TV.writeS(TVDefine.PMode, DEFS.Enable);
// 			return;
//		}
//		if(keyCode==KeyMap.KEYCODE_P_OFF)  
//		{
//			TV.writeS(TVDefine.PMode, DEFS.Disable);
//			TV.writeS(TVDefine.DMode, DEFS.Disable);
//			SerialManager.mUiSLsner.onChange(DEFS.EXIT_APP);
//  			return;
//		}
	 
		if(true){
//			keyCode=TV.readV(TVDefine.SidePanelKeyCode)&0xffff;
			int cmd_data=(keyCode&0xff00)>>8;
			keyCode=keyCode&0x00ff;
			
			Debug.v(TAG, "cmd_data=="+cmd_data+"keyCode=" +keyCode);
			
			if(0x7f==cmd_data){ //panelKey
				switch(keyCode){
				case KeyEvent.KEYCODE_DPAD_UP:
					break;
				case KeyEvent.KEYCODE_DPAD_DOWN:
					break;
				case KeyEvent.KEYCODE_DPAD_RIGHT:
					break;
				case KeyEvent.KEYCODE_DPAD_LEFT:
					break;
				case KeyEvent.KEYCODE_DPAD_CENTER:
					break;
				case KeyEvent.KEYCODE_POWER:
					break;
				case KeyEvent.KEYCODE_HOME:
					break;
				}
			}
			
			switch(cmd_data)
			{

			case 0x05:
				switch(keyCode)
				{
				case 45://鏉╂瑤閲滈幐澶愭暛閺�鏈电瑝閿燂拷?
					TV.writeS(TVDefine.PMode, DEFS.Enable);
					TCL.setInfoDisServiceEnable(DEFS.Enable);
  					break;
				case 63:
					TV.writeS(TVDefine.PMode, DEFS.Disable);
					TV.writeS(TVDefine.DMode, DEFS.Disable);
					TCL.setFacInfoShowEnable(DEFS.Disable);
					TCL.setInfoDisServiceEnable(DEFS.Disable);
					break;
				case 24:
					TV.writeV(TVDefine.WhiteBalance);
  					break;
				case 25:
					int mode = TV.readV(TVDefine.PictureFormat);
					mode--;
					if(mode < 1)
						mode=2;
 					TV.writeV(TVDefine.PictureFormat, mode);
					break;
				}
				break;
			case 0x06:
				switch(keyCode)
				{
				case 20: 
					TV.writeS(TVDefine.KeyCodeTest, DEFS.Disable);	 
					TV.writeS(TVDefine.WarmUP, DEFS.Enable);
					break;
				case 21: 
					TV.writeS(TVDefine.WarmUP, DEFS.Disable);
					break;
				case 22:
					TV.writeS(TVDefine.KeyCodeTest, DEFS.Enable);	 
					break;
				case 23: 
					TV.writeS(TVDefine.KeyCodeTest, DEFS.Disable);	 
					break;
				case 28: 
					TV.readS(TVDefine.DeviceID);
					break;
				case 29: 
					if(TV.readS(TVDefine.NetworkConnectivity) )
					{
						TCL.getPcLinkStatus(false); 
					}
					else
					{						
						TCL.setWifiLink();
					}
					break;
				case 45: //鏉╂瑤閲滈幐澶愭暛閺�鏈电瑝閿燂拷?
					TV.writeS(TVDefine.PMode, DEFS.Enable);
 					break;
				case 46: 
					TV.writeV(TVDefine.ShopInit);
 					break;
				case 47:
//					Context mContext = null;
//					Toast.makeText(mContext, "NVM and ShutDown", 3000).show();
					TV.writeV(TVDefine.NVMReSet);
					break;
				case 127:	
					if(DEFS.RATTLE_ON_OFF ==0 ){
						TV.setSource(DEFS.SOURCE_ATV, 0);
						TV.writeV(TVDefine.AudioMode, 1);
						TV.writeV(TVDefine.AudioBalance, 0);					
						TV.writeV(TVDefine.ChannelSet, 0);
					}else {
						TV.writeV(TVDefine.ChannelSet, 1);
					}
 					break;
				}
				break;
			case 7: 
				switch(keyCode)
				{
				case 143://rtk only
					TV.writeS(TVDefine.KeyCodeTest, DEFS.Disable);
	 				break;
				case 58: //rtk only
					TV.writeV(TVDefine.ShopInit);
					break;
				default:
					TV.writeV(TVDefine.AudioBalance, keyCode);
				}
				break;
			case 8:
				switch(keyCode)
				{ 
				case 1:	
					TV.setSource(DEFS.SOURCE_AV, 1);
					break;  	 
				case 2: 
					TV.setSource(DEFS.SOURCE_AV, 2);
 					break;  
				case 3: 
 					break;  
				case 4: 
 					break;  
				case 5:	
					TV.setSource(DEFS.SOURCE_YPBPR, 1);
 					break;  
				case 6:	
					TV.setSource(DEFS.SOURCE_YPBPR, 2);
 					break;  
				case 7: 
					TV.setSource(DEFS.SOURCE_VGA, 1);
 					break;  
				case 8: 
					TV.setSource(DEFS.SOURCE_HDMI, 1);
  					break; 
				case 9: 
					TV.setSource(DEFS.SOURCE_HDMI, 2);
					break; 
				case 10: 
					TV.setSource(DEFS.SOURCE_HDMI, 3);
					break; 
				case 11: 
					TV.setSource(DEFS.SOURCE_HDMI, 4);
					break; 
				case 12: 
					Utils.intentHandler(DEFS.Package_TCL_FileExplorer, DEFS.Activity_TCL_FileExplorer );
					break;
 				case 20:  
 					TCL.setSerInfoShowEnable(DEFS.Enable);
 					break;
   				case 21: 
   					TCL.setSerInfoShowEnable(DEFS.Disable);                                      
 					break; 
				case 22:	 
 					//TV.writeS(TVDefine.AudioMute, DEFS.Enable);
					ThirdParty.setAudioMuteStatusVisible(DEFS.Enable);
 					break;
 				case 23:		 
 					//TV.writeS(TVDefine.AudioMute, DEFS.Disable);
 					ThirdParty.setAudioMuteStatusVisible(DEFS.Disable);
 					break;
 				case 24:
 					TCL.AsyncEnableKaraoke(DEFS.COMMON_ON);
 					break;
 				case 25:
 					TCL.AsyncEnableKaraoke(DEFS.COMMON_OFF);
 					break;
				case 40:	 
					int typeValue = TV.readV(TVDefine.ColorTemperature);
					typeValue--;
					if(typeValue < 1)
						typeValue=3;
					TV.writeV(TVDefine.ColorTemperature, typeValue);
 					break;
				case 61:
					TV.writeS(TVDefine.ThreeDMode, DEFS.Enable);
					break;
				case 62: 
					TV.writeS(TVDefine.ThreeDMode, DEFS.Disable);
					break;
				case 71: 
					TCL.setTestPatternStatus(true);
					break;
				case 72: 
					TCL.setTestPatternStatus(false);
					break;
				}
				break;
			case 9: 
				switch(keyCode)
				{
				case 143://rtk only
					//TV.writeS(TVDefine.AudioMute, DEFS.Disable);
					ThirdParty.setAudioMuteStatusVisible(DEFS.Disable);
	 				break;
				case 52://rtk only
					TCL.AsyncEnableKaraoke(DEFS.COMMON_ON);
	 				break;
				case 144://rtk only
					//Game
	 				break;
				default:
					TV.writeV(TVDefine.AudioVolume, 30);
				}
 				break;

			case 11: 				
				if(!TV.getSourceType().equalsIgnoreCase(DEFS.ATV))
					TV.setSource(DEFS.SOURCE_ATV, 0);
				TV.setATVChannel(keyCode);
			case 12: 				
				if(!TV.getSourceType().equalsIgnoreCase(DEFS.ATV))
					TV.setSource(DEFS.SOURCE_ATV, 0);
				TV.setATVChannel(keyCode);
 			
 				break;
//			case KeyMap.KEYCODE_VOL_DOWN: 
//				TV.writeV(TVDefine.AudioVolumeDown);
//   				break;
//			case KeyMap.KEYCODE_VOL_UP:
//				TV.writeV(TVDefine.AudioVolumeUp);
//  				break;
//			case KeyMap.KEYCODE_CHUP:
//				TV.writeV(TVDefine.ChannelUp);
//  				break;
//			case KeyMap.KEYCODE_CHDN:
//				TV.writeV(TVDefine.ChannelDown);
//  				break;
//
//			case KeyMap.KEYCODE_CLONE_CHANNEL_TV: 
//				break;
//			case KeyMap.KEYCODE_WBA_INIT:
// 				break;
			
			case 292:
			case 306: 
				break;

			default:
				break;
			}
		}
	}	
	
	public static void parserSerial(int cmd_data,int keyCode) {
		Debug.v(TAG, "cmd_data==" + cmd_data + "keyCode=" + keyCode);
		switch (cmd_data) {
		case 0xDA: // wifi 濡�崇础瀵拷閸忥拷
			switch (keyCode) {
			case 0:
				TCL.setWiFiPower(DEFS.COMMON_OFF);
				break;
			case 1:
				TCL.setWiFiPower(DEFS.COMMON_ON);
				break;
			default:
				TCL.setWiFiPower(DEFS.COMMON_OFF);
			}
			break;
		case 0xDB: // 閽冩繄澧� 濡�崇础瀵拷閸忥拷
			switch (keyCode) {
			case 0://0鐞涖劎銇氶崗锟�
				TCL.setBluetoothPower(DEFS.COMMON_OFF);
				break;
			case 1://1鐞涖劎銇氬锟�
				TCL.setBluetoothPower(DEFS.COMMON_ON);
				break;
			default:
				TCL.setBluetoothPower(DEFS.COMMON_OFF);
			}
			break;
		case 0x72:{ //oxf72  娑撻缚顔曠純顔款嚔鐟凤拷閸旂喕鍏橀敍灞筋洤閺嬫粓娓剁憰浣瑰潑閸旂姾顕㈢粔宥忕礉闂囷拷閺嶈宓佹稉顓㈡？娴犺埖鏆熼幑顔猴拷鍌氼洤閺嬫粍澧嶇拋鍓х枂閻ㄥ嫯顕㈢懛锟芥稉宥囶儊閸氬牆娴楅梽鍛鐠囶叀鈻堥敍灞藉灟娴兼俺顔曠純顔藉灇閼昏精顕�
			IActivityManager am = ActivityManagerNative.getDefault();
			try {
				Configuration config = am.getConfiguration();
				String platform = SystemProperties.get("ro.board.platform");
				switch (keyCode) {
				case 0:  // 閼昏精顕�
					if(platform.equals("mt5891"))
					{
						Locale localEN = null;
						String local = ThirdParty.getLocal();
						if (local == null) {
							Log.i(TAG, "language area invalid");
							break;
						}
						if(local.equals("EU")){
							localEN = new Locale("en", "GB");
						}
						else if(local.equals("AP")){
							localEN = new Locale("en", "IN");
						}
						else if(local.equals("CA")){
							localEN = new Locale("en", "US");
						}
						else if(local.equals("AU")){
							localEN = new Locale("en", "AU");
						}
						config.locale = localEN;
					}
					else
					{
						config.locale = Locale.ENGLISH;
						Log.i(TAG, "LOCALE_ENGLISH");
					}
					break;
				case 1: // 鐡掑﹤宕＄拠锟�
					Locale localVi = new Locale("vi", "VN");
					config.locale = localVi;
					Log.i(TAG, "VI");
					break;
				case 2:  // 缁狅拷娴ｆ挷鑵戦弬锟�
					config.locale = Locale.SIMPLIFIED_CHINESE;
					Log.i(TAG, "LOCALE_CHINESE");
					break;
				case 3: // 濞夋澘娴楃拠锟� 
					Locale localTh = new Locale("th", "TH");
					config.locale = localTh;
					Log.i(TAG, "TH");
					break;
				case 4:  // 闂冩寧濯烘导顖濐嚔 
					Locale localAr = new Locale("ar", "EG");
					config.locale = localAr;
					Log.i(TAG, "AR");
					break;
				case 5:  // 濞夋洝顕�
					if(platform.equals("mt5891"))
					{
						Locale localFR = null;
						String local = ThirdParty.getLocal();
						if (local == null) {
							Log.i(TAG, "language area invalid");
							break;
						}
						if(local.equals("EU")){
							localFR = new Locale("fr", "FR");
						}
						else if(local.equals("CA")){
							localFR = new Locale("fr", "CA");
						}
						config.locale = localFR;
					}
					else
					{
						config.locale = Locale.FRENCH;
						Log.i(TAG, "LOCALE_FRENCH");
					}
					break;
				case 6:  // 瀵扮柉顕�
					config.locale = Locale.GERMAN;
					Log.i(TAG, "LOCALE_GERMAN");
					break;
				case 7:  // 鐟楄法褰悧娆掝嚔
					Locale localES = null;
					if(platform.equals("mt5891"))
					{
						String local = ThirdParty.getLocal();
						if (local == null) {
							Log.i(TAG, "language area invalid");
							break;
						}
						if(local.equals("EU")){
							localES = new Locale("es", "ES");
						}
						else if(local.equals("AP")){
							localES = new Locale("es", "ES");
						}
						else if(local.equals("CA")){
							localES = new Locale("es", "US");
						}
					}
					else
					{
						localES = new Locale("es", "ES");
					}				
					config.locale = localES;
					Log.i(TAG, "ES");
					break;
				case 8:   // 娣囧嫯顕�
					Locale localRu = new Locale("ru", "RU");
					config.locale = localRu;
					Log.i(TAG, "RU");
					break;
				case 9:    // 閽伮ゆ倗閻楁瑨顕�
					Locale localPt = new Locale("pt", "PT");
					config.locale = localPt;
					Log.i(TAG, "PT");
					break;
				case 10:    // 濞夈垺鏌夌拠锟�
					Locale localIr = new Locale("fa", "IR");
					config.locale = localIr;
					Log.i(TAG, "IR");
					break;
				case 11:     // 鐢奔闆嗛弶銉嚔
					Locale localIl = new Locale("iw", "IL");
					config.locale = localIl;
					Log.i(TAG, "IL");
					break;
				case 12:     // 閽傛瑥褰滅拠锟�
					config.locale = new Locale("mn", "MN");
					Log.i(TAG, "MN");
					break;
				case 13:     // 繁体中文
					config.locale = new Locale("zh", "TW");
					Log.i(TAG, "TW");
					break;
				case 14:     // 保加利亚
					config.locale = new Locale("bg", "BG");
					Log.i(TAG, "BG");
					break;
				case 15:     // 克罗地亚
					config.locale = new Locale("hr", "HR");
					Log.i(TAG, "HR");
					break;
				case 16:     // 捷克
					config.locale = new Locale("cs", "CZ");
					Log.i(TAG, "CZ");
					break;
				case 17:     // 丹麦
					config.locale = new Locale("da", "DK");
					Log.i(TAG, "DK");
					break;
				case 18:     // 希腊
					config.locale = new Locale("el", "GR");
					Log.i(TAG, "GR");
					break;
				case 19:     // 芬兰
					config.locale = new Locale("fi", "FI");
					Log.i(TAG, "FI");
					break;
				case 20:     // 匈牙利
					config.locale = new Locale("hu", "HU");
					Log.i(TAG, "HU");
					break;
				case 21:     // 冰岛
					config.locale = new Locale("is", "IS");
					Log.i(TAG, "IS");
					break;
				case 22:     // 意大利
					config.locale = new Locale("it", "IT");
					Log.i(TAG, "IT");
					break;
				case 23:     // 荷兰
					config.locale = new Locale("nl", "NL");
					Log.i(TAG, "NL");
					break;
				case 24:     // 挪威
					config.locale = new Locale("nb", "NO");
					Log.i(TAG, "NO");
					break;
				case 25:     // 波兰
					config.locale = new Locale("pl", "PL");
					Log.i(TAG, "PL");
					break;
				case 26:     // 罗马尼亚
					config.locale = new Locale("ro", "RO");
					Log.i(TAG, "RO");
					break;
				case 27:     // 斯洛伐克
					config.locale = new Locale("sk", "SK");
					Log.i(TAG, "SK");
					break;
				case 28:     // 瑞典
					config.locale = new Locale("sv", "SE");
					Log.i(TAG, "SE");
					break;
				case 29:     // 土耳其
					config.locale = new Locale("tr", "TR");
					Log.i(TAG, "TR");
					break;
				case 30:     // 乌克兰
					config.locale = new Locale("uk", "UA");
					Log.i(TAG, "UA");
					break;
				case 31:     // 韩国
					config.locale = new Locale("ko", "KR");
					Log.i(TAG, "KR");
					break;
				case 32:     // 拉脱维亚
					config.locale = new Locale("lv", "LV");
					Log.i(TAG, "LV");
					break;
				case 33:     // 爱沙尼亚
					config.locale = new Locale("et", "EE");
					Log.i(TAG, "EE");
					break;
				case 34:     // 立陶宛
					config.locale = new Locale("lt", "LT");
					Log.i(TAG, "LT");
					break;
				case 35:     // 塞尔维亚
					config.locale = new Locale("mn", "MN");
					Log.i(TAG, "MN");
					break;
				case 36:     // 斯洛文尼亚
					config.locale = new Locale("sr", "RS");
					Log.i(TAG, "RS");
					break;
				case 37:     // 阿尔巴尼亚
					config.locale = new Locale("sq", "AL");
					Log.i(TAG, "AL");
					break;
				case 39:     // 马其顿
					config.locale = new Locale("mk", "MK");
					Log.i(TAG, "MK");
					break;
				case 41:     // 乌兹别克斯坦
					config.locale = new Locale("uz", "UZ");
					Log.i(TAG, "UZ");
					break;
				case 42:     // 印度尼西亚
					config.locale = new Locale("in", "ID");
					Log.i(TAG, "ID");
					break;
				case 43:     // 马来西亚
					config.locale = new Locale("ms", "MY");
					Log.i(TAG, "MY");
					break;
				default:
					config.locale = Locale.ENGLISH;	
					Log.i(TAG, "default LOCALE_ENGLISH");
				}
//				config.userSetLocale = true;//hubin 
				am.updateConfiguration(config);
			} catch (Exception e) {
				Log.i(TAG, "0x72 e :" + e);
			}
			break;
		}
		case 0x7E: // 閸椻剝濯簅k瀵拷閸忥拷
			switch (keyCode) {
			case 0:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_ON);
				break;
			case 1:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_OFF);
				break;
			default:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_OFF);
			}
			break;
		case 0x9E: // 妤癸箑鍘犳搴″閼宠棄绱戦崗锟�(瀵板懐鈥樼拋銈忕礉閻╊喖澧犻崪灞藉幢閹峰》k閸旂喕鍏樻稉锟介弽锟�)
			switch (keyCode) {
			case 0:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_OFF);
				break;
			case 1:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_ON);
				break;
			default:
				TCL.AsyncEnableKaraoke(DEFS.COMMON_OFF);
			}
			break;
		case 0x29: // 鐏炲繑顥呭ù瀣佸蹇撶磻/閸忥拷
			switch (keyCode) {
			case 0:
				TCL.setTestPatternStatus(false);
				break;
			case 1:
				TCL.setTestPatternStatus(true);
				break;
			default:
				TCL.setTestPatternStatus(false);
			}
			break;
		case 0x3a: //Factory OSD 瀵拷/閸忥拷
			switch (keyCode) {
			case 0:
				//TCL.setFacInfoShowEnable(DEFS.Disable);
				TCL.setInfoDisServiceVisible(DEFS.Disable);
				break;
			case 1:
				//TCL.setFacInfoShowEnable(DEFS.Enable);
				TCL.setInfoDisServiceVisible(DEFS.Enable);
				break;
			default:
				//TCL.setFacInfoShowEnable(DEFS.Disable);
				TCL.setInfoDisServiceVisible(DEFS.Disable);
			}
			break;
		case 0x11://00--Factory OSD Off   01--Factory OSD On   0x02--Pro Info  Display ON   0x03--Pro Info  Display Off
			switch (keyCode) {
			case 0x00:
				TCL.setFacInfoShowEnable(DEFS.Disable);
				break;
			case 0x01:
				TCL.setFacInfoShowEnable(DEFS.Enable);
				break;
			case 0x02:
				TCL.setSerInfoShowEnable(DEFS.Enable);
				break;
			case 0x03:
				TCL.setSerInfoShowEnable(DEFS.Disable);
				break;
			}
			break;
		case 0x13: 
			switch (keyCode) {
			case 0:
				TV.writeS(TVDefine.WarmUP, DEFS.Disable);
				break;
			case 1:
				TV.writeS(TVDefine.WarmUP, DEFS.Enable);
				break;
			default:
				TV.writeS(TVDefine.WarmUP, DEFS.Disable);
			}
			break;
		case 0x14: 
			switch (keyCode) {
			case 0:
				TV.writeS(TVDefine.KeyCodeTest, DEFS.Disable);
				break;
			case 1:
				TV.writeS(TVDefine.KeyCodeTest, DEFS.Enable);
				break;
			}
			break;
		case 0x15:
			switch (keyCode) {
			case 0: // 5376 21 0
				TV.setSource(DEFS.SOURCE_ATV, 1);
				break;
			case 1:// 5377 21 1
				TV.setSource(DEFS.SOURCE_DTV, 1);
				break;
			}
			break;
		case 0x2a:
			int index = keyCode;
			if ((TCL.getTestPatternStatus() == true) && (index >= 0)
					&& (index <= 8)) {
				TCL.setTestPatternColor(index);
			}
			break;
		case 0x20: 
			TCL.AsyncsetATVChannel(keyCode);
			break;
//		case 0x21: 
//			int channelNum=tclCommondBuffer[4]*255+tclCommondBuffer[5];	
//
//			switch(tclCommondBuffer[3])
//			{
//			case 0x00:
//				TCL.AsyncsetDTVChannel(DEFS.TYPE_DTMB,channelNum);
//				break;
//			case 0x01:
//				TCL.AsyncsetDTVChannel(DEFS.TYPE_DVBC,channelNum);
//				break;
//			}
//			
//			break;
		case 0x22:// AV or scart Source Selection
			switch (keyCode) {
			case 0:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_ATV, 1));
				TV.setSource(DEFS.SOURCE_ATV, 1);
				break;
			case 1:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_AV, 1));
				TV.setSource(DEFS.SOURCE_AV, 1);
				break;
			case 2:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_AV, 2));
				TV.setSource(DEFS.SOURCE_AV, 2);
				break;
			}
			break;
		case 0x23://COMP Source Selection Y PB PR
			switch (keyCode) {
			case 1:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_YPBPR, 1));
				TV.setSource(DEFS.SOURCE_YPBPR, 1);
				break;
			}
			break;
		case 0x24://select source VGA
			switch (keyCode) {
			case 1:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_VGA, 1));
				TV.setSource(DEFS.SOURCE_VGA, 1);
				break;
			}
			break;
		case 0x25://select source HDMI	
			switch (keyCode) {
			case 1:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_HDMI, 1));
				TV.setSource(DEFS.SOURCE_HDMI, 1);
				break;
			case 2:
//				Utils.showSourceType(Utils.getSourceName(DEFS.SOURCE_HDMI, 2));
				TV.setSource(DEFS.SOURCE_HDMI, 2);
				break;
			case 3:
				TV.setSource(DEFS.SOURCE_HDMI, 3);
				break;
			case 4:
				TV.setSource(DEFS.SOURCE_HDMI, 4);
				break;
			}
			break;
		case 0x26://Media Source Selection
//			if(tclCommondBuffer[3]>3)
//			{
//				Log.i(TAG, "[COM_OR_DATA_WRONG]tclCommondBuffer[3] = "+tclCommondBuffer[3]);
//				TV.writeD(TVDefine.Serial, COM_OR_DATA_WRONG);
//					return;
//			}
			Utils.intentHandler(DEFS.Package_TCL_FileExplorer, DEFS.Activity_TCL_FileExplorer); 			
			break;
		case 0x30:// Preset Picture mode
			TV.writeV(TVDefine.PictureMode, keyCode);
			break;
//		case 0x60://Mute Control
////			Toast.makeText(ThirdParty.mContext, "value="+keyCode, 3000).show();
//			if(keyCode == 0) {
//				TV.writeV(TVDefine.AudioVolume, keyCode);
//				exec("input keyevent KEYCODE_VOLUME_DOWN");
//			} else if(keyCode == 1) { 
//				TV.writeV(TVDefine.AudioVolume, keyCode + 1);
//				exec("input keyevent KEYCODE_VOLUME_DOWN");
//			} else if(keyCode == 100) {
//				TV.writeV(TVDefine.AudioVolume, keyCode);
//				exec("input keyevent KEYCODE_VOLUME_UP");
//			} else {
//				TV.writeV(TVDefine.AudioVolume, keyCode - 1);
//				exec("input keyevent KEYCODE_VOLUME_UP");
//			}
//			break;
		case 0xd0://3 D model working  
			switch (keyCode) {
			case 0:
				TVDefine.period=-1;						
//				TV.writeS(TVDefine.ThreeDMode, DEFS.Disable);
				TVDefine.status_3d=false;
				//0,1,2
				ThirdParty.setBluetooth3dSyncStatus(TCL.getBluetoothvsync()[0]);
				// 0,1
				ThirdParty.setBluetooth3dWorkStatus(TCL.getBluetoothsync()[0]);
				break;
			case 1:
				if (!TVDefine.status_3d)
					TVDefine.period = -1;
//				TV.writeS(TVDefine.ThreeDMode, DEFS.Enable);
				TVDefine.status_3d = true;
				//0,1,2
				ThirdParty.setBluetooth3dSyncStatus(TCL.getBluetoothvsync()[0]);
				// 0,1
				ThirdParty.setBluetooth3dWorkStatus(TCL.getBluetoothsync()[0]);
				break;
			}
			break;
		
		default:
			break;
		}
	}
	
	private static void exec(final String cmd) {
		new Thread(new Runnable() {

			@Override
			public void run() {
				ThirdParty.setRootSeek(cmd);
			}
		}).start();
	}
		
	
	public interface GetIRCodeListener  
	{
		void onChange(int data);
	}
	public static  GetIRCodeListener   mGetIRCodeListener;
	public static void addListener(GetIRCodeListener getInsListener) 
	{
		mGetIRCodeListener=getInsListener;

	}
	
	

}
