package kr.co.icontrols.ilp300_700.admin.setting;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
import android.widget.RelativeLayout;

import kr.co.icontrols.ilp300_700.MainActivity;
import kr.co.icontrols.ilp300_700.R;
import kr.co.icontrols.ilp300_700.global.Configure;
import kr.co.icontrols.ilp300_700.global.Configure.ConfigValKey;
import kr.co.icontrols.ilp300_700.global.Configure.ConfigValue;
import kr.co.icontrols.ilp300_700.global.Configure.SetValue;
import kr.co.icontrols.ilp300_700.global.DataClasses.POSITION;
import kr.co.icontrols.ilp300_700.global.DataClasses.SubInfoTable;
import kr.co.icontrols.ilp300_700.global.Declare;
import kr.co.icontrols.ilp300_700.global.Enumeration.DATAINPUTSCREEN;
import kr.co.icontrols.ilp300_700.global.Global;
import kr.co.icontrols.ilp300_700.global.ID;
import kr.co.icontrols.wallpadsupport.WpadImageView;
import kr.co.icontrols.wallpadsupport.WpadScreen;
import kr.co.icontrols.wallpadsupport.WpadTextView;

public class AdminSet_Setting_MainSub extends WpadScreen {

    String TAG = "AdminSet_Setting_MainSub";

    boolean bLOG = true;   // true, false
    boolean bLOG_DEBUG = false;   // true, false
    boolean bLOG_INFO = true;   // true, false
    Context mContext;
    WpadImageView Image_Background;
    WpadTextView Text_Title;
    WpadTextView Text_Line_01_Item;
    WpadTextView Text_Line_02_Item;
    WpadTextView Text_Line_03_Item;
    WpadTextView Text_Line_04_Item;
    WpadTextView Text_Line_05_Item;
    WpadTextView Text_Line_06_Item;
    WpadTextView Text_Line_01_Input;
    WpadTextView Text_Line_02_Input;
    WpadTextView Text_Line_03_Input;
    WpadTextView Text_Line_04_Input;
    WpadTextView Text_Line_05_Input;
    WpadTextView Text_Line_06_Input;
    int TextColor_Normal = Color.WHITE;
    int TextColor_Highlight = Color.GREEN;
    int nFontSize_Instruction = 28;
    boolean bFontNonBold = false;
    boolean bFontBold = true;
    String strText_Title = "메인/서브 설정";
    String strText_Line_01_Item = "1] 메인";
    String strText_Line_02_Item = "2] 서브";
    String strText_Line_03_Item = "서브 로비폰 개수";
    String strText_Line_04_Item = "순서";
    String strText_Line_05_Item = "서브 로비폰 ID";
    String strText_Line_06_Item = "메인 로비폰 ID";
    String strText_Line_01_Input = "0";   // 사용안함
    String strText_Line_02_Input = "0";   // 사용안함
    String strText_Line_03_Input = "0";   // 서브로비폰 개수
    String strText_Line_04_Input = "0";   // 서브로비폰 ID 설정 : 순서
    String strText_Line_05_Input = "0";   // 서브로비폰 ID 설정 : 서브로비폰 ID 입력
    String strText_Line_06_Input = "0";   // 메인로비폰 ID 입력
    int nTempSubCnt = 0;   // 화면용 서브개수
    int[] anTempSubIDs;   // 화면용 서브로비폰 정보
    int nTempMainID;   // 화면용 서브로비폰 정보
    boolean bSetReady = false;
    int nPageNo = 0;
    public AdminSet_Setting_MainSub(Context context, RelativeLayout layout) {
        super(context, layout);
        try {
            LOG("------------------ [START - AdminSet_Setting_MainSub] -------------------");

            mContext = context;
            Initialize();

            Image_Background = new WpadImageView(context, 0, Declare.DeviceInfo.getScreenSizeFullW(ConfigValue.DEVICE_MODELTYPE), Declare.DeviceInfo.getScreenSizeFullH(ConfigValue.DEVICE_MODELTYPE), R.drawable.bg_back, 0, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.IMAGES.BACKGROUND);
            ViewRegistration(layout, Image_Background, 0, 0);

            Text_Title = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE);
            ViewRegistration(layout, Text_Title, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE).Y);
            Text_Title.setText(strText_Title);

            Text_Line_01_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item);
            ViewRegistration(layout, Text_Line_01_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item).Y);
            Text_Line_01_Item.setText(strText_Line_01_Item);

            Text_Line_02_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item);
            ViewRegistration(layout, Text_Line_02_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item).Y);
            Text_Line_02_Item.setText(strText_Line_02_Item);

            Text_Line_03_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item);
            ViewRegistration(layout, Text_Line_03_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item).Y);
            Text_Line_03_Item.setText(strText_Line_03_Item);

            Text_Line_04_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item);
            ViewRegistration(layout, Text_Line_04_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item).Y);
            Text_Line_04_Item.setText(strText_Line_04_Item);

            Text_Line_05_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item);
            ViewRegistration(layout, Text_Line_05_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item).Y);
            Text_Line_05_Item.setText(strText_Line_05_Item);

            Text_Line_06_Item = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item);
            ViewRegistration(layout, Text_Line_06_Item, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item).Y);
            Text_Line_06_Item.setText(strText_Line_06_Item);

            Text_Line_01_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input);
            ViewRegistration(layout, Text_Line_01_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input).Y);
            Text_Line_01_Input.setText("( " + strText_Line_01_Input + " )");

            Text_Line_02_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input);
            ViewRegistration(layout, Text_Line_02_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input).Y);
            Text_Line_02_Input.setText("[ " + strText_Line_02_Input + " ]");

            Text_Line_03_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input);
            ViewRegistration(layout, Text_Line_03_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input).Y);
            Text_Line_03_Input.setText("[ " + strText_Line_03_Input + " ]");

            Text_Line_04_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input);
            ViewRegistration(layout, Text_Line_04_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input).Y);
            Text_Line_04_Input.setText("[ " + strText_Line_04_Input + " ]");

            Text_Line_05_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input);
            ViewRegistration(layout, Text_Line_05_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input).Y);
            Text_Line_05_Input.setText("[ " + strText_Line_05_Input + " ]");

            Text_Line_06_Input = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input).W, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input).H, Gravity.CENTER, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input);
            ViewRegistration(layout, Text_Line_06_Input, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input).X, getPosition(ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input).Y);
            Text_Line_06_Input.setText("[ " + strText_Line_06_Input + " ]");

            UpdateScreen();
            if (ConfigValue.eFirstBoot != SetValue.TRUE) {
                ((MainActivity) mContext).setAutoScreenChange(ID.SCREENS.Main, MainActivity.nAdminScreenTimeout);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] AdminSet_Setting_MainSub(...) : " + e);
            e.printStackTrace();
        }
    }

    private void LOG(String log) {
        if (bLOG) Log.v(TAG, log);
    }

    private void LOG_DEBUG(String log) {
        if (bLOG_DEBUG) Log.d(TAG, log);
    }

    private void LOG_INFO(String log) {
        if (bLOG_INFO) Log.i(TAG, log);
    }

    protected void Initialize() {
        try {
            LOG("[Initialize] ===== START =====");
            Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_01;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] Initialize() : " + e);
            e.printStackTrace();
        }
    }

    @Override
    protected void onClose() {
        try {
            LOG("------------------ [onClose - AdminSet_Setting_MainSub] -------------------");
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onClose() : " + e);
            e.printStackTrace();
        }
        super.onClose();
    }

    @Override
    protected void onBrReceive(Intent intent) {
        try {
            LOG("[onBrReceive] Intent : " + intent);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onBrReceive(...) : " + e);
            e.printStackTrace();
        }
        super.onBrReceive(intent);
    }

    @Override
    protected void onKeyDown(int keyCode, KeyEvent event) {
        try {
//            LOG("[onKeyDown] keyCode [" + keyCode + "], event [" + event + "]");
            if (Declare.Button.NUMBER_00 <= keyCode && keyCode <= Declare.Button.NUMBER_09) {
                if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_01) {
                    if (keyCode == Declare.Button.NUMBER_01) {
                        strText_Line_03_Input = "0";
                        Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_02;
                    } else if (keyCode == Declare.Button.NUMBER_02) {
                        strText_Line_06_Input = "0";
                        Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_04;
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_02) {
                    strText_Line_03_Input += keyCode - 7;
                    if (strText_Line_03_Input.length() > 2) {
                        strText_Line_03_Input = strText_Line_03_Input.substring(1);
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                    strText_Line_05_Input += keyCode - 7;
                    if (strText_Line_05_Input.length() > 2) {
                        strText_Line_05_Input = strText_Line_05_Input.substring(1);
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_04) {
                    strText_Line_06_Input += keyCode - 7;
                    if (strText_Line_06_Input.length() > 2) {
                        strText_Line_06_Input = strText_Line_06_Input.substring(1);
                    }
                }
                UpdateScreen();
            } else if (keyCode == Declare.Button.SHARP) {
                if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                    if (checkValidityInputValues()) {
                        if (!changeDetailScreen(nPageNo - 1, true, strText_Line_05_Input)) {
                            MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                        }
                    } else {
                        MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                    }
                    setDetailScreenValues();
                    UpdateScreen();
                }
            } else if (keyCode == Declare.Button.GUARD) {
                // 설정정보를 저장하는 기능을 정의한다.
                if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_02) {
                    nTempSubCnt = Integer.parseInt(strText_Line_03_Input);
                    if (nTempSubCnt == 0) {
                        if (setSubIDs(nTempSubCnt, null)) {
                            if (ConfigValue.eFirstBoot == SetValue.TRUE) {
                                super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SmartAutodoorLink);
                            } else {
                                MainActivity.mSound.PlayMent_lobby(R.raw.setting);
                                super.setChangeScreen(ID.SCREENS.AdminSet_Setting);
                            }
                        } else {
                            MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                            strText_Line_03_Input = "0";
                        }
                    } else {
                        Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_03;
                        initSubIDsDetails();
                        setDetailScreenValues();
                        UpdateScreen();
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                    if (setSubIDs(nTempSubCnt, anTempSubIDs)) {
                        if (ConfigValue.eFirstBoot == SetValue.TRUE) {
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SmartAutodoorLink);
                        } else {
                            MainActivity.mSound.PlayMent_lobby(R.raw.setting);
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting);
                        }
                    } else {
                        MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                        initSubIDsDetails();
                        setDetailScreenValues();
                        UpdateScreen();
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_04) {
                    if (setMainID(strText_Line_06_Input)) {
                        if (ConfigValue.eFirstBoot == SetValue.TRUE) {
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SmartAutodoorLink);
                        } else {
                            MainActivity.mSound.PlayMent_lobby(R.raw.setting);
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting);
                        }
                    } else {
                        strText_Line_06_Input = "0";
                        MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                        UpdateScreen();
                    }
                }
            } else if (keyCode == Declare.Button.CANCEL || keyCode == Declare.Button.TACT_CANCEL) {
                if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_01) {
                    if (ConfigValue.eFirstBoot != SetValue.TRUE) {
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting);
                    } else {
                        Initialize();
                        MainActivity.mSound.PlayMent_lobby(R.raw.retryinput);
                        UpdateScreen();
                    }
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_02) {
                    Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_01;
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                    Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_02;
                } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_04) {
                    Global.DataInputScreen = DATAINPUTSCREEN.DETAIL_01;
                }
                UpdateScreen();
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onKeyDown(...) : " + e);
            e.printStackTrace();
        }
        super.onKeyDown(keyCode, event);
    }

    protected void UpdateVisibility() {
        try {
            LOG("[UpdateVisibility] ===== START =====");
            if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_01) {
                // 메인/버스 설정
                Text_Line_01_Item.setVisibility(View.VISIBLE);
                Text_Line_02_Item.setVisibility(View.VISIBLE);
                Text_Line_03_Item.setVisibility(View.INVISIBLE);
                Text_Line_04_Item.setVisibility(View.INVISIBLE);
                Text_Line_05_Item.setVisibility(View.INVISIBLE);
                Text_Line_06_Item.setVisibility(View.INVISIBLE);

                Text_Line_01_Input.setVisibility(View.INVISIBLE);
                Text_Line_02_Input.setVisibility(View.INVISIBLE);
                Text_Line_03_Input.setVisibility(View.INVISIBLE);
                Text_Line_04_Input.setVisibility(View.INVISIBLE);
                Text_Line_05_Input.setVisibility(View.INVISIBLE);
                Text_Line_06_Input.setVisibility(View.INVISIBLE);
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_02) {
                // 메인선택 : 서브 로비폰 개수 설정
                Text_Line_01_Item.setVisibility(View.INVISIBLE);
                Text_Line_02_Item.setVisibility(View.INVISIBLE);
                Text_Line_03_Item.setVisibility(View.VISIBLE);
                Text_Line_04_Item.setVisibility(View.INVISIBLE);
                Text_Line_05_Item.setVisibility(View.INVISIBLE);
                Text_Line_06_Item.setVisibility(View.INVISIBLE);

                Text_Line_01_Input.setVisibility(View.INVISIBLE);
                Text_Line_02_Input.setVisibility(View.INVISIBLE);
                Text_Line_03_Input.setVisibility(View.VISIBLE);
                Text_Line_04_Input.setVisibility(View.INVISIBLE);
                Text_Line_05_Input.setVisibility(View.INVISIBLE);
                Text_Line_06_Input.setVisibility(View.INVISIBLE);
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                // 메인선택 : 서브로비폰 ID 설정
                Text_Line_01_Item.setVisibility(View.INVISIBLE);
                Text_Line_02_Item.setVisibility(View.INVISIBLE);
                Text_Line_03_Item.setVisibility(View.INVISIBLE);
                Text_Line_04_Item.setVisibility(View.VISIBLE);
                Text_Line_05_Item.setVisibility(View.VISIBLE);
                Text_Line_06_Item.setVisibility(View.INVISIBLE);

                Text_Line_01_Input.setVisibility(View.INVISIBLE);
                Text_Line_02_Input.setVisibility(View.INVISIBLE);
                Text_Line_03_Input.setVisibility(View.INVISIBLE);
                Text_Line_04_Input.setVisibility(View.INVISIBLE);
                Text_Line_05_Input.setVisibility(View.VISIBLE);
                Text_Line_06_Input.setVisibility(View.INVISIBLE);
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_04) {
                // 서브선택 : 메인로비폰 ID 입력
                Text_Line_01_Item.setVisibility(View.INVISIBLE);
                Text_Line_02_Item.setVisibility(View.INVISIBLE);
                Text_Line_03_Item.setVisibility(View.INVISIBLE);
                Text_Line_04_Item.setVisibility(View.INVISIBLE);
                Text_Line_05_Item.setVisibility(View.INVISIBLE);
                Text_Line_06_Item.setVisibility(View.VISIBLE);

                Text_Line_01_Input.setVisibility(View.INVISIBLE);
                Text_Line_02_Input.setVisibility(View.INVISIBLE);
                Text_Line_03_Input.setVisibility(View.INVISIBLE);
                Text_Line_04_Input.setVisibility(View.INVISIBLE);
                Text_Line_05_Input.setVisibility(View.INVISIBLE);
                Text_Line_06_Input.setVisibility(View.VISIBLE);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] UpdateVisibility() : " + e);
            e.printStackTrace();
        }
    }

    protected void UpdateScreen() {
        try {
            LOG("[updateScreen] ===== START =====");
            if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_01) {
                UpdateVisibility();
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_02) {
                UpdateVisibility();
                Text_Line_03_Input.setText("[ " + Integer.parseInt(strText_Line_03_Input) + " ]");

                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_05_Item.setTextColor(TextColor_Normal);
                Text_Line_06_Item.setTextColor(TextColor_Normal);

                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Highlight);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
                Text_Line_05_Input.setTextColor(TextColor_Normal);
                Text_Line_06_Input.setTextColor(TextColor_Normal);
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_03) {
                UpdateVisibility();
                Text_Line_04_Item.setText("순서 ( " + nPageNo + " )");
                Text_Line_05_Input.setText("[ " + Integer.parseInt(strText_Line_05_Input) + " ]");

                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_05_Item.setTextColor(TextColor_Normal);
                Text_Line_06_Item.setTextColor(TextColor_Normal);

                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
                Text_Line_05_Input.setTextColor(TextColor_Highlight);
                Text_Line_06_Input.setTextColor(TextColor_Normal);
            } else if (Global.DataInputScreen == DATAINPUTSCREEN.DETAIL_04) {
                UpdateVisibility();
                Text_Line_06_Input.setText("[ " + Integer.parseInt(strText_Line_06_Input) + " ]");

                Text_Line_01_Item.setTextColor(TextColor_Normal);
                Text_Line_02_Item.setTextColor(TextColor_Normal);
                Text_Line_03_Item.setTextColor(TextColor_Normal);
                Text_Line_04_Item.setTextColor(TextColor_Normal);
                Text_Line_05_Item.setTextColor(TextColor_Normal);
                Text_Line_06_Item.setTextColor(TextColor_Normal);

                Text_Line_01_Input.setTextColor(TextColor_Normal);
                Text_Line_02_Input.setTextColor(TextColor_Normal);
                Text_Line_03_Input.setTextColor(TextColor_Normal);
                Text_Line_04_Input.setTextColor(TextColor_Normal);
                Text_Line_05_Input.setTextColor(TextColor_Normal);
                Text_Line_06_Input.setTextColor(TextColor_Highlight);
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] updateScreen() : " + e);
            e.printStackTrace();
        }
    }

    public POSITION getPosition(int nID) {
//        LOG("[getPosition] ===== START =====");
        POSITION position = new POSITION();
        position.SetPosition(0, 0, 480, 272);
        try {
            switch (nID) {
                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.IMAGES.BACKGROUND:
                    position.SetPosition(0, 0, 480, 272);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.TITLE:
                    position.SetPosition(0, 24, 480, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Item:
                    position.SetPosition(30, 104, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Item:
                    position.SetPosition(30, 154, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Item:
                    position.SetPosition(30, 104, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Item:
                    position.SetPosition(30, 84, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Item:
                    position.SetPosition(30, 134, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Item:
                    position.SetPosition(30, 104, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_01_Input:
                    position.SetPosition(205, 104, 205, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_02_Input:
                    position.SetPosition(205, 154, 205, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_03_Input:
                    position.SetPosition(30, 154, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_04_Input:
                    position.SetPosition(205, 134, 245, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_05_Input:
                    position.SetPosition(30, 184, 420, 40);
                    return position;

                case ID.SCREENS.ADMINSET_SETTING_MAINSUB.ELEMENTS.TEXTS.LINE_06_Input:
                    position.SetPosition(30, 154, 420, 40);
                    return position;

                default:
                    return position;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] getPosition() : " + e);
            e.printStackTrace();
            return position;
        }
    }

    private void initSubIDsDetails() {
        try {
            LOG("[initSubIDsDetails] ===== START =====");
            bSetReady = false;
            nPageNo = 1;
            anTempSubIDs = new int[nTempSubCnt];

            for (int i = 0; i < nTempSubCnt; i++) {
                anTempSubIDs[i] = 0;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] initLineDetail() : " + e);
            e.printStackTrace();
        }
    }

    private void PageUp() {
        try {
            if (nPageNo < nTempSubCnt) nPageNo++;
            else {
                bSetReady = true;
                nPageNo = 1;
            }
        } catch (Exception e) {
            Log.e(TAG, "[Exception] PageUp() : " + e);
            e.printStackTrace();
        }
    }

    private void PageDown() {
        try {
            if (nPageNo > 1) nPageNo--;
            else nPageNo = nTempSubCnt;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] PageDown() : " + e);
            e.printStackTrace();
        }
    }

    private boolean changeDetailScreen(int index, boolean bPageUp, String subids) {
        try {
            LOG("[changeLineInfoInputScreen] index [" + index + "], bPageUp [" + bPageUp + "], subids [" + subids + "]");

            int ids = Integer.parseInt(subids);

            if (ids < 1 || 99 < ids) return false;

            if (!saveTempValues(index, subids)) return false;

            if (bPageUp) PageUp();
            else PageDown();

            return setDetailScreenValues();
        } catch (Exception e) {
            Log.e(TAG, "[Exception] changeLineInfoInputScreen(index, linename, linelow, linehigh)");
            e.printStackTrace();
            return false;
        }
    }

    private boolean saveTempValues(int index, String subids) {
        try {
            LOG("[saveTempValues] index [" + index + "], subids [" + subids + "]");
            anTempSubIDs[index] = Integer.parseInt(subids);
            return true;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] saveTempValues() : " + e);
            e.printStackTrace();
            return false;
        }
    }

    private boolean setDetailScreenValues() {
        try {
            LOG("[setDetailPageValues] ===== START =====");
            int index = nPageNo - 1;
            LOG("[setDetailPageValues] nPageNo [" + nPageNo + "], SubID[" + index + "] = " + anTempSubIDs[index]);
            strText_Line_05_Input = Integer.toString(anTempSubIDs[index]);
            return true;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setDetailPageValues() : " + e);
            e.printStackTrace();
            return false;
        }
    }

    private boolean checkValidityInputValues() {
        try {
            // 기 입력된 라인정보중에 동일한 라인정보 존재유무 확인
            for (int i = 0; i < anTempSubIDs.length; i++) {
                if (anTempSubIDs[i] == Integer.parseInt(strText_Line_05_Input)) {
                    if (nPageNo - 1 != i) {
                        LOG_INFO("[checkValidityInputValues] There is a same linename!! anTempSubIDs[" + i + "] = " + anTempSubIDs[i] + ", strText_Line_05_Input = " + strText_Line_05_Input);
                        return false;
                    }
                }
            }
            return true;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] checkValidityInputValues() : " + e);
            e.printStackTrace();
            return false;
        }
    }

    private boolean setSubIDs(int nCnt, int[] nSubIDs) {
        try {
            String strResult = "ERROR";
            SubInfoTable mSubInfoTable = new SubInfoTable();
            mSubInfoTable.clearTable();
            int nDongIP = Integer.parseInt(ConfigValue.strDevice_Dong) % 100;
            String strIP = "";
            for (int i = 0; i < nCnt; i++) {
                strIP = "10." + nDongIP + ".0." + nSubIDs[i];
                mSubInfoTable.addSubTable(nSubIDs[i], strIP, null);
            }
            strResult = Configure.makeSubIDsString(mSubInfoTable);
            LOG("[setLineInfo] strResult = " + strResult);
            if (!strResult.matches(".*ERROR.*")) {
                ConfigValue.eMainSub = SetValue.Main;
                ConfigValue.strMainLPID = ConfigValue.strDevice_ID;
                ConfigValue.strSubIDs = strResult;
                if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainSub, ConfigValue.eMainSub))
                    return false;
                if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.SubIDs, ConfigValue.strSubIDs))
                    return false;
                if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainLPID, ConfigValue.strMainLPID))
                    return false;
                return Configure.extractSubIDs(ConfigValue.strSubIDs);
            }
            return false;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setSubIDs(nCnt, nSubIDs) : " + e);
            e.printStackTrace();
            return false;
        }
    }

    private boolean setMainID(String strMainID) {
        try {
            int nID = Integer.parseInt(strMainID);
            if (nID < 1 || 99 < nID) {
                LOG_INFO("[setMainID] strMainID is invalid!! strMainID = " + strMainID);
                return false;
            }
            if (ConfigValue.strDevice_ID.equals(strMainID)) {
                LOG_INFO("[setMainID] strMainID is same as this device id!! strMainID = " + strMainID);
                return false;
            }

            ConfigValue.eMainSub = SetValue.Sub;
            ConfigValue.strSubIDs = "NONE";
            ConfigValue.strMainLPID = strMainID;

            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainSub, ConfigValue.eMainSub))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.SubIDs, ConfigValue.strSubIDs))
                return false;
            if (!MainActivity.ConfigDBManager.setData(Declare.DBInfo.TABLE_NAME_CONFIG, ConfigValKey.MainLPID, ConfigValue.strMainLPID))
                return false;

            return Configure.extractSubIDs(ConfigValue.strSubIDs);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] setMainID(mainid) : " + e);
            e.printStackTrace();
            return false;
        }
    }


}