local common = LibStub("LibAddon"):GetAddon("common")
local tvsettingtab = LibStub("LibAddon"):NewAddon("tvsettingtab", "LibEvent", "LibTimer")

local CSETFLG = {
	CSF_MicrophoneFlg		= 1,		-- 设置麦克风是否开启			value = 1时表示开启，0表示关闭
	CSF_MicrophoneVolume	= 2,		-- 更改说话的环境音量			范围:value >= 0 & value <= 100
	CSF_MicrophoneMuteFlg	= 3,		-- 更改麦克风静音模式			value = 1 时静音，0表示没静音
	CSF_MicrophoneEnhance	= 4,		-- 设置麦克风加强					value = 1 时表示开启，0表示关闭
	CSF_SpeakerVolume		= 5,		-- 更改喇叭的播放音量			范围:value >= 0 & value <= 100
	CSF_SpeakerMuteFlg		= 6,		-- 更改喇叭静音模式				value = 1 时静音，0表示没静音
	CSF_DenoiseFlg			= 7,		-- 麦克风降噪音						value = 1 时表示开启，0表示关闭
	CSF_AECFlg				= 8,		-- 回声消除							value = 1 时表示开启，0表示关闭
	CSF_SpeakMode			= 9,		-- 说话模式							value = 0 鼠标, 1 按键, 2 自由
	CSF_SpeakKey			= 10,		-- 按键		
};
local SPEAKMODE = {
	SPM_MOUSEMOD			= 0,		-- 鼠标说话 
	SPM_KEYMODE				= 1,		-- 按键说话
	SPM_FREEMOD				= 2,		-- 自由说话
};
local COMFLG = {
	CMF_On = 1,
	CMF_Off = 0,
	CMF_MuteOn = 1,
	CMF_MuteOff = 0,
	CMF_Lock = 1;
	CMF_UnLock = 0;
};
local default_db = {
	chk_free_lock = COMFLG.CMF_UnLock,
	chk_key_lock = COMFLG.CMF_UnLock,
	slider_vol_lock = COMFLG.CMF_UnLock,
	slider_mic_lock = COMFLG.CMF_UnLock,
	microphoneflg = COMFLG.CMF_On,
	microphonevolume = 100,
	microphonemuteflg = COMFLG.CMF_MuteOff,
	microphoneenhance = COMFLG.CMF_On,
	speakervolume = 100,
	speakermuteflg = COMFLG.CMF_MuteOff,
	denoiseflg = COMFLG.CMF_On,
	aecflg = COMFLG.CMF_On,
	speakmode = SPEAKMODE.SPM_FREEMOD,
	speakkey = 84,
	speakkey_scancode = 0,
	user_operating = true,					-- 是否用户主动操作
	has_mute_count = false,					-- 是否有上报过静音统计
	has_unmute_count = false,				-- 是否有上报过取消静音统计
};
local change_settings_funclist = {};

-- 初始化函数
function tvsettingtab:OnInitialize()
	self:DisableDebug();
	-- self:EnableDebug();
	self:debug("OnInitialize");
	self.CSETFLG = CSETFLG;
	self.COMFLG = COMFLG;
	self.SPEAKMODE = SPEAKMODE;
	self.db = default_db;
	self:SetFuncList();
	
	self:init_wnd();
	self:RegisterEvents();

	local icon_arry = {
		"set:YYUI image:TabSettingIconNormal",
		"set:YYUI image:TabSettingIconSelected",
		"set:YYUI image:TabSettingIconSelected"
	}
	self:SendMessage("MSG_TEAMVOICE_ADD_TAB_PAGE", self.obj_wnd_setting, icon_arry);

end

function tvsettingtab:RegisterEvents()
	self:RegisterEvent("YYT_TO_PIP_CHANGE_SETTINGS", "on_change_settings");
	self:RegisterEvent("YYT_TO_PIP_JOIN_TEAM", "on_join_channel");
	self:RegisterEvent("WM_TEAMVOICE_SETDEFAULTKEY", "on_teamvoice_setdefaultkey");
	self:RegisterEvent("WM_TVSHOW_FREESPEAK_BUTTON", "on_show_freespeak_button");
	
	self:RegisterMessage("MSG_TVSHOW_PAGE_EDGE", "on_show_edge");
	
	self.root:subscribeEvent("KeyDown", self.on_root_keydown, self);
	self.root:subscribeEvent("KeyUp", self.on_root_keyup, self);
end

-- 显示隐藏‘自由说话’按钮
function tvsettingtab:on_show_freespeak_button(event, show)
	if not show then
		self.obj_chk_free:hide()
		self.obj_txt_key:show()
		self.obj_chk_key:hide()
		self.obj_hotkey:hide()
		self.obj_chk_key:setSelected(true)
		self.obj_hotkey:setProperty("UnifiedAreaRect","{{0,85},{0,18},{0,141},{0,41}}")
		self.obj_chk_enhancemic:setProperty("UnifiedAreaRect","{{0,10},{0,53},{0,100},{0,68}}")
		self.obj_chk_AEC:setProperty("UnifiedAreaRect","{{0,10},{0,85},{0,80},{0,100}}")
		self.obj_btn_vol:setProperty("UnifiedAreaRect","{{0,11},{0,119},{0,29},{0,137}}")
		self.obj_btn_mic:setProperty("UnifiedAreaRect","{{0,82},{0,119},{0,100},{0,137}}")
		self.obj_slider_vol:setProperty("UnifiedAreaRect","{{0,32},{0,122},{0,71},{0,142}}")
		self.obj_slider_mic:setProperty("UnifiedAreaRect","{{0,102},{0,122},{0,141},{0,137}}")
	else
		self.obj_chk_free:show()
		self.obj_txt_key:hide()
		self.obj_chk_key:show()
		self.obj_hotkey:show()
		self.obj_hotkey:setProperty("UnifiedAreaRect","{{0,84},{0,16},{0,139},{0,39}}")
		self.obj_chk_enhancemic:setProperty("UnifiedAreaRect","{{0,10},{0,69},{0,100},{0,84}}")
		self.obj_chk_AEC:setProperty("UnifiedAreaRect","{{0,10},{0,94},{0,80},{0,109}}")
		self.obj_btn_vol:setProperty("UnifiedAreaRect","{{0,10},{0,121},{0,28},{0,139}}")
		self.obj_btn_mic:setProperty("UnifiedAreaRect","{{0,79},{0,121},{0,97},{0,139}}")
		self.obj_slider_vol:setProperty("UnifiedAreaRect","{{0,32},{0,124},{0,70},{0,144}}")
		self.obj_slider_mic:setProperty("UnifiedAreaRect","{{0,100},{0,124},{0,138},{0,139}}")
	end
end

function tvsettingtab:init_wnd()
	self:SendMessage("MSG_TEAMVOICE_UPDATE_MAINBAR_TEXT", true);

	self.root = CEGUI.System:getSingleton():getGUISheet();
	self.wnd_mgr = CEGUI.WindowManager:getSingleton();
	
	self.obj_wnd_setting = self.wnd_mgr:getWindow("SettingFrame");

	self.obj_chk_free = self.wnd_mgr:getWindow("SettingFrame/SpeakFreeChk");
	self.obj_chk_free = CEGUI.toCheckbox(self.obj_chk_free);

	self.obj_txt_key = self.wnd_mgr:getWindow("SettingFrame/SpeakKeyText");
	
	self.obj_chk_key = self.wnd_mgr:getWindow("SettingFrame/SpeakKeyChk");
	self.obj_chk_key = CEGUI.toCheckbox(self.obj_chk_key);

	self.obj_chk_enhancemic = self.wnd_mgr:getWindow("SettingFrame/EnhanceMicChk");
	self.obj_chk_enhancemic = CEGUI.toCheckbox(self.obj_chk_enhancemic);
	
	self.obj_chk_AEC = self.wnd_mgr:getWindow("SettingFrame/AECChk");
	self.obj_chk_AEC = CEGUI.toCheckbox(self.obj_chk_AEC);

	self.obj_hotkey = self.wnd_mgr:getWindow("SettingFrame/SpeakHotKey");
	self.obj_hotkey = CEGUI.toHotkeyCtrl(self.obj_hotkey);

	self.obj_btn_vol = self.wnd_mgr:getWindow("SettingFrame/VolBtn");
	self.obj_btn_mic = self.wnd_mgr:getWindow("SettingFrame/MicBtn");

	self.obj_slider_vol = self.wnd_mgr:getWindow("SettingFrame/SliderVol");
	self.obj_slider_vol = CEGUI.toSlider(self.obj_slider_vol);

	self.obj_slider_mic = self.wnd_mgr:getWindow("SettingFrame/SliderMic");
	self.obj_slider_mic = CEGUI.toSlider(self.obj_slider_mic);

	self.obj_btn_close = self.wnd_mgr:getWindow("SettingFrame/CloseBtn");

	self.obj_top_edge = self.wnd_mgr:getWindow("SettingFrame/bg/head");
	self.obj_bottom_edge = self.wnd_mgr:getWindow("SettingFrame/bg/bottom");
	
	self.obj_slider_vol:setMaxValue(100)
	self.obj_slider_vol:setClickStep(10)
	self.obj_slider_mic:setMaxValue(100)
	self.obj_slider_mic:setClickStep(10)

	self.obj_wnd_setting:hide();
	self:RegistrEvents();
end

-- 显示上下边沿黑线
function tvsettingtab:on_show_edge(event, mode)
	if mode ~= nil then
		if mode == 0 then
			self.obj_top_edge:show()
			self.obj_bottom_edge:hide()
		elseif mode == 1 then
			self.obj_top_edge:hide()
			self.obj_bottom_edge:show()
		end
	end
end

function tvsettingtab:SetFuncList()
	change_settings_funclist[CSETFLG.CSF_MicrophoneFlg] = tvsettingtab.on_change_settings_microphoneflg;
	change_settings_funclist[CSETFLG.CSF_MicrophoneVolume] = tvsettingtab.on_change_settings_microphonevolume;
	change_settings_funclist[CSETFLG.CSF_MicrophoneMuteFlg] = tvsettingtab.on_change_settings_microphonemuteflg;
	change_settings_funclist[CSETFLG.CSF_MicrophoneEnhance] = tvsettingtab.on_change_settings_microphoneenhance;
	change_settings_funclist[CSETFLG.CSF_SpeakerVolume] = tvsettingtab.on_change_settings_speakervolume;
	change_settings_funclist[CSETFLG.CSF_SpeakerMuteFlg] = tvsettingtab.on_change_settings_speakermuteflg;
	change_settings_funclist[CSETFLG.CSF_DenoiseFlg] = tvsettingtab.on_change_settings_denoiseflg;
	change_settings_funclist[CSETFLG.CSF_AECFlg] = tvsettingtab.on_change_settings_aecflg;
	change_settings_funclist[CSETFLG.CSF_SpeakMode] = tvsettingtab.on_change_settings_speakmode;
	change_settings_funclist[CSETFLG.CSF_SpeakKey] = tvsettingtab.on_change_settings_speakkey;
end

function tvsettingtab:on_root_keydown(args)
	local ret = false;

	local key_args = CEGUI.toKeyEventArgs(args);
	if (key_args.scancode == tvsettingtab.db.speakkey_scancode and tvsettingtab.db.speakmode == tvsettingtab.SPEAKMODE.SPM_KEYMODE) then
		common.interface.tvsettingtab:set_microphoneflg(tvsettingtab.COMFLG.CMF_On);
		ret = true;
	end

	return ret;
end

function tvsettingtab:on_root_keyup(args)
	local ret = false;
	
	local key_args = CEGUI.toKeyEventArgs(args);
	if (key_args.scancode == tvsettingtab.db.speakkey_scancode and tvsettingtab.db.speakmode == tvsettingtab.SPEAKMODE.SPM_KEYMODE) then
		common.interface.tvsettingtab:set_microphoneflg(tvsettingtab.COMFLG.CMF_Off);
		ret = true;
	end
	
	return ret;
end

function tvsettingtab:on_teamvoice_setdefaultkey(event, key, keymod)
	local sepakset = common.interface.config:read("SPEAK_INFO", "user_speakset", 0);
	local sepakmod = common.interface.config:read("SPEAK_INFO", "user_speakmode", 0);

	self:debug(("on_teamvoice_setdefaultkey key:%s, keymod:%s"):format(tostring(key), tostring(keymod)));

	-- 用户从来没有主动设置过
	if sepakset == 0 or sepakset == "0" then
		self.db.user_operating = false;
		self.obj_hotkey:setHotkey(key);
		self.db.user_operating = true;
	end
	if keymod == true then
		if sepakmod == 0 or sepakmod == "0" then
			self.db.user_operating = false;
			self.obj_chk_key:setSelected(true);
			self.db.user_operating = true;
		end
	end
end

function tvsettingtab:on_join_channel(event)
	if TeamTalkClient:getSingleton():IsInternetCafe() == true then
		self.db.user_operating = false;
		self.obj_chk_key:setSelected(true);
		self.db.user_operating = true;
	end
end

function tvsettingtab:RegistrEvents()
	self.obj_wnd_setting:subscribeEvent("Hidden", self.on_wnd_hide, self);
	self.obj_hotkey:subscribeEvent("HotkeyChanged", self.on_hotkey_changed_speak, self);
	self.obj_chk_free:subscribeEvent("CheckStateChanged", self.on_speakfree_checked, self);
	self.obj_chk_key:subscribeEvent("CheckStateChanged", self.on_speakkey_checked, self );
	self.obj_chk_enhancemic:subscribeEvent("CheckStateChanged", self.on_enhancemic_checked, self );
	self.obj_chk_AEC:subscribeEvent("CheckStateChanged", self.on_acemic_checked, self );
	self.obj_btn_vol:subscribeEvent("Clicked", self.on_btn_vol_clicked, self);
	self.obj_btn_mic:subscribeEvent("Clicked", self.on_btn_mic_clicked, self);
	self.obj_btn_close:subscribeEvent("Clicked", self.on_btn_close_clicked, self);
	self.obj_slider_vol:subscribeEvent("ThumbTrackEnded", self.on_slider_vol, self);
	self.obj_slider_mic:subscribeEvent("ThumbTrackEnded", self.on_slider_mic, self);
	self.obj_slider_vol:subscribeEvent("ValueChanged", self.on_slider_vol, self);
	self.obj_slider_mic:subscribeEvent("ValueChanged", self.on_slider_mic, self);
end

function tvsettingtab:on_change_settings(event, type_flg, value)
	self:debug(("on_change_settings type_flg:%d, value:%d"):format(type_flg, value));
	local func = change_settings_funclist[type_flg];
	if (func) then
		func(self, value);
	else
		self:error(("error type_flg:%d"):format(type_flg));
	end
end

function tvsettingtab:on_change_settings_microphoneflg(value)
	self:debug(("on_change_settings_microphoneflg value:%d"):format(value));
	self.db.microphoneflg = value;
end

function tvsettingtab:on_change_settings_microphonevolume(value)

	self:debug(("on_change_settings_microphonevolume value:%d"):format(value));
	
	self.db.slider_mic_lock = COMFLG.CMF_Lock;
	self.db.microphonevolume = value;
	local nSize = self.db.microphonevolume or 80;
	self.obj_slider_mic:setCurrentValue(math.floor(nSize));
	self.db.slider_mic_lock = COMFLG.CMF_UnLock;
end

function tvsettingtab:on_change_settings_microphonemuteflg(value)
	self:debug(("on_change_settings_microphonemuteflg value:%d"):format(value));
	self.db.microphonemuteflg = value;

	if (self.db.microphonemuteflg == COMFLG.CMF_MuteOff) then
		self.obj_btn_mic:setID(COMFLG.CMF_MuteOff);
		self.obj_btn_mic:setProperty("HoverImage", "set:YYUI image:AdvSpeakHover");
		self.obj_btn_mic:setProperty("PushedImage", "set:YYUI image:AdvSpeakPushed");
		self.obj_btn_mic:setProperty("NormalImage", "set:YYUI image:AdvSpeakNormal");
		if (self.db.speakermuteflg == COMFLG.CMF_MuteOff) then
			-- 发送取消屏蔽声音统计信息 
			if  self.db.has_unmute_count == false then
				self.db.has_unmute_count = true
				common.hiido:Count("miniyy_voice_unmute", 1);
			end
		end
	else
		-- 检查喇叭是否也静音，如果是的话，把mainbar工具条的喇叭按钮设置成全静音状态
		if (self.db.speakermuteflg == COMFLG.CMF_MuteOn) then
			-- 发送屏蔽声音统计信息 
			if  self.db.has_mute_count == false then
				self.db.has_mute_count = true;
				common.hiido:Count("miniyy_voice_mute", 1);
			end
		end
		self.obj_btn_mic:setID(COMFLG.CMF_MuteOn);
		self.obj_btn_mic:setProperty("HoverImage", "set:YYUI image:AdvNoSpeakHover");
		self.obj_btn_mic:setProperty("PushedImage", "set:YYUI image:AdvNoSpeakPushed");
		self.obj_btn_mic:setProperty("NormalImage", "set:YYUI image:AdvNoSpeakNormal");
	end
end

function tvsettingtab:on_change_settings_microphoneenhance(value)
	self:debug(("on_change_settings_microphoneenhance value:%d"):format(value));
	self.db.microphoneenhance = value;
	
	if(self.db.microphoneenhance == COMFLG.CMF_On) then
		self.obj_chk_enhancemic:setSelected(true);
	else
		self.obj_chk_enhancemic:setSelected(false);
	end
end

function tvsettingtab:on_change_settings_speakervolume(value)
	self:debug(("on_change_settings_speakervolume value:%d"):format(value));
	
	self.db.slider_vol_lock = COMFLG.CMF_Lock;
	self.db.speakervolume = value;
	local nSize = self.db.speakervolume or 80;
	self.obj_slider_vol:setCurrentValue(math.floor(nSize));
	self.db.slider_vol_lock = COMFLG.CMF_UnLock;
end

function tvsettingtab:on_change_settings_speakermuteflg(value)
	self:debug(("on_change_settings_speakermuteflg value:%d"):format(value));
	self.db.speakermuteflg = value;

	if (self.db.speakermuteflg == COMFLG.CMF_MuteOff) then
		self.obj_btn_vol:setID(COMFLG.CMF_MuteOff);
		self.obj_btn_vol:setProperty("HoverImage", "set:YYUI image:AdvListenHover");
		self.obj_btn_vol:setProperty("PushedImage", "set:YYUI image:AdvListenPushed");
		self.obj_btn_vol:setProperty("NormalImage", "set:YYUI image:AdvListenNormal");
		if (self.db.microphonemuteflg == COMFLG.CMF_MuteOff) then
			-- 发送取消屏蔽声音统计信息 
			if  self.db.has_unmute_count == false then
				self.db.has_unmute_count = true
				common.hiido:Count("miniyy_voice_unmute", 1);
			end
		end
	else
		-- 检查麦克风是否也静音，如果是的话，把mainbar工具条的喇叭按钮设置成全静音状态
		if (self.db.microphonemuteflg == COMFLG.CMF_MuteOn) then
			-- 发送屏蔽声音统计信息 
			if  self.db.has_mute_count == false then
				self.db.has_mute_count = true;
				common.hiido:Count("miniyy_voice_mute", 1);
			end
		end
		self.obj_btn_vol:setID(COMFLG.CMF_MuteOn);
		self.obj_btn_vol:setProperty("HoverImage", "set:YYUI image:AdvNoListenHover");
		self.obj_btn_vol:setProperty("PushedImage", "set:YYUI image:AdvNoListenPushed");
		self.obj_btn_vol:setProperty("NormalImage", "set:YYUI image:AdvNoListenNormal");
	end
end

function tvsettingtab:on_change_settings_denoiseflg(value)
	self:debug(("on_change_settings_denoiseflg value:%d"):format(value));
	self.db.denoiseflg = value;
end

function tvsettingtab:on_change_settings_aecflg(value)
	self:debug(("on_change_settings_aecflg value:%d"):format(value));
	self.db.aecflg = value;

	if(self.db.aecflg == COMFLG.CMF_On) then
		self.obj_chk_AEC:setSelected(true);
	else
		self.obj_chk_AEC:setSelected(false);
	end
end

function tvsettingtab:on_change_settings_speakmode(value)
	self:debug(("on_change_settings_speakmode value:%d"):format(value));
	self.db.speakmode = value;
	
	self.db.user_operating = false;

	if (self.db.speakmode == SPEAKMODE.SPM_KEYMODE) then	-- 按键说话
		self.db.chk_free_lock = COMFLG.CMF_Lock;
		self.db.chk_key_lock = COMFLG.CMF_Lock;
		common.interface.tvsettingtab:set_microphoneflg(tvsettingtab.COMFLG.CMF_Off);
		self.obj_chk_free:setSelected(false);
		self.obj_chk_key:setSelected(true);
		self.obj_hotkey:enable();
		self.db.chk_free_lock = COMFLG.CMF_UnLock;
		self.db.chk_key_lock = COMFLG.CMF_UnLock;
	elseif (self.db.speakmode == SPEAKMODE.SPM_FREEMOD) then	-- 自由说话
		self.db.chk_free_lock = COMFLG.CMF_Lock;
		self.db.chk_key_lock = COMFLG.CMF_Lock;
		common.interface.tvsettingtab:set_microphoneflg(tvsettingtab.COMFLG.CMF_On);
		self.obj_chk_free:setSelected(true);
		self.obj_chk_key:setSelected(false);
		self.obj_hotkey:disable();
		self.db.chk_free_lock = COMFLG.CMF_UnLock;
		self.db.chk_key_lock = COMFLG.CMF_UnLock;
	end

	self.db.user_operating = true;
	self:SendMessage("MSG_TEAMVOICE_UPDATE_MAINBAR_TEXT", true);
end

function tvsettingtab:on_change_settings_speakkey(value)
	self:print("on_change_settings_speakkey value=" ..value)
	self.db.speakkey = value;
	self.db.user_operating = false;
	self.obj_hotkey:setHotkey(self.db.speakkey);
	self.db.user_operating = true;
	self:SendMessage("MSG_TEAMVOICE_UPDATE_MAINBAR_TEXT", true);
end

function tvsettingtab:on_wnd_hide(args)
end

function tvsettingtab:on_hotkey_changed_speak(args)
	local code = self.obj_hotkey:getHotkey();
	local scancode = self.obj_hotkey:getScanCode();

	-- 通知teamvoice插件更新说话按键
	self:SendMessage("MSG_TEAMVOICE_UPDATE_SPEAK_KEY", code);
	
	self.db.speakkey = code;
	self.db.speakkey_scancode = scancode;

	local key_name = CUIControl:getSingleton():GetKeyNameFromVkCode(self.db.speakkey, 1);
	if (key_name == "Space") then
		key_name = "空格";
	elseif (key_name == "Caps Lock") then
		key_name = "Caps";
	end
	self.obj_txt_key:setText("按住 " .. key_name .. " 键说话");

	self.obj_hotkey:deactivate();
	common.interface.tvsettingtab:set_speakkey(code);
	
	if self.db.user_operating == true then
		common.interface.config:write("SPEAK_INFO", "user_speakset", "1");
	end

	return true;
end

function tvsettingtab:on_speakfree_checked(args)
	if (self.db.chk_free_lock ~= COMFLG.CMF_Lock) then
		if (self.db.speakmode == SPEAKMODE.SPM_FREEMOD) then	-- 自由说话
			self.obj_chk_free:setSelected(true);
		else
			common.interface.tvsettingtab:set_speakmode(SPEAKMODE.SPM_FREEMOD);
			
			if self.db.user_operating == true then
				common.interface.config:write("SPEAK_INFO", "user_speakmode", "1");
			end
		end
	end
	return true;
end

function tvsettingtab:on_speakkey_checked(args)
	if (self.db.chk_key_lock ~= COMFLG.CMF_Lock) then
		if (self.db.speakmode == SPEAKMODE.SPM_KEYMODE) then	-- 按键说话
			self.obj_chk_key:setSelected(true);
		else
			common.interface.tvsettingtab:set_speakmode(SPEAKMODE.SPM_KEYMODE);
			
			if self.db.user_operating == true then
				common.interface.config:write("SPEAK_INFO", "user_speakmode", "1");
			end
		end
	end
	return true;
end

function tvsettingtab:on_enhancemic_checked(args)
	if (self.obj_chk_enhancemic:isSelected() == true) then
		common.interface.tvsettingtab:set_denoiseflg(COMFLG.CMF_On);
		common.interface.tvsettingtab:set_microphoneenhance(COMFLG.CMF_On);
		
	else
		common.interface.tvsettingtab:set_denoiseflg(COMFLG.CMF_Off);
		common.interface.tvsettingtab:set_microphoneenhance(COMFLG.CMF_Off);
	end
end

function tvsettingtab:on_acemic_checked(args)
	if (self.obj_chk_AEC:isSelected() == true) then
		common.interface.tvsettingtab:set_aecflg(COMFLG.CMF_On);
	else
		common.interface.tvsettingtab:set_aecflg(COMFLG.CMF_Off);
	end
end

function tvsettingtab:on_btn_vol_clicked(args)
	if (self.obj_btn_vol:getID() == COMFLG.CMF_MuteOn) then
		self.obj_btn_vol:setID(COMFLG.CMF_MuteOff);
		common.interface.tvsettingtab:set_speakermuteflg(COMFLG.CMF_MuteOff);
	else
		self.obj_btn_vol:setID(COMFLG.CMF_MuteOn);
		common.interface.tvsettingtab:set_speakermuteflg(COMFLG.CMF_MuteOn);
	end
	return true;
end

function tvsettingtab:on_btn_mic_clicked(args)
	if (self.obj_btn_mic:getID() == COMFLG.CMF_MuteOn) then
		self.obj_btn_mic:setID(COMFLG.CMF_MuteOff);
		common.interface.tvsettingtab:set_microphonemuteflg(COMFLG.CMF_MuteOff);
	else
		self.obj_btn_mic:setID(COMFLG.CMF_MuteOn);
		common.interface.tvsettingtab:set_microphonemuteflg(COMFLG.CMF_MuteOn);
	end
	return true;
end

function tvsettingtab:on_btn_close_clicked(args)
	return true;
end

function tvsettingtab:on_slider_vol(args)
	if (self.db.slider_vol_lock ~= COMFLG.CMF_Lock) then
		local nSize = self.obj_slider_vol:getCurrentValue();
		common.interface.tvsettingtab:set_speakervolume(math.floor(nSize));
	end
	return true;
end

function tvsettingtab:on_slider_mic(args)
	if (self.db.slider_mic_lock ~= COMFLG.CMF_Lock) then
		local nSize = self.obj_slider_mic:getCurrentValue();
		common.interface.tvsettingtab:set_microphonevolume(math.floor(nSize));
	end
	return true;
end
