package com.tcl.factory.impl;

import android.os.Message;
import android.util.Log;
import android.widget.Toast;

import com.tcl.factory.commands.FactoryCommandEvent;
import com.tcl.factory.commands.IFactoryCommandsListener;
import com.tcl.factory.thirdparty.ThirdParty;
import com.tcl.factory.utils.Debug;
import com.tcl.factory.view.InfoService;

public class FactoryCommandsListener implements IFactoryCommandsListener {

	private final String TAG = "FactoryCommandsListener";
	
	@Override
	public boolean onEvent(FactoryCommandEvent commandEvent) {
		int cmd_data_type = commandEvent.getCode();// 类型
		int keyCode = commandEvent.getData1();// 参数
		Log.d(TAG, "0712 onEvent cmd_data_type=" + cmd_data_type);
		int cmd_type = (cmd_data_type & 0xff00) >> 8;
//		Toast.makeText(ThirdParty.mContext, "kode="+cmd_data_type+"__"+keyCode, 3000).show();
		if (cmd_type == 0x0F) {// 取高位为0x0F 表示处理串口逻辑 else 处理按键逻辑
			int cmd_data = cmd_data_type & 0x00ff; // 取低8位
			Log.d(TAG, "cmd_type =" + cmd_type + " ");
			Message msg = new Message();
			msg.what = 0;
			msg.arg1 = cmd_data;
			msg.arg2 = keyCode;
			InfoService.serialAndKeyHandler.sendMessage(msg);
			// IRManager.parserSerial(cmd_data,keyCode);
		} else {

			Debug.v(TAG, "cmd_data==" + commandEvent.getCode() + "keyCode="
					+ commandEvent.getData1());
			Message msg = new Message();
			msg.what = 1;
			msg.arg1 = cmd_data_type;
			msg.arg2 = keyCode;
			InfoService.serialAndKeyHandler.sendMessage(msg);
			// IRManagerListener.parserEvent(cmd_data_type,keyCode);
		}
		return false;
	}
}
