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 ParamSettingDBC  extends SubMenu{
	public static  String MenuInfos_ParamSettingDBC[][]={
		{"Bp",""},
		{"APL_2",""},
		{"APL/DBC",""},
		{"DBC Enable",""},
		{"DBC PrintEnable",""},
		{"BK_Standard",""},
		{"BKE",""},
		{"ADIM_Ap",""},
		{"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 NatureLightADIMAPValue = 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 	ParamSettingDBC()
	{
		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: super.ValueHandler(TVDefine.NatureLightBP, keyCode) ;break;
			case 1: super.ValueHandler(TVDefine.NatureLightAPL2, keyCode) ;break;
			case 2: {
				NatureLightMode++;
				if(NatureLightMode>2)NatureLightMode=0;
				TV.writeV(TVDefine.NatureLightMode, NatureLightMode);
				break;
			}
			case 3: {
				NatureLightEnable++;
				if(NatureLightEnable>1)NatureLightEnable=0;
				
				if(NatureLightEnable==0) {
					ThirdParty.setNatureLightEnable(false);
				}
				else {
					ThirdParty.setNatureLightEnable(true);
				}
				break;
			}
			case 4: {
				NatureLightPrintEnable++;
				if(NatureLightPrintEnable>1)NatureLightPrintEnable=0;
				
				if(NatureLightPrintEnable==0) {
					ThirdParty.setNatureLightPrintEnable(false);
					ThirdParty.setBackLightValue(100);
					ThirdParty.setContrastValue(50);
				}
				else {
					ThirdParty.setNatureLightPrintEnable(true);
				}
				break;
			}
			case 5: {
				//00-100
				NatureLightSBLValue = ThirdParty.getNatureLightSBLValue();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)NatureLightSBLValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)NatureLightSBLValue++;
				
				if(NatureLightSBLValue>100)NatureLightSBLValue=100;
				else if(NatureLightSBLValue<0)NatureLightSBLValue=0;
				
				ThirdParty.setNatureLightSBLValue(NatureLightSBLValue);
				break;
			}
			case 6: {
				//20-40
				NatureLightBKEValue = ThirdParty.getNatureLightBKEValue();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)NatureLightBKEValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)NatureLightBKEValue++;
				
				if(NatureLightBKEValue>40)NatureLightBKEValue=40;
				else if(NatureLightBKEValue<20)NatureLightBKEValue=20;
				
				ThirdParty.setNatureLightBKEValue(NatureLightBKEValue);
				break;
			}
			case 7: {
				//0-255
				NatureLightADIMAPValue = ThirdParty.getNatureLightDimAPValue();
				if(keyCode==KeyEvent.KEYCODE_DPAD_LEFT)NatureLightADIMAPValue--;
				else if(keyCode == KeyEvent.KEYCODE_DPAD_RIGHT)NatureLightADIMAPValue++;
				
				if(NatureLightADIMAPValue>255)NatureLightADIMAPValue=0;
				else if(NatureLightADIMAPValue<0)NatureLightADIMAPValue=255;
				
				ThirdParty.setNatureLightDimAPValue(NatureLightADIMAPValue);
				break;
			}
			case 8: {
				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() {
		// TODO Auto-generated method stub
		super.updateValueInfo(TVDefine.NatureLightBP, 0);
		super.updateValueInfo(TVDefine.NatureLightAPL2, 1);
		menuInfos[2][1] = ""+NatureLightMode;
		
		if(ThirdParty.getNatureLightEnable())NatureLightEnable = 1;
		else NatureLightEnable = 0;
		if(ThirdParty.getNatureLightPrintEnable())NatureLightPrintEnable = 1;
		else NatureLightPrintEnable = 0;
		NatureLightSBLValue = ThirdParty.getNatureLightSBLValue();
		NatureLightBKEValue = ThirdParty.getNatureLightBKEValue();
		NatureLightADIMAPValue = ThirdParty.getNatureLightDimAPValue();
		es = ThirdParty.getEnergySaving();
		esIndex = getEsIndex();
		
		if(NatureLightEnable!=0) menuInfos[3][1] = "ON";
		else menuInfos[3][1] = "OFF";
		
		if(NatureLightPrintEnable!=0) menuInfos[4][1] = "ON";
		else menuInfos[4][1] = "OFF";
		
		menuInfos[5][1] = ""+NatureLightSBLValue;
		menuInfos[6][1] = ""+NatureLightBKEValue;
		menuInfos[7][1] = ""+NatureLightADIMAPValue;
		menuInfos[8][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;
	}
}