package com.tcl.factory.view;

import android.util.Log;
import android.view.KeyEvent;

import com.tcl.factory.bsp.TV;
import com.tcl.factory.bsp.TVDefine;
import com.tcl.factory.thirdparty.ThirdParty;
import com.tcl.tvmanager.vo.EnTCLEnergySaving;
  

public class ParamSettingDBCAu  extends SubMenu{
	public static  String MenuInfos_ParamSettingDBC[][]={
		/*{"Bp",""},
		{"APL_2",""},
		{"APL/DBC",""},
		{"DBC Enable",""},
		{"DBC PrintEnable",""},
		{"BK_Standard",""},
		{"BKE",""},
		{"ADIM_Ap",""},*/
		{"DBC_Mode","0"},
		{"APL1","30"},
		{"APL1_BL","50"},
		{"APL2","130"},
		{"BP","70"},
		{"K","22"},
		{"Print_Enable","ON"},
		{"Energy saving","High"},
	};
  	int NatureLightMode = 0;
  	int NatureLightEnable = 1;
  	int NatureLightPrintEnable = 0; //0-off,1-apl/I,2-all
  	int NatureLightSBLValue = 0;
  	int NatureLightBKEValue = 0;
  	int kValue = 0;
  	int esIndex = 0;
  	EnTCLEnergySaving es;
  	EnTCLEnergySaving[] ess = {
  			EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_OFF, 
  			EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_LOW,
  			EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_HIGH};
  	String[] esStr = {"OFF", "LOW", "HIGH"};
  	
  	
  	public 	ParamSettingDBCAu()
	{
		super.menuInfos=MenuInfos_ParamSettingDBC;
		super.menuLabel = "Main\\Param Setting\\DBC";
		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: {
				NatureLightMode++;
				if(NatureLightMode>2)NatureLightMode=0;
				TV.writeV(TVDefine.NatureLightMode, NatureLightMode);
				break;
			}
			case 1: {
				//20-40
				NatureLightBKEValue = ThirdParty.getNatureLightBKEValue();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)NatureLightBKEValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)NatureLightBKEValue++;
				
				if(NatureLightBKEValue>255)NatureLightBKEValue=0;
				else if(NatureLightBKEValue<0)NatureLightBKEValue=255;
				
				ThirdParty.setNatureLightBKEValue(NatureLightBKEValue);
				break;
			}
			case 2: {
				//00-100
				NatureLightSBLValue = ThirdParty.getNatureLightSBLValue();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)NatureLightSBLValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)NatureLightSBLValue++;
				
				if(NatureLightSBLValue>255)NatureLightSBLValue=0;
				else if(NatureLightSBLValue<0)NatureLightSBLValue=255;
				
				ThirdParty.setNatureLightSBLValue(NatureLightSBLValue);
				break;
			}
			case 3: super.ValueHandler(TVDefine.NatureLightAPL2, keyCode) ;break;
			case 4: super.ValueHandler(TVDefine.NatureLightBP, keyCode) ;break;
			case 5: {
				//0-100
				kValue = ThirdParty.getNatureLightVerboseLevel();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)kValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)kValue++;
				
				if(kValue>100)kValue=0;
				else if(kValue<0)kValue=100;
				
				ThirdParty.setNatureLightVerboseLevel(kValue);
				break;
			}
			case 6: {
				NatureLightPrintEnable++;
				if(NatureLightPrintEnable>1)NatureLightPrintEnable=0;
				
				if(NatureLightPrintEnable==0) {
					ThirdParty.setNatureLightPrintEnable(false);
	//				ThirdParty.setBackLightValue(100);
	//				ThirdParty.setContrastValue(50);
				}
				else {
					ThirdParty.setNatureLightPrintEnable(true);
				}
				break;
			}
			case 7: {
				es = ThirdParty.getEnergySaving();
				esIndex = getEsIndex();
				Log.i("fkyy", "before11 esIndex =" + esIndex);
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)esIndex--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)esIndex++;
				
				if(esIndex>ess.length - 1)esIndex=0;
				else if(esIndex<0)esIndex=ess.length - 1;
				Log.i("fkyy", "after esIndex =" + esIndex);
				ThirdParty.setEnergySaving(ess[esIndex]);
	//			ThirdParty.setEnergySaving(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_HIGH);
				break;
				}
			}
		}
		break;
		default:
			break;
		}
	}

	/* (non-Javadoc)
	 * Factory
	 */
	@Override
	public void updateMenuInfos() {
		if (ThirdParty.getNatureLightPrintEnable())
			NatureLightPrintEnable = 1;
		else
			NatureLightPrintEnable = 0;
		NatureLightMode = ThirdParty.getNatureLightModeValue();
		NatureLightSBLValue = ThirdParty.getNatureLightSBLValue();
		NatureLightBKEValue = ThirdParty.getNatureLightBKEValue();
		kValue = ThirdParty.getNatureLightVerboseLevel();
		es = ThirdParty.getEnergySaving();
		esIndex = getEsIndex();
		
		menuInfos[0][1] = ""+NatureLightMode;
		menuInfos[1][1] = ""+NatureLightBKEValue;
		menuInfos[2][1] = ""+NatureLightSBLValue;
		super.updateValueInfo(TVDefine.NatureLightAPL2, 3);
		super.updateValueInfo(TVDefine.NatureLightBP, 4);
		menuInfos[5][1] = ""+kValue;
		if (NatureLightPrintEnable != 0)
			menuInfos[6][1] = "ON";
		else
			menuInfos[6][1] = "OFF";
		
		menuInfos[7][1] = ""+esStr[esIndex];
		
		Log.i("fkyy", "111esIndex =" + es + "::" + es.name());
	}
	
	private int getEsIndex() {
		Log.i("fkyy", "esIndex =" + es + "::" + es.name());
		if(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_OFF.compareTo(es) == 0) {
			return 0;
		} else if(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_LOW.compareTo(es) == 0) {
			return 1;
		} if(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_HIGH.compareTo(es) == 0) {
			return 2;
		} 
		return 0;
	}
}