package com.tcl.factory.view;

import android.os.SystemProperties;
import android.view.KeyEvent;

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;
 
 
public class PModeMenu extends SubMenu {

	public static String MenuInfos_PModeMenu[][]={
		{"0-Factory hotkey",""},
		{"1-Warm up","OFF"},
		{"2-White Balance",""},
		{"3-Reset Shop",">"},
		{"4-NVM Reset",">"},
		{"5-Power on mode",""},
		{"6-USB Clone",""},
		{"7-Preset Factory Channel",""},
		{"8-DeviceID Test","DO"},
		//{"9-Other ",""},
		{"9-Sita P mode",""}
	};
	public PModeMenu()
	{
		menuInfos=MenuInfos_PModeMenu;
		menuLabel = "Main menu\\Factory";
		super.setTAG();
		updateMenuInfos();
	}
	
	public void KeyEvent(int keyCode,int pos)
	{
		switch(keyCode)
		{
		case KeyEvent.KEYCODE_DPAD_LEFT:
		case KeyEvent.KEYCODE_DPAD_RIGHT:
		{
			switch(pos)
			{
				case 0: commonHandler(TVDefine.PMode) ;break;
				case 1: commonHandler(TVDefine.WarmUP);break;
				case 3: commonHandler(TVDefine.ShopInit);break;
				case 4: commonHandler(TVDefine.NVMReSet);break;
				case 5: {
					int value = TV.readV(TVDefine.PowerMode);
					if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT){
						value--;
					}
					else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT){	
						value++;
					}
					if(value>2)value=0;
					else if(value<0)value=2;
					
					TV.writeV(TVDefine.PowerMode,value);
					break;
				}
				case 8: TCL.getDeviceIDShortTestStatus(); break;
				case 9:commonHandler(TVDefine.SitaPMode);break;
			}
		}
		break;
		default:
			break;
		}
	}
	
	/* (non-Javadoc)
	 * Factory
	 */
	@Override
	public void updateMenuInfos() 
	{
		super.updateStatusInfo(TVDefine.PMode, 0);
//		super.updateStatusInfo(TVDefine.WarmUP, 1);
		super.updateValueInfo(TVDefine.PowerMode, 5);
		
		if((ThirdParty.getPModeStatus()) && (ThirdParty.isWarmUpAble() == true))
		{
			super.setItemEnable(1);
			super.updateStatusInfo(TVDefine.WarmUP, 1);
		}
		else
		{
			super.setItemDisable(1);
// 			TV.writeS(TVDefine.WarmUP, DEFS.Disable);//11 10 15
 			super.updateStatusInfo(TVDefine.WarmUP, 1);
 		}
		
		if(ThirdParty.isWhiteBalanceChangeAble()==false)
		{
			super.setItemDisable(2);
		}
		
		if(ThirdParty.isPowerModeSelectAble()==false)
		{
			menuInfos[5][1] = "NONE";
			super.setItemDisable(5);
		}
		super.updateStatusInfo(TVDefine.SitaPMode,9);
	}
 
	private void commonHandler(int TVDefineID)
	{
		switch(TVDefineID)
		{
			case TVDefine.WarmUP:
				TV.writeS(TVDefine.WarmUP, DEFS.Enable); break;
	//		case TVDefine.DeviceID:
	//			TV.readS(TVDefine.DeviceID); break;
			case TVDefine.ShopInit:
				TV.writeV(TVDefine.ShopInit); break;
			case TVDefine.NVMReSet:
				TV.writeV(TVDefine.NVMReSet); break;
			case TVDefine.PMode:
			{
				if(TV.readS(TVDefine.PMode))
				{
	//				TV.writeS(TVDefine.Serial, DEFS.Disable);//longc remove
					TV.writeS(TVDefine.PMode, DEFS.Disable);
				}
				else
				{
	//				TV.writeS(TVDefine.Serial, DEFS.Enable);//longc remove
					TV.writeS(TVDefine.PMode, DEFS.Enable);
				}
			}
			break;
			case TVDefine.SitaPMode:
			{
				if(TV.readS(TVDefine.SitaPMode))
				{
					TV.writeS(TVDefine.SitaPMode, DEFS.Disable);
				}
				else
				{
					TV.writeS(TVDefine.SitaPMode, DEFS.Enable);
				}
			}
			break;
		}
	}
	/* (non-Javadoc)
	 * Factory
	 */
	@Override
	public void enterSubMenu(int pos) {
		super.enterSubMenu(pos);
		switch(pos)
		{
		case 2:MainMenu.mSubMenu=new PModeWhiteBalanceMenu(); break;
		case 6:MainMenu.mSubMenu=new PModeUSBCloneMenu(); break;
		case 7:MainMenu.mSubMenu=new PModePresetChannel();break;
		//case 9:MainMenu.mSubMenu=new PModeOtherMenu(); break;
		//case 10:MainMenu.mSubMenu=new ParamSettingADC(); break;
		}
		 
	}
}
