/*
 * Copyright (c) 2015. Ncomz. All Rights Reserved
 */

package com.ntels.kneet.v3.view.rules;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Toast;

import com.ntels.kneet.v3.common.AppConfig;
import com.ntels.kneet.v3.common.Constants;
import com.ntels.kneet.v3.common.http.HttpSend;
import com.ntels.kneet.v3.common.http.Response;
import com.ntels.kneet.v3.common.c_interface.List_Interface;
import com.ntels.kneet.v3.common.c_interface.Main_Interface;
import com.ntels.kneet.v3.common.c_interface.OnDataSendToReslut;
import com.ntels.kneet.v3.common.util.Dlog;
import com.ntels.kneet.v3.common.util.Util;
import com.ntels.kneet.v3.common.widget.CustomActivity;
import com.ntels.kneet.v3.R;
import com.ntels.kneet.v3.view.dialog.CustomDialog;
import com.ntels.kneet.v3.view.dialog.Dialog_Spinner;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Locale;

import jp.wasabeef.recyclerview.adapters.AlphaInAnimationAdapter;
import jp.wasabeef.recyclerview.adapters.ScaleInAnimationAdapter;

public class Rules_Things_Select extends CustomActivity implements View.OnClickListener,
                                                                   CustomDialog.OnMsgAlterToResult,
                                                                   List_Interface {

    /** Called when the activity is first created. */

    private Toolbar   toolbar;
    private AppConfig appConfig;
    Main_Interface mCallback;
    private Util util = new Util();
    private Intent   intent;
    private Activity act;
    //    private DecimalFormat decimalFormat = new DecimalFormat("00");

    private CustomDialog                       customDialog          = new CustomDialog();
    private String                             sCallType             = "";
    private String                             sTemperature          = "";
    private ArrayList<HashMap<String, Object>> alList_Triggers       = new ArrayList<HashMap<String, Object>>();
    private ArrayList<HashMap<String, Object>> alList_Conditions     = new ArrayList<HashMap<String, Object>>();
    private ArrayList<HashMap<String, Object>> alList_Actions        = new ArrayList<HashMap<String, Object>>();
    private int                                iDevicesPosition      = -1;
    private int                                iSelectedPosition     = -1;
    private String                             sDevices_Select_Title = "";
    private String                             sDevices              = "";
    private String                             sDevices_Code         = "";
    private String                             sHTTP_item_type_code  = "";
    private String                             sDEVICE_ID            = "";
    private String                             sNODE_ID              = "";
    private ArrayList<String>                  alDevicesTitle        = new ArrayList<String>();
    private ArrayList<String>                  alDevicesId           = new ArrayList<String>();
    private ArrayList<String>                  alDevicesImage        = new ArrayList<String>();
    private ArrayList<String>                  alDevicesViewImage    = new ArrayList<String>();
    private ArrayList<HashMap<String, Object>> alTotalList           = new ArrayList<HashMap<String, Object>>();
    //    private View vSelectView;

    int iScreenType = 0;
    /*통신 관련*/
    private              ArrayList<HashMap<String, Object>> alAllTotalList                              = new ArrayList<HashMap<String, Object>>();
    private              int                                iType                                       = 0;
    private static final int                                MSG_COM_G_RULES_ITEM_DEVICES_ITEM_TYPE_CODE = 1;
    private Rules_Things_Select_Adapter dataAdapter;
    private RecyclerView                rcvList;
    private boolean bListHeader        = false;
    private boolean bListFooter        = false;
    private boolean bListFooterVisible = false;
    private boolean bListFooterAnd     = false;
    private int     iListColumnsCnt    = 1;
    private GridLayoutManager   glmList;
    private LinearLayoutManager llmList;
    //    private MyLinearLayoutManager llmList;
    private int iSelectPosition = -1;

    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        act = Rules_Things_Select.this;
        appConfig = (AppConfig) act.getApplicationContext();
        customDialog.setOnMsgAlterToResultEvent(this);

        View viewToLoad = LayoutInflater.from(act).inflate(R.layout.rules_things_select, null);
        this.setContentView(viewToLoad);
        String sTempHour = "";
        if ( savedInstanceState != null ) {

        } else {
            Intent intent = getIntent();

            //1:트리거, 2:액션, 3:컨디션, 4:모드
            sCallType = util.null2string(intent.getStringExtra(Constants.EXTRA_CALL_TYPE));
            sDEVICE_ID = util.null2string(intent.getStringExtra(Constants.EXTRA_DEVICE_ID));
            sNODE_ID = util.null2string(intent.getStringExtra(Constants.EXTRA_NODE_ID));
            iSelectedPosition = intent.getIntExtra(Constants.EXTRA_POSITION, 0);
            alList_Triggers = (ArrayList<HashMap<String, Object>>) intent.getSerializableExtra(Constants.EXTRA_TRIGGERS);
            alList_Conditions = (ArrayList<HashMap<String, Object>>) intent.getSerializableExtra(Constants.EXTRA_CONDITIONS);
            alList_Actions = (ArrayList<HashMap<String, Object>>) intent.getSerializableExtra(Constants.EXTRA_ACTIONS);
            //            sTemperature = intent.getStringExtra(Constants.EXTRA_TEMPERATURE);
        }

        displayListView();
    }

    private void displayListView() {

        util.getView(act, R.id.llBtn1).setOnClickListener(this);
        util.getView(act, R.id.llBtn2).setOnClickListener(this);

        util.setKeyboardHide(act, util.getLinearLayout(act, R.id.llPageRoot));
        //        util.setKeyboardHide(act, util.getLinearLayout(act, R.id.llBodyList));
        util.getView(act, R.id.llPageRoot).setVisibility(View.INVISIBLE);

        if ( sCallType.equals("1") ) {
            sHTTP_item_type_code = "01";
            sDevices_Select_Title = util.getString(act, R.string.layout_rules_triggers_select_05);
        } else if ( sCallType.equals("2") ) {
            sHTTP_item_type_code = "02";
            sDevices_Select_Title = util.getString(act, R.string.layout_rules_edit_04);
        } else if ( sCallType.equals("3") ) {
            sHTTP_item_type_code = "01";
            if (AppConfig.getLanguageType().equals(Locale.ENGLISH.toString())) {
                sDevices_Select_Title = util.getString(act, R.string.layout_rules_edit_09).substring(4);
            } else {
                sDevices_Select_Title = util.getString(act, R.string.layout_rules_edit_09);
            }
        } else if ( sCallType.equals("4") ) {
            sHTTP_item_type_code = "02";
            sDevices_Select_Title = util.getString(act, R.string.layout_rules_edit_04);
        }

        bListFooter = false;
        bListFooterVisible = true;
        dataAdapter = new Rules_Things_Select_Adapter(act, R.layout.row_rules_things_select, R.layout.row_rules_things_select, R.layout.row_rules_things_select, alTotalList, this);
        dataAdapter.setFooterCheck(bListFooter);
        //        dataAdapter.setFooterVisible(bListFooterVisible);

        rcvList = (RecyclerView) act.findViewById(R.id.rcvList);
        //        rcvList.setHasFixedSize(true);
        iListColumnsCnt = 1;
        if ( iListColumnsCnt == 1 ) {
            llmList = new LinearLayoutManager(act);
            //            llmList = new MyLinearLayoutManager(act);
            rcvList.setLayoutManager(llmList);
        } else {
            glmList = new GridLayoutManager(act, iListColumnsCnt, GridLayoutManager.VERTICAL, false);
            glmList.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
                @Override public int getSpanSize(int position) {

                    int iPositionType = dataAdapter.getItemViewType(position);
                    int iTotalConut = dataAdapter.getItemCount();
                    int iValueConut = dataAdapter.getItemCount();
                    if ( bListHeader ) {
                        iValueConut = iTotalConut - 1;
                    }

                    if ( iPositionType == dataAdapter.TYPE_HEADER ) {
                        return glmList.getSpanCount();
                    } else {
                        return dataAdapter.getItemViewType(position) == 1 ? 1 : (iValueConut % iListColumnsCnt == 1 ? glmList.getSpanCount() : 1);
                    }
                }
            });
            rcvList.setLayoutManager(glmList);
        }

        //        rcvList.setItemAnimator(new FadeInAnimator());
        //        rcvList.setAdapter(dataAdapter);
        AlphaInAnimationAdapter alphaAdapter = new AlphaInAnimationAdapter(dataAdapter);
        alphaAdapter.setDuration(150);
        ScaleInAnimationAdapter scaleAdapter = new ScaleInAnimationAdapter(alphaAdapter);
        scaleAdapter.setDuration(150);
        rcvList.setAdapter(scaleAdapter);

        ComHandler.sendMessageDelayed(ComHandler.obtainMessage(MSG_COM_G_RULES_ITEM_DEVICES_ITEM_TYPE_CODE), 10);
    }

    @Override public void onClick(View v) {

        switch (v.getId()) {
            case R.id.llBtn1:
                String sNode_id = "";
                //                int iCnt = util.getLinearLayout(act, R.id.llBodyList).getChildCount();

                Boolean bSelectCheck = false;
                int iTempSelectRow = -1;
                for ( int iRow = 0; iRow < alTotalList.size(); iRow++ ) {
                    Dlog.v("irow cnt =", iRow);
                    if ( alTotalList.get(iRow).get(Constants.HTTP_SELECT_YN).equals("Y") ) {
                        iTempSelectRow = iRow;
                        bSelectCheck = true;
                    }
                }
                if ( !bSelectCheck ) {
                    util.setShowToast(act, util.getString(act, R.string.MSG850), Toast.LENGTH_SHORT);
                    return;
                } else {
                    String sHTTP_source_sub_id = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_source_sub_id));
                    String sHTTP_source_sub_name = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_source_sub_name));
                    String sHTTP_control_min_value = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_control_min_value));
                    String sHTTP_control_max_value = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_control_max_value));
                    String sHTTP_control_step = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_control_step));
                    String sHTTP_unit = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_unit));
                    String sHTTP_data_type_code = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_data_type_code));
                    String sHTTP_cmdcls_type_id = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_type_id));
                    String sHTTP_cmdcls_code = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_code));
                    String sHTTP_cmdcls_type_name = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_type_name));
                    String sHTTP_cmdcls_type_system_name = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_type_system_name));
                    String sHTTP_cmdcls_value_list = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_value_list));
                    String sHTTP_cmdcls_value = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_value));
                    String sHTTP_cmdcls_value_msg = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_cmdcls_value_msg));
                    String sHTTP_condition_type_code = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_condition_type_code));
                    String sHTTP_condition_type_code_name = util.null2string(alTotalList.get(iTempSelectRow).get(Constants.HTTP_condition_type_code_name));

                    if ( sHTTP_cmdcls_value.equals("") ) {
                        util.setShowToast(act, util.getString(act, R.string.MSG826), Toast.LENGTH_SHORT);
                        return;
                    }
                    String sSOURCE_ID = "";
                    String sSOURCE_NAME = "";
                    String sSOURCE_SUB_ID = "";
                    String sSOURCE_SUB_NAME = "";
                    String sCONDITION_TYPE_CODE = "";
                    String sCONDITION_TYPE_CODE_NAME = "";
                    String sCMDCLS_VALUE = "";
                    String sCMDCLS_VALUE_MSG = "";
                    String sDATA_TYPE_CODE = "";
                    String sDAYOFWEEK = "";
                    String sREPEATABLE = "";
                    String sHOUR = "";
                    String sMINUTE = "";
                    String sUNIT = "";
                    String sIMAGE_FILE_NAME = "";
                    String sAVAILABLE_YN = "";

                    sSOURCE_ID = alDevicesId.get(iDevicesPosition);
                    sSOURCE_NAME = alDevicesTitle.get(iDevicesPosition);
                    sSOURCE_SUB_ID = sHTTP_source_sub_id;
                    sSOURCE_SUB_NAME = sHTTP_source_sub_name;
                    sCONDITION_TYPE_CODE = sHTTP_condition_type_code;
                    sCONDITION_TYPE_CODE_NAME = sHTTP_condition_type_code_name;
                    sCMDCLS_VALUE = sHTTP_cmdcls_value;
                    sCMDCLS_VALUE_MSG = sHTTP_cmdcls_value_msg;
                    sDATA_TYPE_CODE = sHTTP_data_type_code;
                    sUNIT = sHTTP_unit;
                    sIMAGE_FILE_NAME = alDevicesViewImage.get(iDevicesPosition);

                    HashMap<String, Object> hmItem_Sub = new HashMap<String, Object>();
                    hmItem_Sub.put(Constants.HTTP_source_id, sSOURCE_ID);
                    hmItem_Sub.put(Constants.HTTP_source_name, sSOURCE_NAME);
                    hmItem_Sub.put(Constants.HTTP_source_sub_id, sSOURCE_SUB_ID);
                    hmItem_Sub.put(Constants.HTTP_source_sub_name, sSOURCE_SUB_NAME);
                    hmItem_Sub.put(Constants.HTTP_condition_type_code, sCONDITION_TYPE_CODE);
                    hmItem_Sub.put(Constants.HTTP_condition_type_code_name, sCONDITION_TYPE_CODE_NAME);
                    hmItem_Sub.put(Constants.HTTP_cmdcls_value, sCMDCLS_VALUE);
                    hmItem_Sub.put(Constants.HTTP_cmdcls_value_msg, sCMDCLS_VALUE_MSG);
                    hmItem_Sub.put(Constants.HTTP_unit, sUNIT);
                    hmItem_Sub.put(Constants.HTTP_data_type_code, sDATA_TYPE_CODE);
                    hmItem_Sub.put(Constants.HTTP_dayofweek, sDAYOFWEEK);
                    hmItem_Sub.put(Constants.HTTP_repeatable, sREPEATABLE);
                    hmItem_Sub.put(Constants.HTTP_hour, sHOUR);
                    hmItem_Sub.put(Constants.HTTP_minute, sMINUTE);
                    hmItem_Sub.put(Constants.HTTP_image_file_name, sIMAGE_FILE_NAME);
                    hmItem_Sub.put(Constants.HTTP_available_yn, sAVAILABLE_YN);

                    ArrayList<HashMap<String, Object>> alTempList_Item_Sub = new ArrayList<HashMap<String, Object>>();
                    if ( sCallType.equals("1") ) {
                        alTempList_Item_Sub.clear();
                        alTempList_Item_Sub.add(hmItem_Sub);
                        alList_Triggers.clear();

                        HashMap<String, Object> hmTriggers = new HashMap<String, Object>();
                        hmTriggers.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                        hmTriggers.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_triggers_select_05));
                        hmTriggers.put(Constants.HTTP_item_sub_type_code, "01");

                        alList_Triggers.add(hmTriggers);
                    } else if ( sCallType.equals("2") ) {
                        hmItem_Sub.put(Constants.HTTP_action_type_code, "00");
                        HashMap<String, Object> hmTempActions = new HashMap<String, Object>();
                        if ( alList_Actions.size() > 0 ) {
                            Boolean bCheck = false;
                            for ( int iRow = 0; iRow < alList_Actions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iRow).get(Constants.HTTP_item_sub);
                                        if ( sDEVICE_ID.equals("") ) {
                                            //액션은 있지만 선택하지 않고 추가하는경우
                                            alTempList_Item_Sub.add(hmItem_Sub);
                                        } else {
                                            //액션은 있고 선택한 경우
                                            alTempList_Item_Sub.set(iSelectedPosition, hmItem_Sub);
                                        }
                                        bCheck = true;
                                        break;
                                    }
                                }
                            }
                            if ( !bCheck ) {
                                //액션은 있지만 선택하지 않고 디바이스액션이 없는경우 추가하는경우(메세지만 있는경우)
                                alTempList_Item_Sub.add(hmItem_Sub);
                                hmTempActions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_03));
                                hmTempActions.put(Constants.HTTP_item_sub_type_code, "01");
                                hmTempActions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                                alList_Actions.add(hmTempActions);
                            }
                        } else {
                            //액션이 아예 없는 경우
                            alTempList_Item_Sub.add(hmItem_Sub);
                            hmTempActions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_03));
                            hmTempActions.put(Constants.HTTP_item_sub_type_code, "01");
                            hmTempActions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                            alList_Actions.add(hmTempActions);
                        }
                    } else if ( sCallType.equals("3") ) {
                        hmItem_Sub.put(Constants.HTTP_action_type_code, "00");
                        HashMap<String, Object> hmTempConditions = new HashMap<String, Object>();
                        if ( alList_Conditions.size() > 0 ) {
                            Boolean bCheck = false;
                            for ( int iRow = 0; iRow < alList_Conditions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Conditions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Conditions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Conditions.get(iRow).get(Constants.HTTP_item_sub);
                                        if ( sDEVICE_ID.equals("") ) {
                                            //액션은 있지만 선택하지 않고 추가하는경우
                                            alTempList_Item_Sub.add(hmItem_Sub);
                                        } else {
                                            //액션은 있고 선택한 경우
                                            alTempList_Item_Sub.set(iSelectedPosition, hmItem_Sub);
                                        }
                                        bCheck = true;
                                        break;
                                    }
                                }
                            }
                            if ( !bCheck ) {
                                //액션은 있지만 선택하지 않고 디바이스액션이 없는경우 추가하는경우(메세지만 있는경우)
                                alTempList_Item_Sub.add(hmItem_Sub);
                                hmTempConditions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_08));
                                hmTempConditions.put(Constants.HTTP_item_sub_type_code, "01");
                                hmTempConditions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                                alList_Conditions.add(hmTempConditions);
                            }
                        } else {
                            //액션이 아예 없는 경우
                            alTempList_Item_Sub.add(hmItem_Sub);
                            hmTempConditions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_03));
                            hmTempConditions.put(Constants.HTTP_item_sub_type_code, "01");
                            hmTempConditions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                            alList_Conditions.add(hmTempConditions);
                        }
                    } else if ( sCallType.equals("4") ) {
                        hmItem_Sub.put(Constants.HTTP_action_type_code, "00");
                        HashMap<String, Object> hmTempActions = new HashMap<String, Object>();
                        if ( alList_Actions.size() > 0 ) {
                            Boolean bCheck = false;
                            for ( int iRow = 0; iRow < alList_Actions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iRow).get(Constants.HTTP_item_sub);
                                        if ( sDEVICE_ID.equals("") ) {
                                            //액션은 있지만 선택하지 않고 추가하는경우
                                            alTempList_Item_Sub.add(hmItem_Sub);
                                        } else {
                                            //액션은 있고 선택한 경우
                                            alTempList_Item_Sub.set(iSelectedPosition, hmItem_Sub);
                                        }
                                        bCheck = true;
                                        break;
                                    }
                                }
                            }
                            if ( !bCheck ) {
                                //액션은 있지만 선택하지 않고 디바이스액션이 없는경우 추가하는경우(메세지만 있는경우)
                                alTempList_Item_Sub.add(hmItem_Sub);
                                hmTempActions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_03));
                                hmTempActions.put(Constants.HTTP_item_sub_type_code, "01");
                                hmTempActions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                                alList_Actions.add(hmTempActions);
                            }
                        } else {
                            //액션이 아예 없는 경우
                            alTempList_Item_Sub.add(hmItem_Sub);
                            hmTempActions.put(Constants.HTTP_item_name, util.getString(act, R.string.layout_rules_detail_03));
                            hmTempActions.put(Constants.HTTP_item_sub_type_code, "01");
                            hmTempActions.put(Constants.HTTP_item_sub, alTempList_Item_Sub);
                            alList_Actions.add(hmTempActions);
                        }
                    }

                    intent = new Intent();
                    intent.putExtra(Constants.EXTRA_TRIGGERS, alList_Triggers);
                    intent.putExtra(Constants.EXTRA_ACTIONS, alList_Actions);
                    intent.putExtra(Constants.EXTRA_CONDITIONS, alList_Conditions);
                    act.setResult(RESULT_OK, intent);
                    finish();
                }
                break;
            case R.id.llBtn2:
                onBackPressed();
                break;
            default:
                break;
        }
    }

    @Override public void resultCustomDialogResponse(int iMsgID, int iBtnResult) {

        switch (iMsgID) {

            case Constants.MSG998:
                util.callApp_Start(act, "LOGOUT");
                break;
            case Constants.MSG997:
                util.callApp_Start(act, "HOME_RELOAD");
                break;
            case Constants.MSG807:
                if ( iBtnResult == 1 ) {
                    ComHandler.sendMessage(ComHandler.obtainMessage(MSG_COM_G_RULES_ITEM_DEVICES_ITEM_TYPE_CODE));
                } else {
                    onBackPressed();
                }
                break;
            default:
                break;
        }
    }

    @Override protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
    }

    @Override public void onBackPressed() {

        if ( iScreenType == 1 ) {
            iScreenType = 0;
            iDevicesPosition = -1;
            util.getView(act, R.id.llPageRoot).setVisibility(View.INVISIBLE);
            callDevicesList();
        } else {
            intent = new Intent();
            act.setResult(RESULT_CANCELED, intent);
            finish();
        }
    }

    void callDevicesList() {

        intent = new Intent();
        intent.setClass(act, Dialog_Spinner.class);
        intent.putExtra(Constants.EXTRA_SPINNER_LIST1, alDevicesTitle);
        intent.putExtra(Constants.EXTRA_SPINNER_ICON_LIST, alDevicesImage);

        intent.putExtra(Constants.EXTRA_SPINNER_TITLE, sDevices_Select_Title);
        intent.putExtra(Constants.EXTRA_SPINNER_TYPE, 0);
        intent.putExtra(Constants.EXTRA_SPINNER_POSITION, iDevicesPosition);
        util.callActivityForResultNoAnim(act, intent, Constants.ACT_SPINNER);
    }
    Handler ComHandler = new Handler(new IncomingHandlerCallBack());

    class IncomingHandlerCallBack implements Handler.Callback {

        @Override public boolean handleMessage(Message msg) {

            iType = msg.what;
            switch (msg.what) {
                case MSG_COM_G_RULES_ITEM_DEVICES_ITEM_TYPE_CODE:
                    //dialog_show();
                    send_G_rules_item_devices_item_type_code();
                    break;

                default:
                    break;
            }
            return true;
        }
    }

    /**
     * <PRE>
     * 1. MethodName: send_G_rules_item_devices_item_type_code
     * 2. ClassName :
     * 3. Comment   : [Send][GET]액션 장치의 목록 조회(규칙 아이템(조건,액션)으로 사용할 장치를 조회)
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    private void send_G_rules_item_devices_item_type_code() {

        try {
            HttpSend httpSend;

            //            httpSend = new HttpSend(act, !swipeRefreshLayout.isRefreshing());
            httpSend = new HttpSend(act);

            httpSend.setOnDataSendToReslutEvent(new OnDataSendToReslut() {
                @Override public void resultResponse(Response result) {

                    result_G_rules_item_devices_item_type_code(result);
                }
            });

            httpSend.G_rules_item_devices_item_type_code(sHTTP_item_type_code);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * <PRE>
     * 1. MethodName: result_G_rules_item_devices_item_type_code
     * 2. ClassName :
     * 3. Comment   : [Result][GET]액션 장치의 목록 조회(규칙 아이템(조건,액션)으로 사용할 장치를 조회)
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    private void result_G_rules_item_devices_item_type_code(Response rpResult) {

        try {
            if ( rpResult.getStatusCode() == 200 ) {
                ArrayList<HashMap<String, Object>> alList = util.jsonToArrayListMap(rpResult.getContent());
                if ( alList.size() > 0 ) {
                    for ( int iRow = 0; iRow < alList.size(); iRow++ ) {
                        HashMap<String, Object> hmTemp = new HashMap<String, Object>();
                        hmTemp = alList.get(iRow);
                        alAllTotalList.add(hmTemp);

                        String sHTTP_source_id = util.null2string(hmTemp.get(Constants.HTTP_source_id));
                        String sHTTP_source_name = util.null2string(hmTemp.get(Constants.HTTP_source_name));
                        String sHTTP_image_file_name = util.null2string(hmTemp.get(Constants.HTTP_image_file_name));
                        String sHTTP_image_file_view_name = util.null2string(hmTemp.get(Constants.HTTP_image_file_view_name));
                        alDevicesId.add(sHTTP_source_id);
                        alDevicesTitle.add(sHTTP_source_name);
                        alDevicesImage.add(sHTTP_image_file_name);
                        alDevicesViewImage.add(sHTTP_image_file_view_name);
                        //                        if ( sCOMMON_CODE.equals(sArea_Code) ) {
                        //                            iAreaPosition = iRow;
                        //                            String sArea = util.null2string(alAreaTitle.get(iAreaPosition));
                        //                            util.getTextView(act, R.id.tvArea).setText(sArea);
                        //                            util.getViewUnderline(act, R.id.tvArea);
                        //                        }
                    }
                }

                if ( sDEVICE_ID.equals("") ) {
                    callDevicesList();
                } else {
                    for ( int iRow2 = 0; iRow2 < alDevicesId.size(); iRow2++ ) {
                        if ( alDevicesId.get(iRow2).equals(sDEVICE_ID) ) {
                            iDevicesPosition = iRow2;
                            util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);
                            setDispNodes();
                            break;
                        }
                    }
                }
            } else {
                JSONObject joResult = new JSONObject(rpResult.getContent());
                Dlog.v(joResult.toString());
                String sERR_CODE = util.null2string(joResult.get(Constants.HTTP_err_code));
                String sERR_MSG = util.null2string(joResult.get(Constants.HTTP_err_msg));

                if ( sERR_CODE.equals("401") ) {
                    customDialog.MsgAlert(act, Constants.MSG998, sERR_MSG);
                } else if ( sERR_CODE.equals("401-106") ) {
                    customDialog.MsgAlert(act, Constants.MSG997, sERR_MSG);
                } else {
                    customDialog.MsgAlert(act, Constants.MSG000, sERR_MSG);
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            customDialog.MsgAlert(act, Constants.MSG807);
        }
    }

    @Override public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);
        Boolean bReload_Flag = false;
        if ( resultCode == RESULT_OK ) {
            switch (requestCode) {
                case Constants.ACT_SPINNER:
                    int iTempDevicesPosition = data.getIntExtra(Constants.EXTRA_SPINNER_RESULT, -1);
                    if ( iTempDevicesPosition == -1 ) {
                        util.setShowToast(act, util.getString(act, R.string.MSG827), Toast.LENGTH_SHORT);
                        callDevicesList();
                        break;
                    } else {
                        iScreenType = 1;
                        util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);
                        iDevicesPosition = iTempDevicesPosition;
                        setDispNodes();
                    }
                    break;
                case Constants.ACT_RULES_MULTISENSOR_SELECT:
                    String sTempMULTISENSOR = data.getStringExtra(Constants.EXTRA_MULTISENSOR);
                    String sTempUNIT = data.getStringExtra(Constants.EXTRA_UNIT);
                    String sTempCONDITION_TYPE_CODE = data.getStringExtra(Constants.EXTRA_CONDITION_TYPE_CODE);
                    String sTempCONDITION_TYPE_CODE_NAME = "";
                    if ( sTempCONDITION_TYPE_CODE.equals("03") ) {
                        sTempCONDITION_TYPE_CODE_NAME = util.getString(act, R.string.layout_sequentes);
                    } else {
                        sTempCONDITION_TYPE_CODE_NAME = util.getString(act, R.string.layout_over);
                    }

                    //                    util.getTextView(vSelectView, R.id.tvRulesCmd).setText(sTempMULTISENSOR + " " + (sTempMULTISENSOR.equals("") ? "" : sTempUNIT) + " " + (sTempMULTISENSOR.equals("")
                    //                                                                                                                                                            ? ""
                    //                                                                                                                                                            : sTempCONDITION_TYPE_CODE_NAME));

                    //                    int iTag = (int) vSelectView.getTag();
                    Dlog.v("sTempMULTISENSOR =" + sTempMULTISENSOR);
                    Dlog.v("sTempCONDITION_TYPE_CODE =" + sTempCONDITION_TYPE_CODE);
                    Dlog.v("sTempCONDITION_TYPE_CODE_NAME =" + sTempCONDITION_TYPE_CODE_NAME);
                    alTotalList.get(iSelectPosition).put(Constants.HTTP_cmdcls_value, sTempMULTISENSOR);
                    alTotalList.get(iSelectPosition).put(Constants.HTTP_condition_type_code, sTempCONDITION_TYPE_CODE);
                    alTotalList.get(iSelectPosition).put(Constants.HTTP_condition_type_code_name, sTempCONDITION_TYPE_CODE_NAME);
                    dataAdapter.notifyDataSetChanged();
                    break;
            }
        } else {
            switch (requestCode) {
                case Constants.ACT_SPINNER:
                    intent = new Intent();
                    //                    intent.putExtra(Constants.EXTRA_LOGOUT_FLAG, true);
                    act.setResult(RESULT_CANCELED, intent);
                    finish();
                    break;
                default:
                    break;
            }
        }
    }

    void setDispNodes() {

        //        util.getLinearLayout(act, R.id.llBodyList).removeAllViews();
        HashMap<String, Object> hmTemp = new HashMap<String, Object>();
        hmTemp = alAllTotalList.get(iDevicesPosition);

        String sTempHTTP_source_id = util.null2string(hmTemp.get(Constants.HTTP_source_id));
        String sTempHTTP_source_name = util.null2string(hmTemp.get(Constants.HTTP_source_name));
        String sTempHTTP_image_file_name = util.null2string(hmTemp.get(Constants.HTTP_image_file_name));
        String sTempHTTP_image_file_view_name = util.null2string(hmTemp.get(Constants.HTTP_image_file_view_name));

        //아이콘
        util.setImage(act, sTempHTTP_image_file_name, R.id.ivTitleIcon);
        //디바이스명
        util.getTextView(act, R.id.tvTitle).setText(sTempHTTP_source_name);

        alTotalList.clear();
        if ( !util.null2string(hmTemp.get(Constants.HTTP_item_sub)).equals("") ) {
            ArrayList<HashMap<String, Object>> alList_Item_Sub1 = (ArrayList<HashMap<String, Object>>) hmTemp.get(Constants.HTTP_item_sub);
            //            Dlog.v(" alTotalList.size()",  alTotalList.size());
            int iDefaultPostion = -1;
            for ( int iRow1 = 0; iRow1 < alList_Item_Sub1.size(); iRow1++ ) {
                HashMap<String, Object> hmTemp1 = new HashMap<String, Object>();
                hmTemp1 = alList_Item_Sub1.get(iRow1);
                String sHTTP_source_sub_id = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_source_sub_id));
                String sHTTP_source_sub_name = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_source_sub_name));
                String sHTTP_control_min_value = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_control_min_value));
                String sHTTP_control_max_value = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_control_max_value));
                String sHTTP_control_step = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_control_step));
                String sHTTP_unit = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_unit));
                String sHTTP_data_type_code = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_data_type_code));
                String sHTTP_cmdcls_type_id = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_cmdcls_type_id));
                String sHTTP_cmdcls_code = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_cmdcls_code));
                String sHTTP_cmdcls_type_name = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_cmdcls_type_name));
                String sHTTP_cmdcls_type_system_name = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_cmdcls_type_system_name));
                String sHTTP_cmdcls_value_list = util.null2string(alList_Item_Sub1.get(iRow1).get(Constants.HTTP_cmdcls_value_list));

                Dlog.v("sNODE_ID = " + sNODE_ID);
                Dlog.v("sHTTP_source_sub_id = " + sHTTP_source_sub_id);
                if ( sHTTP_source_sub_id.equals(sNODE_ID) ) {
                    String sSelectHTTP_cmdcls_value = "";
                    String sSelectHTTP_cmdcls_value_msg = "";
                    String sSelectHTTP_condition_type_code = "";
                    String sSelectHTTP_condition_type_code_name = "";

                    ArrayList<HashMap<String, Object>> alTempList_Item_Sub = new ArrayList<HashMap<String, Object>>();
                    if ( sCallType.equals("1") ) {
                        if ( alList_Triggers.size() > 0 ) {
                            if ( !util.null2string(alList_Triggers.get(0).get(Constants.HTTP_item_sub)).equals("") ) {
                                alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Triggers.get(0).get(Constants.HTTP_item_sub);
                                sSelectHTTP_cmdcls_value = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value));
                                sSelectHTTP_cmdcls_value_msg = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value_msg));
                                sSelectHTTP_condition_type_code = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code));
                                sSelectHTTP_condition_type_code_name = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code_name));
                            }
                        }
                    } else if ( sCallType.equals("2") ) {
                        if ( alList_Actions.size() > 0 ) {
                            for ( int iRow = 0; iRow < alList_Actions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iRow).get(Constants.HTTP_item_sub);
                                        sSelectHTTP_cmdcls_value = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value));
                                        sSelectHTTP_cmdcls_value_msg = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value_msg));
                                        sSelectHTTP_condition_type_code = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code));
                                        sSelectHTTP_condition_type_code_name = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code_name));
                                        break;
                                    }
                                }
                            }
                        }
                    } else if ( sCallType.equals("3") ) {
                        if ( alList_Conditions.size() > 0 ) {
                            for ( int iRow = 0; iRow < alList_Conditions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Conditions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Conditions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Conditions.get(iRow).get(Constants.HTTP_item_sub);
                                        sSelectHTTP_cmdcls_value = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value));
                                        sSelectHTTP_cmdcls_value_msg = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value_msg));
                                        sSelectHTTP_condition_type_code = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code));
                                        sSelectHTTP_condition_type_code_name = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code_name));
                                        break;
                                    }
                                }
                            }
                        }
                    } else if ( sCallType.equals("4") ) {
                        if ( alList_Actions.size() > 0 ) {
                            for ( int iRow = 0; iRow < alList_Actions.size(); iRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iRow).get(Constants.HTTP_item_sub);
                                        sSelectHTTP_cmdcls_value = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value));
                                        sSelectHTTP_cmdcls_value_msg = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_cmdcls_value_msg));
                                        sSelectHTTP_condition_type_code = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code));
                                        sSelectHTTP_condition_type_code_name = util.null2string(alTempList_Item_Sub.get(iSelectedPosition).get(Constants.HTTP_condition_type_code_name));
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    alList_Item_Sub1.get(iRow1).put(Constants.HTTP_cmdcls_value, sSelectHTTP_cmdcls_value);
                    alList_Item_Sub1.get(iRow1).put(Constants.HTTP_cmdcls_value_msg, sSelectHTTP_cmdcls_value_msg);
                    alList_Item_Sub1.get(iRow1).put(Constants.HTTP_condition_type_code, sSelectHTTP_condition_type_code);
                    alList_Item_Sub1.get(iRow1).put(Constants.HTTP_condition_type_code_name, sSelectHTTP_condition_type_code_name);
                    iDefaultPostion = iRow1;
                }

                if ( iDefaultPostion != iRow1 ) {
                    if ( sCallType.equals("2") ) {
                        if ( alList_Actions.size() > 0 ) {
                            for ( int iTempRow = 0; iTempRow < alList_Actions.size(); iTempRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iTempRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iTempRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        ArrayList<HashMap<String, Object>> alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iTempRow).get(
                                                Constants.HTTP_item_sub);
                                        for ( int iTempRow1 = 0; iTempRow1 < alTempList_Item_Sub.size(); iTempRow1++ ) {
                                            String sTemp_HTTP_source_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_id));
                                            String sTemp_HTTP_source_sub_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_sub_id));
                                            if ( sTempHTTP_source_id.equals(sTemp_HTTP_source_id) && sHTTP_source_sub_id.equals(sTemp_HTTP_source_sub_id) ) {
                                                hmTemp1.put(Constants.HTTP_DISABLE_YN, "Y");
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    } else if ( sCallType.equals("3") ) {
                        if ( alList_Conditions.size() > 0 ) {
                            for ( int iTempRow = 0; iTempRow < alList_Conditions.size(); iTempRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Conditions.get(iTempRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Conditions.get(iTempRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        ArrayList<HashMap<String, Object>> alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Conditions.get(iTempRow).get(
                                                Constants.HTTP_item_sub);
                                        for ( int iTempRow1 = 0; iTempRow1 < alTempList_Item_Sub.size(); iTempRow1++ ) {
                                            String sTemp_HTTP_source_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_id));
                                            String sTemp_HTTP_source_sub_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_sub_id));
                                            if ( sTempHTTP_source_id.equals(sTemp_HTTP_source_id) && sHTTP_source_sub_id.equals(sTemp_HTTP_source_sub_id) ) {
                                                hmTemp1.put(Constants.HTTP_DISABLE_YN, "Y");
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    } else if ( sCallType.equals("4") ) {
                        if ( alList_Actions.size() > 0 ) {
                            for ( int iTempRow = 0; iTempRow < alList_Actions.size(); iTempRow++ ) {
                                String sHTTP_item_sub_type_code = util.null2string(alList_Actions.get(iTempRow).get(Constants.HTTP_item_sub_type_code));
                                if ( sHTTP_item_sub_type_code.equals("01") ) {
                                    if ( !util.null2string(alList_Actions.get(iTempRow).get(Constants.HTTP_item_sub)).equals("") ) {
                                        ArrayList<HashMap<String, Object>> alTempList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Actions.get(iTempRow).get(
                                                Constants.HTTP_item_sub);
                                        for ( int iTempRow1 = 0; iTempRow1 < alTempList_Item_Sub.size(); iTempRow1++ ) {
                                            String sTemp_HTTP_source_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_id));
                                            String sTemp_HTTP_source_sub_id = util.null2string(alTempList_Item_Sub.get(iTempRow1).get(Constants.HTTP_source_sub_id));
                                            if ( sTempHTTP_source_id.equals(sTemp_HTTP_source_id) && sHTTP_source_sub_id.equals(sTemp_HTTP_source_sub_id) ) {
                                                hmTemp1.put(Constants.HTTP_DISABLE_YN, "Y");
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                if ( iDefaultPostion == iRow1 ) {
                    hmTemp1.put(Constants.HTTP_SELECT_YN, "Y");
                } else {
                    hmTemp1.put(Constants.HTTP_SELECT_YN, "N");
                }
                alTotalList.add(hmTemp1);
            }
        }
        dataAdapter.notifyDataSetChanged();
        int viewHeight = util.getScaleVal(act, 115) * dataAdapter.getItemCount();
        rcvList.getLayoutParams().height = viewHeight;
    }

    @Override public void onListReload() {

        //        loading = true;
        //        bMore = true;
        //        sSearch_Type = "";
        //        sRule_id = "";
        //        if ( setHomeHubStateList() ) {
        //            ComHandler.sendMessageDelayed(ComHandler.obtainMessage(MSG_COM_G_RULES), 10);
        //        }
    }

    @Override public void onLogout() {
        //        mCallback.onLogout();
    }
    @Override public void onCallAction(int iCallType, int iPosition) {

        if ( iCallType == 0 ) {
            //추가하기
            //            Rules_Edit();
        } else if ( iCallType == 1 ) {
            // 멀티센서 선택
            iSelectPosition = iPosition;
            //                                        vSelectView = v;
            String sHTTP_source_sub_name = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_source_sub_name));
            String sHTTP_control_min_value = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_control_min_value));
            String sHTTP_control_max_value = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_control_max_value));
            String sHTTP_control_step = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_control_step));
            String sHTTP_unit = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_unit));
            String sHTTP_cmdcls_value = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_cmdcls_value));
            String sHTTP_condition_type_code = util.null2string(alTotalList.get(iSelectPosition).get(Constants.HTTP_condition_type_code));
            intent = new Intent();
            intent.setClass(act, Rules_Multisensor_Select.class);
            intent.putExtra(Constants.EXTRA_NAME, sHTTP_source_sub_name);
            intent.putExtra(Constants.EXTRA_MULTISENSOR, sHTTP_cmdcls_value);
            intent.putExtra(Constants.EXTRA_CONDITION_TYPE_CODE, sHTTP_condition_type_code);
            intent.putExtra(Constants.EXTRA_MIN, util.str2int(sHTTP_control_min_value));
            intent.putExtra(Constants.EXTRA_MAX, util.str2int(sHTTP_control_max_value));
            intent.putExtra(Constants.EXTRA_STEP, util.str2int(sHTTP_control_step));
            intent.putExtra(Constants.EXTRA_UNIT, sHTTP_unit);
            util.callActivityForResultNoAnim(act, intent, Constants.ACT_RULES_MULTISENSOR_SELECT);
        } else if ( iCallType == 2 ) {
            // 삭제하기
            //            String sHTTP_group_name = util.null2string(alTotalList.get(iPosition).get(Constants.HTTP_group_name));
            //            String sHTTP_device_name = util.null2string(alTotalList.get(iPosition).get(Constants.HTTP_device_name));
            //            String sCOMPANY_DESC = util.getString(act, R.string.layout_things_device_add_07);
            //            iSelectPosition = iPosition;
            //            customDialog.MsgAlert(act, Constants.MSG810, R.string.MSG_TITLE_003, util.getString(act, R.string.layout_delete), util.getString(act, R.string.layout_cancel));
        } else if ( iCallType == 3 ) {
            // 활성화 비활성화
            //            iSelectPosition = iPosition;
            //            String sHTTP_use_yn = util.null2string(alTotalList.get(iPosition).get(Constants.HTTP_use_yn));
            //            if ( sHTTP_use_yn.equals("Y") ) {
            //                util.setShowToast(act, util.getString(act, R.string.MSG808), Toast.LENGTH_SHORT);
            //                ComHandler.sendMessageDelayed(ComHandler.obtainMessage(MSG_COM_P_RULES_HOMEGRP_RULE_ID_STATUS), 10);
            //            } else if ( sHTTP_use_yn.equals("N") ) {
            //                util.setShowToast(act, util.getString(act, R.string.MSG809), Toast.LENGTH_SHORT);
            //                ComHandler.sendMessageDelayed(ComHandler.obtainMessage(MSG_COM_P_RULES_HOMEGRP_RULE_ID_STATUS), 10);
            //            } else if ( sHTTP_use_yn.equals("X") ) {
            //                customDialog.MsgAlert(act, Constants.MSG818, R.string.MSG_TITLE_000, util.getString(act, R.string.MSG_BTN_EDIT), util.getString(act, R.string.MSG_BTN_CANCEL));
            //            }
        }
    }
}
