package com.tcl.factory.view;

 

import java.util.ArrayList;
import java.util.List;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.KeyEvent;
import android.content.ComponentName;
import android.content.Context;

import com.tcl.factory.FactoryManager;
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.tvmanager.vo.EnTCLChanelListType;
import com.tcl.tvmanager.vo.ProgramInfo;
import com.tcl.factory.bsp.TCL;

 
@SuppressLint("DefaultLocale") public class HotelMainMenu extends SubMenu 
{
	private int modeType=4;    //hotel data 
	//----------------------channel define ------------------------------------
	//private int AtvMaxProgramNumber = 1;
	//private int DtvMaxProgramNumber = 1;
	private int currentSourceIndex = 0;
	private int currentChannelNum = 0;
	//----------------------input source define--------------------------------
	private String[] DefaultSourceList = {"ATV","DTV","SCART","AV1","YPBPR","VGA","HDMI1","HDMI2","HDMI3","HDMI4"};
	private Integer[] DefaultSourceNum = {
			DEFS.HOTEL_SOURCE_ATV,DEFS.HOTEL_SOURCE_DTV,DEFS.HOTEL_SOURCE_AV1,DEFS.HOTEL_SOURCE_AV2,
			DEFS.HOTEL_SOURCE_YPBPR,DEFS.HOTEL_SOURCE_VGA,DEFS.HOTEL_SOURCE_HDMI1,DEFS.HOTEL_SOURCE_HDMI2,
			DEFS.HOTEL_SOURCE_HDMI3,DEFS.HOTEL_SOURCE_HDMI4};
	ArrayList<ConfigDataSet> SourcelistMap = new ArrayList<ConfigDataSet>();
	//----------------------picture mode define--------------------------------
	private String[] DefaultPictureModeList = {"STANDARD","VIVID","MILD","STUDIO","USER","DYNAMIC"};
	private String[] DefaultPictureModeList2 = {"STANDARD","VIVID","MILD","STUDIO","USER","DYNAMIC","STADIUM","CINEMA"};
	//private String[] DefaultPictureModeName = {"Standard","Vivid","Mild","Studio","User","Dynamic","Stadium","Digital cinema"};
	private Integer[] DefaultPictureModeNum = {
			DEFS.HOTEL_PM_STANDARD,DEFS.HOTEL_PM_VIVID,DEFS.HOTEL_PM_MILD,
			DEFS.HOTEL_PM_STUDIO,DEFS.HOTEL_PM_USER,DEFS.HOTEL_PM_DYNAMIC,
			DEFS.HOTEL_PM_STADIUM,DEFS.HOTEL_PM_CINEMA};
	ArrayList<ConfigDataSet> PictureListMap = new ArrayList<ConfigDataSet>();
	//----------------------sound mode define--------------------------------
	private String[] DefaultSoundModeList = {"MUSIC","MOVIE","NEWS","STANDARD","USER"};
	private String[] DefaultSoundModeList2 = {"MUSIC","MOVIE","NEWS","STANDARD","USER","SUBWOOFER","STADIUM","GAME","SPORT"};
	//private String[] DefaultSoundModeName = {"Music","Movie","News","Standard","User","Subwoofer","Stadium","Game","Sport"};
	private Integer[] DefaultSoundModeNum = {
			DEFS.HOTEL_SM_MUSIC,DEFS.HOTEL_SM_MOVIE,DEFS.HOTEL_SM_NEWS,
			DEFS.HOTEL_SM_STANDARD,DEFS.HOTEL_SM_PERSONAL,
			DEFS.HOTEL_SM_SUBWOFOFER,DEFS.HOTEL_SM_STADIUM,
			DEFS.HOTEL_SM_GAME,DEFS.HOTEL_SM_SPORT};
	ArrayList<ConfigDataSet> SoundListMap = new ArrayList<HotelMainMenu.ConfigDataSet>();

	class ConfigDataSet
	{
		public String ConfigName;
		public Integer ConfigIndex;
	}

	private final static int ITEM_HOTEL_ENABLE = 0;	//for sita P
	private final static int ITEM_CHANNEL_LOCK = 1;	//for sita P
	private final static int ITEM_MAX_VOLUME = 2;	  // for warmup
	private final static int ITEM_AUTO_SET = 3;
	private final static int ITEM_PICTURE_MODE = 4;	
	private final static int ITEM_SOUND_MODE = 5;	
	private final static int ITEM_PRESET_VOLUME  = 6;
	private final static int ITEM_INPUT_PRESET = 7;	
	private final static int ITEM_CHANNEL_PRESET  = 8;	
	private final static int ITEM_KEY_LOCK  = 9;	
	private final static int ITEM_POWER_LOGO  = 10;
	private final static int ITEM_POWER_ANIMATION  = 11;
	private final static int ITEM_POWER_VIDEO  = 12;
	private final static int ITEM_SILENT_INSTALL  = 13;
	private final static int ITEM_SCREEN_POSITION  = 14;
	private final static int ITEM_START_FROM_APP  = 15;
	private final static int ITEM_POWER_ON_MODE  = 16;
	private final static int ITEM_STANDBY_LED_INDICATOR  = 17;
	private final static int ITEM_TV_TO_USB  = 18;
	private final static int ITEM_USB_TO_TV  = 19;

	private final static String TAG = "HotelMainMenu";
	public static  String MenuInfos_HotelMainMenu[][]=
	{
		{"Hotel Enable",""},
		{"Channel Lock",""},
		{"Max Volume",""},
		{"Auto Set",""},
		{"Picture Mode",""},
		{"Sound Mode",""},
		{"Preset Volume",""},//5
		{"Input Preset",""},
		{"Channel Preset",""},
		{"Key Lock",""},
		{"Power Logo","..."},
		{"Power Animation","..."},	//10
		{"Power Video","..."}	,
		{"Silent Update",""}	,
		{"Screen Position",""},	// 
		{"Start From APP","..."},
		{"Power On Mode",""},	//15
		{"Standby LED Indicator",""},
		{"TV to USB",">"},
		{"USB to TV",">"},	
	};
	private Context mContext;
	public HotelMainMenu(Context context)
 	{
 		mContext = context;
		super.menuInfos=MenuInfos_HotelMainMenu;
		super.menuLabel = "Main menu\\Hotel Menu";
		super.setTAG();
		currentSourceIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
		currentChannelNum = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_POWER_ATV_CH,0);
		updateSoureList();
		updatePictureList();
		updateSoundList();
		updateChannelInfo(false);
		updateMenuInfos();
	}
	
	public void updateChannelInfo(boolean bChangeSrc)
	{
		int channelNum = currentChannelNum;
		List<ProgramInfo> tvchlList = null;

		if(currentSourceIndex == DEFS.HOTEL_SOURCE_ATV)
		{
			tvchlList = ThirdParty.mTvChannelManager.getChannelList(EnTCLChanelListType.EN_CHANNEL_ANALOGUE);
		}
		else
		{
			tvchlList = ThirdParty.mTvChannelManager.getChannelList(EnTCLChanelListType.EN_CHANNEL_DIGINAL);
		}
		
		if(tvchlList != null)
		{
			if(tvchlList.size()>0)
			{
				int i;
				for(i=0;i<tvchlList.size();i++)
				{
					if(channelNum == tvchlList.get(i).number)
					{
						break;
					}
				}
				if(i == tvchlList.size())
				{
					channelNum = tvchlList.get(0).number; 
				}	
			}
			else
			{
				channelNum = 1;
			}
		}
		if(channelNum != currentChannelNum)
		{
			currentChannelNum = channelNum;
			ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_POWER_ATV_CH,channelNum);
		}
	}
	
	private String getHotelChanelNumber()
	{
		String channelNumString = "";
		//int sourceIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
		channelNumString = "CH:" + currentChannelNum;
		return channelNumString;
	}

	public void updateSoundList()
	{
		String[] src=null;
		String str = ThirdParty.GetSoundModePreset();

		if(str == null || str.trim().equals("") || str.trim().equalsIgnoreCase("null"))
		{
			src = DefaultSoundModeList;			
		}
		else 
		{
			src = str.toUpperCase().trim().split(":");
		}	
		SoundListMap.clear();
		for(int i=0;i<src.length;i++)
		{
			if(i>=DefaultSoundModeList2.length)
			{
				break;
			}
			String[] name = null;
			String strtemp ="";
			boolean setname = false;
			if(src[i].contains(","))
			{
				name = src[i].split(",");
				if(name.length == 2)
				{
					setname = true;
					strtemp = name[0];
				}
				else
				{
					strtemp = src[i];
				}
			}
			else
			{
				strtemp = src[i];
			}

			
			for(int j=0;j<DefaultSoundModeList2.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();

				if(strtemp.equals(DefaultSoundModeList2[j]))
				{
					if(setname == true)
					{
						configDataSet.ConfigName = name[1];
					}
					else 
					{
						configDataSet.ConfigName = DefaultSoundModeList2[j];						
					}
					configDataSet.ConfigIndex = DefaultSoundModeNum[j];
					SoundListMap.add(configDataSet);
					break;
				}					
			}			
		}
		if(SoundListMap.size() == 0)
		{
			for(int j=0;j<DefaultSoundModeList.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();
				configDataSet.ConfigName = DefaultSoundModeList[j];
				configDataSet.ConfigIndex = DefaultSoundModeNum[j];
				SoundListMap.add(configDataSet);
			}			
		}
	}	
	
	public int getNextSoundMode(int keycode, int index)
	{
		int i=0,retIndex=0;
		for(i=0;i<SoundListMap.size();i++)
		{
			if(SoundListMap.get(i).ConfigIndex.equals(index))
			{
				break;
			}
		}	
		if(keycode == KeyEvent.KEYCODE_DPAD_LEFT)
		{
			if((i == SoundListMap.size()) || (i == 0))
			{
				i = SoundListMap.size()-1;
			}
			else
			{
				i--;
			}
		}
		else if(keycode == KeyEvent.KEYCODE_DPAD_RIGHT)
		{	
			if(i >= SoundListMap.size()-1)
			{
				i = 0;
			}		
			else
			{
				i++;
			}
		}	
		retIndex = SoundListMap.get(i).ConfigIndex;
		return retIndex;
	}	
	
	private String getHotelSoundType()
	{
		int soundIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOUND_MODE, 0);
		String Sound = "";		
		if(soundIndex>=0 && soundIndex<DefaultSoundModeList2.length)
		{
			for(int i=0;i<SoundListMap.size();i++)
			{
				if(SoundListMap.get(i).ConfigIndex.intValue() == soundIndex)
				{
					Sound = SoundListMap.get(i).ConfigName;//DefaultSoundModeName[soundIndex];
					break;
				}
			}
		}
		return Sound;
	}
	
	public void updatePictureList()
	{
		String[] src=null;
		String str = ThirdParty.GetPictureModePreset();

		if(str == null || str.trim().equals("") || str.trim().equalsIgnoreCase("null"))
		{
			src = DefaultPictureModeList;			
		}
		else 
		{
			src = str.toUpperCase().trim().split(":");
		}	
		PictureListMap.clear();
		for(int i=0;i<src.length;i++)
		{
			if(i>=DefaultPictureModeList2.length)
			{
				break;
			}
			String[] name = null;
			String strtemp ="";
			boolean setname = false;
			if(src[i].contains(","))
			{
				name = src[i].split(",");
				if(name.length == 2)
				{
					setname = true;
					strtemp = name[0];
				}
				else
				{
					strtemp = src[i];
				}
			}
			else
			{
				strtemp = src[i];
			}			
			
			for(int j=0;j<DefaultPictureModeList2.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();
				if(strtemp.equals(DefaultPictureModeList2[j]))
				{
					if(setname == true)
					{
						configDataSet.ConfigName = name[1];
					}
					else 
					{
						configDataSet.ConfigName = DefaultPictureModeList2[j];						
					}
					configDataSet.ConfigIndex = DefaultPictureModeNum[j];
					PictureListMap.add(configDataSet);
					break;
				}
			}			
		}
		if(PictureListMap.size()==0)
		{
			for(int j=0;j<DefaultPictureModeList.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();
				configDataSet.ConfigName = DefaultPictureModeList[j];
				configDataSet.ConfigIndex = DefaultPictureModeNum[j];
				PictureListMap.add(configDataSet);
			}				
		}
	}
	
	public int getNextPictureMode(int keycode, int index)
	{
		int i=0,retIndex=0;
		for(i=0;i<PictureListMap.size();i++)
		{
			if(PictureListMap.get(i).ConfigIndex.equals(index))
			{
				break;
			}
		}	
		if(keycode == KeyEvent.KEYCODE_DPAD_LEFT)
		{
			if((i == PictureListMap.size()) || (i == 0))
			{
				i = PictureListMap.size()-1;
			}
			else
			{
				i--;
			}
		}
		else if(keycode == KeyEvent.KEYCODE_DPAD_RIGHT)
		{	
			if(i >= PictureListMap.size()-1)
			{
				i = 0;
			}		
			else
			{
				i++;
			}
		}	
		retIndex = PictureListMap.get(i).ConfigIndex;
		return retIndex;
	}	
	
	private String getHotelPictureType()
	{
		int pictureIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_PICTURE_MODE, 0);
		String Picture = "";		
		if(pictureIndex>=0 && pictureIndex<DefaultPictureModeList2.length)
		{
			for(int i=0;i<PictureListMap.size();i++)
			{
				if(pictureIndex == PictureListMap.get(i).ConfigIndex.intValue())
				{
					Picture = PictureListMap.get(i).ConfigName;//DefaultPictureModeName[pictureIndex];			
					break;
				}
			}
		}
		return Picture;
	}	
	
	public void updateSoureList()
	{
		String[] src=null;
		String str = ThirdParty.GetInputSourceList();

		Log.v(TAG,"updateSoureList="+str);
		
		if(str == null || str.trim().equals("") || str.trim().equalsIgnoreCase("null"))
		{
			src = DefaultSourceList;			
		}
		else 
		{
			src = str.toUpperCase().trim().split(":");
		}	
		SourcelistMap.clear();
		for(int i=0;i<src.length;i++)
		{
			if(i>=DefaultSourceList.length)
			{
				break;
			}
			for(int j=0;j<DefaultSourceList.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();				
				if(src[i].equals(DefaultSourceList[j]))
				{
					configDataSet.ConfigName = DefaultSourceList[j];
					configDataSet.ConfigIndex = DefaultSourceNum[j];
					SourcelistMap.add(configDataSet);
					break;
				}
			}			
		}
		if(SourcelistMap.size() == 0)
		{
			for(int j=0;j<DefaultSourceList.length;j++)
			{
				ConfigDataSet configDataSet = new ConfigDataSet();				
				configDataSet.ConfigName = DefaultSourceList[j];
				configDataSet.ConfigIndex = DefaultSourceNum[j];
				SourcelistMap.add(configDataSet);
			}			
		}
	}
	
	public int getNextSource(int keycode, int index)
	{
		int i=0,retIndex=0;
		for(i=0;i<SourcelistMap.size();i++)
		{
			if(SourcelistMap.get(i).ConfigIndex.equals(index))
			{
				break;
			}
		}	
		if(keycode == KeyEvent.KEYCODE_DPAD_LEFT)
		{
			if((i == SourcelistMap.size()) || (i == 0))
			{
				i = SourcelistMap.size()-1;
			}
			else
			{
				i--;
			}
		}
		else if(keycode == KeyEvent.KEYCODE_DPAD_RIGHT)
		{	
			if(i >= SourcelistMap.size()-1)
			{
				i = 0;
			}		
			else
			{
				i++;
			}
		}	
		retIndex = SourcelistMap.get(i).ConfigIndex;
		return retIndex;
	}
	
	private String getHotelSourceType()
	{
		int sourceIndex = currentSourceIndex;//ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
		String source = "";		
		if(sourceIndex>=0 && sourceIndex<DefaultSourceList.length)
		{
			source = DefaultSourceList[sourceIndex];
		}
		return source;
	}	

	public void KeyEvent(int keyCode,int pos)
	{
		switch(keyCode)
		{
		case KeyEvent.KEYCODE_DPAD_LEFT:
		case KeyEvent.KEYCODE_DPAD_RIGHT:
		{
			Log.d(TAG, "keyCode = "+keyCode+", pos ="+pos);
			switch(pos)
			{
				case ITEM_HOTEL_ENABLE:
					setHotelFlag(keyCode);
				break;			
				case ITEM_CHANNEL_LOCK: 
					super.StatusHandler(TVDefine.CH_LOCK);
				break; 
				case ITEM_MAX_VOLUME: 
					super.ValueHandler(TVDefine.Hotel_MaxVolume,keyCode);
				break;//ok 
				case ITEM_AUTO_SET: 
					super.StatusHandler(TVDefine.AUTO_SET);
				break; 
				case ITEM_PICTURE_MODE: 
					//super.ValueHandler(TVDefine.Hotel_PictureMode, keyCode);
					PresetPictureHandler(keyCode);
				break;//ok
				case ITEM_SOUND_MODE: 
					//super.ValueHandler(TVDefine.Hotel_SoundMode,keyCode);
					PresetSoundHandler(keyCode);
				break;//ok
				
				case ITEM_PRESET_VOLUME: 
					super.ValueHandler(TVDefine.Hotel_PresetVolume,keyCode);
				break; //ok
				
				case ITEM_INPUT_PRESET: 
					PresetInputHandler(keyCode);
				break;
				case ITEM_CHANNEL_PRESET: 
					PresetChannelHandler(keyCode);
				break;
				case ITEM_KEY_LOCK: 
					super.StatusHandler(TVDefine.KeyLock);
				break;//ok
				case ITEM_SILENT_INSTALL: 
					super.StatusHandler(TVDefine.SilentInstallMode);
				break;
				case ITEM_SCREEN_POSITION: 
					ThirdParty.setHotelScreenPosition(!ThirdParty.mFactoryAdapter.getHotelScreenPosition());
				break;
				case ITEM_POWER_ON_MODE: {
					int value = TV.readV(TVDefine.PowerMode);
					value= super.dataDeal(keyCode,value,0,2);
					TV.writeV(TVDefine.PowerMode,value);
					ThirdParty.mFactoryAdapter.setHotelPowerOnMode(value);
					break;
				}
				case ITEM_STANDBY_LED_INDICATOR: 
					int value = TV.readV(TVDefine.StandbyLEDIndicatorMode);
					value= super.dataDeal(keyCode,value,0,2);
					TV.writeV(TVDefine.StandbyLEDIndicatorMode,value);
					break;
				case ITEM_TV_TO_USB: 
					nvmToUsb();
				break; 
				case ITEM_USB_TO_TV: 
					usbToNvm();
				break;
					
	 		}
		}
		break;
		default:
			break;
		}
	}		 	 

	/* (non-Javadoc)
	 * Factory
	 */
	@Override
	public void updateMenuInfos() 
	{	
		if(ThirdParty.getHotelFlag() == DEFS.COMMON_OFF){
			menuInfos[ITEM_HOTEL_ENABLE][1]=""+"< OFF >";
		} else {
			menuInfos[ITEM_HOTEL_ENABLE][1]=""+"< ON >";
			for(int i = 1;i<MenuInfos_HotelMainMenu.length;i++){
				super.setItemEnable(i);
			}				
		}
		super.updateStatusInfo(TVDefine.CH_LOCK, ITEM_CHANNEL_LOCK);//频道锁定
		super.updateValueInfo(TVDefine.Hotel_MaxVolume, ITEM_MAX_VOLUME);//�?大音�?
		super.updateStatusInfo(TVDefine.AUTO_SET, ITEM_AUTO_SET);//自动恢复
		//super.updateValueInfo(TVDefine.Hotel_PictureMode, ITEM_PICTURE_MODE);//图像模式
		//super.updateValueInfo(TVDefine.Hotel_SoundMode, ITEM_SOUND_MODE);//声音模式
		menuInfos[ITEM_PICTURE_MODE][1] = "< " +getHotelPictureType()+" >";
		menuInfos[ITEM_SOUND_MODE][1] = "< " +getHotelSoundType()+" >";		
		
		super.updateValueInfo(TVDefine.Hotel_PresetVolume, ITEM_PRESET_VOLUME);//�?机音�?
		menuInfos[ITEM_INPUT_PRESET][1] = "< " + getHotelSourceType()+" >";//FACTORY_ATTR_HOTEL_SOURCE
		
		//super.updateValueInfo(TVDefine.ChannelPreSet , 7);//�?机频�?//这里取默认�?�，行不行啊
		menuInfos[ITEM_CHANNEL_PRESET][1] = "< " + getHotelChanelNumber()+" >";
		
		super.updateStatusInfo(TVDefine.KeyLock, ITEM_KEY_LOCK);//面板按键锁定
		
		if(ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_AUTO_SET))
		{
			super.setItemEnable(ITEM_PICTURE_MODE);
			super.setItemEnable(ITEM_SOUND_MODE);
			super.setItemEnable(ITEM_PRESET_VOLUME);
			super.setItemEnable(ITEM_INPUT_PRESET);
			if(currentSourceIndex == DEFS.HOTEL_SOURCE_ATV ||currentSourceIndex == DEFS.HOTEL_SOURCE_DTV)
			{
				super.setItemEnable(ITEM_CHANNEL_PRESET);
			}
			else
			{
				super.setItemDisable(ITEM_CHANNEL_PRESET);
			}
		}
		else
		{
			super.setItemDisable(ITEM_PICTURE_MODE);
			super.setItemDisable(ITEM_SOUND_MODE);
			super.setItemDisable(ITEM_PRESET_VOLUME);
			super.setItemDisable(ITEM_INPUT_PRESET);
			super.setItemDisable(ITEM_CHANNEL_PRESET);
		}

		super.updateStatusInfo(TVDefine.SilentInstallMode, ITEM_SILENT_INSTALL);
		if(ThirdParty.mFactoryAdapter.getHotelScreenPosition()){
			menuInfos[ITEM_SCREEN_POSITION][1] = "< Vertical >" ;
		}else{
			menuInfos[ITEM_SCREEN_POSITION][1] = "< Horizontal >" ;
		}
		super.setItemDisable(ITEM_SCREEN_POSITION);

		super.updateValueInfo(TVDefine.PowerMode, ITEM_POWER_ON_MODE);
		super.updateValueInfo(TVDefine.StandbyLEDIndicatorMode, ITEM_STANDBY_LED_INDICATOR);

		if(ThirdParty.getHotelFlag() == DEFS.COMMON_OFF){
			for(int i = 1;i<MenuInfos_HotelMainMenu.length;i++){
				super.setItemDisable(i);
			}				
		}
   	}
	
	private void PresetSoundHandler(int keyCode) 
	{
		int soundIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOUND_MODE, 0);
		soundIndex = getNextSoundMode(keyCode,soundIndex);
		ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOUND_MODE, soundIndex);
	}	
	
	private void PresetPictureHandler(int keyCode) 
	{
		int pictureIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_PICTURE_MODE, 0);
		pictureIndex = getNextPictureMode(keyCode,pictureIndex);
		ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_PICTURE_MODE, pictureIndex);
	}	
	
	private void PresetInputHandler(int keyCode) 
	{
		// TODO Auto-generated method stub
		int sourceIndex = currentSourceIndex;//ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
		Log.d("lyf", "sourceIndex="+sourceIndex);
		//sourceIndex = super.valueDeal(TVDefine.Hotel_InputSource, keyCode, sourceIndex);
		sourceIndex = getNextSource(keyCode,sourceIndex);
		currentSourceIndex = sourceIndex;
		switch(sourceIndex)
		{
			case DEFS.HOTEL_SOURCE_ATV: 
				//TV.setSource(DEFS.SOURCE_ATV, 1);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_ATV);
				updateChannelInfo(true);
			break;
			case DEFS.HOTEL_SOURCE_DTV: 
				//TV.setSource(DEFS.SOURCE_DTV, 1);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_DTV);
				updateChannelInfo(true);
			break;
			case DEFS.HOTEL_SOURCE_AV1: 
				//TV.setSource(DEFS.SOURCE_AV,1);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_AV1);
			break;	
			case DEFS.HOTEL_SOURCE_AV2: 
				//TV.setSource(DEFS.SOURCE_AV,1);  //change cvbs1
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_AV2);
			break;
			case DEFS.HOTEL_SOURCE_YPBPR: 
				//TV.setSource(DEFS.SOURCE_YPBPR,1);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_YPBPR);
			break;					
			case DEFS.HOTEL_SOURCE_VGA: 
				//TV.setSource(DEFS.SOURCE_VGA,1);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_VGA);
			break;
			case DEFS.HOTEL_SOURCE_HDMI1: 
				//TV.setSource(DEFS.SOURCE_HDMI,1	);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_HDMI1);
			break;
			case DEFS.HOTEL_SOURCE_HDMI2: 
				//TV.setSource(DEFS.SOURCE_HDMI,2);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_HDMI2);
			break;	
			case DEFS.HOTEL_SOURCE_HDMI3: 
				//TV.setSource(DEFS.SOURCE_HDMI,3);
				ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, DEFS.HOTEL_SOURCE_HDMI3);
			break;	
			default:
			break;	
		}
		// save preset input source to eeprom for recovery
		//TV.writeV(TVDefine.InputSource,sourceIndex);
		Debug.v(TAG, "PresetInputHandler : PresetInput index " + sourceIndex);
	}
	
	private void PresetChannelHandler(int keyCode) 
	{
		int sourceIndex = currentSourceIndex;//ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
		int channelNum = currentChannelNum;//ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_POWER_ATV_CH,0);
		List<ProgramInfo> tvchlList = null;
		int totalsize = 0;
		int offset = 0;
		int find = 0;
		int i = 0;			
		
		if(sourceIndex == DEFS.HOTEL_SOURCE_ATV)
		{
			tvchlList = ThirdParty.mTvChannelManager.getChannelList(EnTCLChanelListType.EN_CHANNEL_ANALOGUE);
		}
		else 
		{
			tvchlList = ThirdParty.mTvChannelManager.getChannelList(EnTCLChanelListType.EN_CHANNEL_DIGINAL);
		}	
		if(tvchlList != null)
		{
			totalsize = tvchlList.size();
			if(totalsize > 0)
			{
				if(keyCode == KeyEvent.KEYCODE_DPAD_LEFT)
				{
					offset = -1;
				}
				else 
				{	
					offset = 1;
				}
				for( i=0;i < totalsize;i++)
				{
					if(tvchlList.get(i).number == currentChannelNum)
					{
						find = i;
						break;
					}
				}
				if(i == totalsize)	//do not find number
				{
					channelNum = tvchlList.get(0).number;
				}
				else 
				{
					if((offset == -1 && find > 0) || (offset == 1 && find < totalsize-1))
					{
						channelNum = tvchlList.get(find+offset).number;
					}
				}
			}
		}
		currentChannelNum = channelNum;
		ThirdParty.setHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_POWER_ATV_CH,channelNum);
	}
	
//	private void USB2TV(int keyCode) {
//		// TODO Auto-generated method stub
//		usbCloneModeChanges(keyCode);
//		Debug.v(TAG, "need to modify");
////		new UsbCloneDialog( CommandExecute.mContent,DEFS.USB_TO_NVM,modeType);
//	}
//	private void TV2USB(int keyCode) {
//		// TODO Auto-generated method stub
//		usbCloneModeChanges(keyCode);
//		Debug.v(TAG, "need to modify");
////		new UsbCloneDialog( CommandExecute.mContent,DEFS.NVM_TO_USB ,modeType);
//	}
	private void nvmToUsb() {	
//		USBCloneDialog  usbCloneDialog=new USBCloneDialog( TCL.mContext,DEFS.NVM_TO_USB ,modeType);
			TV.writeV(TVDefine.NVM2USB,modeType);
   }

   private void usbToNvm() {
//			USBCloneDialog  usbCloneDialog=new USBCloneDialog( TCL.mContext,DEFS.USB_TO_NVM,modeType);
			TV.writeV(TVDefine.USB2NVM,modeType);
			currentSourceIndex = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_SOURCE, 0);
			currentChannelNum = ThirdParty.getHotelAttribute(FactoryManager.FACTORY_ATTR_HOTEL_POWER_ATV_CH,0);			
			updateMenuInfos();
   }

	@Override
	public void enterSubMenu(int pos) 
	{
		// TODO Auto-generated method stub
		super.setMenuPosition(pos);
		if(ThirdParty.getHotelBootLogoCheckStatus()!=DEFS.HOTEL_BOOT_LOGO_CHECK_STATUS_NULL)
		{
			return;
		}
		switch(pos)
		{
			case ITEM_POWER_LOGO: 

				MainMenu.mSubMenu = new HotelBootLogoList(mContext, DEFS.HOTEL_BOOT_LOGO);
			break;
			case ITEM_POWER_ANIMATION: 

				MainMenu.mSubMenu = new HotelBootLogoList(mContext, DEFS.HOTEL_BOOT_ANIM);
			break;
			case ITEM_POWER_VIDEO: 
				MainMenu.mSubMenu = new HotelBootLogoList(mContext, DEFS.HOTEL_BOOT_VIDEO);
			break;	
			case ITEM_START_FROM_APP: 
				MainMenu.mSubMenu = new HotelAppList(mContext);
			break;			
		}
		Debug.v(TAG, "enterSubMenu : pos = " + pos);
	}

	private void setHotelFlag(int keyCode) 
	{
		// TODO Auto-generated method stub
		
		if(ThirdParty.getHotelFlag() == DEFS.COMMON_OFF)
		{
			ThirdParty.setHotelFlag(DEFS.COMMON_ON);
			ThirdParty.HotelModeInit();
  		}
		else
		{
			ThirdParty.setHotelFlag(DEFS.COMMON_OFF);
			ThirdParty.HotelModeExit();
  		}		
	}
}
