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

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.CountDownTimer;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
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.ConfigValue;
import kr.co.icontrols.ilp300_700.global.DataClasses.POSITION;
import kr.co.icontrols.ilp300_700.global.Declare;
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 AdminSetSettingScreen extends WpadScreen {

    static final String TAG = "AdminSetSettingScreen";

    static WpadImageView Image_Background;
    static WpadTextView Text_Title;
    static WpadTextView Text_Guide;
    static WpadTextView Text_Line_01;
    static WpadTextView Text_Line_02;
    static WpadTextView Text_Line_03;
    static WpadTextView Text_Line_04;

    boolean bLOG = true;   // true, false
    boolean bLOG_DEBUG = false;   // true, false
    boolean bLOG_INFO = false;   // true, false

    int nFontSize_Instruction = 28;
    int nFontSize_Guide = 14;
    boolean bFontNonBold = false;
    boolean bFontBold = true;

    String strText_Title = "";
    String strText_Guide = " * : 이전 페이지 이동\n# : 다음 페이지 이동";
    String strText_Line_01 = "";
    String strText_Line_02 = "";
    String strText_Line_03 = "";
    String strText_Line_04 = "";
    String strTitle_AdminSetting = "설정기능";
    String[] AstrMenu_AdminSetting = {
            "로비폰 기본정보 설정",   // 1
            "경비실기 ID 설정",   // 2
            "라인정보 설정",   // 3
            "메인/서브 설정",   // 4
            "출입 비밀번호 선택",   // 5
            "공용 출입 비밀번호 설정",   // 6
            "관리자 출입 비밀번호 설정",   // 7
            "관리자 비밀번호 설정",   // 8
            "세대 호출범위 설정",   // 9
            "카드 출입범위 설정",   // 10
            "출입카드 발급횟수",   // 11
            "호출음 설정",   // 12
            "음량 조절",   // 13
            "문열림 시간 설정",   // 14
            "화재 문열림 지연시간 설정",   // 15
            "시간 설정",   // 16
            "절전모드 설정",   // 17
            "HeartBeat 전송",   // 18
            "로그정보 전송",   // 19
            "시스템 초기화",   // 20
            "로비폰 역할 설정",   // 21
            "출입통제 연동",   // 22
            "택배 연동",   // 23
            "단지관리 시스템 선택",   // 24
            "카드리더 선택",   // 25
            "Elev. 비연동층 설정",   // 26
            "IP 대역 확장 설정",   // 27
            "세대 분리 설정",   // 28
            "IP 수동 설정",   // 29
            "스마트 자동문 연동",   // 30
            "내부센서 연동 설정", // 31
            "ZigBee 신호 감도 설정", // 32
            "지문인식 연동 설정", // 33
            "BLE 출력 설정", // 34
            "원패스 RSSI 테이블", // 35
            "원패스 환경설정", // 36
            "스마트키 환경설정", // 37
            "타사 원패스 연동" // 38
    };

    int nTotalPage = 0;
    int nCurrentPage = 0;
    int nMenuCnt = 0;
    int nMenuPerPage = 4;

    CountDownTimer KeyTimer;   // 멀티키를 인식하기 위한 타이머
    boolean bMenuNumOver9 = false;
    boolean bMenuNumOver19 = false;
    boolean bMenuNumOver29 = false;
    boolean bMenuNumOver39 = false;

    Context mContext;

    public AdminSetSettingScreen(Context context, RelativeLayout layout) {
        super(context, layout);
        try {
            LOG("------------------ [START - AdminSetSettingScreen] -------------------");

            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.ADMINSETSETTING.ELEMENTS.IMAGES.BACKGROUND);
            ViewRegistration(layout, Image_Background, 0, 0);

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

            Text_Guide = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE).W, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE).H, Gravity.LEFT, Color.parseColor("#7d7d7d"), nFontSize_Guide, bFontNonBold, ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE);
            ViewRegistration(layout, Text_Guide, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE).X, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE).Y);
            Text_Guide.setText(strText_Guide);

            Text_Line_01 = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01).W, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01);
            ViewRegistration(layout, Text_Line_01, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01).X, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01).Y);
            Text_Line_01.setText(strText_Line_01);

            Text_Line_02 = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02).W, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02);
            ViewRegistration(layout, Text_Line_02, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02).X, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02).Y);
            Text_Line_02.setText(strText_Line_02);

            Text_Line_03 = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03).W, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03);
            ViewRegistration(layout, Text_Line_03, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03).X, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03).Y);
            Text_Line_03.setText(strText_Line_03);

            Text_Line_04 = new WpadTextView(context, false, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04).W, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04).H, Gravity.LEFT, Color.WHITE, nFontSize_Instruction, bFontNonBold, ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04);
            ViewRegistration(layout, Text_Line_04, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04).X, getPosition(ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04).Y);
            Text_Line_04.setText(strText_Line_04);

            UpdateScreen();
            ((MainActivity) mContext).setAutoScreenChange(ID.SCREENS.Main, MainActivity.nAdminScreenTimeout);
        } catch (Exception e) {
            Log.e(TAG, "[Exception] AdminSetSettingScreen(Context context, RelativeLayout layout)");
            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 {
            nCurrentPage = Global.nAdminSetPageNumber;

            strText_Title = strTitle_AdminSetting;
            strText_Line_01 = AstrMenu_AdminSetting[0];
            strText_Line_02 = AstrMenu_AdminSetting[1];
            strText_Line_03 = AstrMenu_AdminSetting[2];
            strText_Line_04 = AstrMenu_AdminSetting[3];

            // 페이지를 계산한다.
            nMenuCnt = AstrMenu_AdminSetting.length;
            LOG("[Initialize] nMenuCnt = " + nMenuCnt);
            if ((nMenuCnt % nMenuPerPage) != 0) nTotalPage = (nMenuCnt / nMenuPerPage) + 1;
            else nTotalPage = nMenuCnt / nMenuPerPage;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] Initialize() : " + e);
            e.printStackTrace();
        }
    }

    @Override
    protected void onClose() {
        try {
            LOG("------------------ [onClose - AdminSetSettingScreen] -------------------");
        } 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 (nCurrentPage == 1) {
                    if (keyCode == Declare.Button.NUMBER_01) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_BasicInfo);
                    } else if (keyCode == Declare.Button.NUMBER_02) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_GuardID);
                    } else if (keyCode == Declare.Button.NUMBER_03) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_LineInfo);
                    } else if (keyCode == Declare.Button.NUMBER_04) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_MainSub);
                    }
                } else if (nCurrentPage == 2) {
                    if (keyCode == Declare.Button.NUMBER_05) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SelectAccessPW);
                    } else if (keyCode == Declare.Button.NUMBER_06) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_PublicAccessPW);
                    } else if (keyCode == Declare.Button.NUMBER_07) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_AdminAccessPW);
                    } else if (keyCode == Declare.Button.NUMBER_08) {
                        Global.nAdminSetPageNumber = nCurrentPage;
                        super.setChangeScreen(ID.SCREENS.AdminSet_Setting_AdminPW);
                    }
                } else if (nCurrentPage == 3) {
                    if (bMenuNumOver9) {
                        if (keyCode == Declare.Button.NUMBER_00) {   // 10
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_RFAccessLevel);
                        } else if (keyCode == Declare.Button.NUMBER_01) {   // 11
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_RFAccessKeyIssuedCnt);
                        } else if (keyCode == Declare.Button.NUMBER_02) {   // 12
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_Melody);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_01) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver9 = true;
                        } else if (keyCode == Declare.Button.NUMBER_09) {   // 9
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_CallLevel);
                        }
                    }
                } else if (nCurrentPage == 4) {
                    if (bMenuNumOver9) {
                        if (keyCode == Declare.Button.NUMBER_03) {   // 13
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_Volume);
                        } else if (keyCode == Declare.Button.NUMBER_04) {   // 14
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_DoorOpenDuration);
                        } else if (keyCode == Declare.Button.NUMBER_05) {   // 15
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_FireSensorDoorOpenDelay);
                        } else if (keyCode == Declare.Button.NUMBER_06) {   // 16
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_Calendar);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_01) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver9 = true;
                        }
                    }
                } else if (nCurrentPage == 5) {
                    if (bMenuNumOver9) {
                        if (keyCode == Declare.Button.NUMBER_07) {   // 17
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ECOMode);
                        } else if (keyCode == Declare.Button.NUMBER_08) {   // 18
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SendHeartbeat);
                        } else if (keyCode == Declare.Button.NUMBER_09) {   // 19
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_LogFileSend);
                        }
                    } else if (bMenuNumOver19) {
                        if (keyCode == Declare.Button.NUMBER_00) {   // 20
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ResetSystem);
                        }
                    } else {
                        if (!bMenuNumOver9 && !bMenuNumOver19) {
                            if (keyCode == Declare.Button.NUMBER_01) {
                                if (KeyTimer != null) {
                                    KeyTimer.cancel();
                                    KeyTimer = null;
                                }
                                KeyPressTimer();
                                KeyTimer.start();
                                bMenuNumOver9 = true;
                            } else if (keyCode == Declare.Button.NUMBER_02) {
                                if (KeyTimer != null) {
                                    KeyTimer.cancel();
                                    KeyTimer = null;
                                }
                                KeyPressTimer();
                                KeyTimer.start();
                                bMenuNumOver19 = true;
                            }
                        }
                    }
                } else if (nCurrentPage == 6) {
                    if (bMenuNumOver19) {
                        if (keyCode == Declare.Button.NUMBER_01) {   // 21
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_LobbyRole);
                        } else if (keyCode == Declare.Button.NUMBER_02) {   // 22
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ACULink);
                        } else if (keyCode == Declare.Button.NUMBER_03) {   // 23
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ParcelLink);
                        } else if (keyCode == Declare.Button.NUMBER_04) {   // 24
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_MainServerType);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_02) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver19 = true;
                        }
                    }
                } else if (nCurrentPage == 7) {
                    if (bMenuNumOver19) {
                        if (keyCode == Declare.Button.NUMBER_05) {   // 25
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_DerivedType);
                        } else if (keyCode == Declare.Button.NUMBER_06) {   // 26
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ElevDisableFloor);
                        } else if (keyCode == Declare.Button.NUMBER_07) {   // 27
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_IPExpansion);
                        } else if (keyCode == Declare.Button.NUMBER_08) {   // 28
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_HouseDivision);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_02) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver19 = true;
                        }
                    }
                } else if (nCurrentPage == 8) {
                    if (bMenuNumOver19) {
                        if (keyCode == Declare.Button.NUMBER_09) {   // 29
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SetIPManually);
                        }
                    } else if (bMenuNumOver29) {
                        if (keyCode == Declare.Button.NUMBER_00) {   // 30
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SmartAutodoorLink);
                        } else if (keyCode == Declare.Button.NUMBER_01) {   // 31
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_InsideSensorLink);
                        } else if (keyCode == Declare.Button.NUMBER_02) { // 32
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ZigBeeSensitivity);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_02) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver19 = true;
                        } else if (keyCode == Declare.Button.NUMBER_03) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver29 = true;
                        }
                    }
                } else if (nCurrentPage == 9) {
                    if (bMenuNumOver29) {
                        if (keyCode == Declare.Button.NUMBER_03) {   // 33
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_FingerPrintLink);
                        }
                        else if (keyCode == Declare.Button.NUMBER_04) { // 34
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_BLEStrength);
                        }
                        else if (keyCode == Declare.Button.NUMBER_05) { // 35
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_OnePassRSSIIndex);
                        }
                        else if (keyCode == Declare.Button.NUMBER_06) { // 36
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_OnePassConfigure);
                        }
                    } else {
                        if (keyCode == Declare.Button.NUMBER_03) {
                            if (KeyTimer != null) {
                                KeyTimer.cancel();
                                KeyTimer = null;
                            }
                            KeyPressTimer();
                            KeyTimer.start();
                            bMenuNumOver29 = true;
                        }
                    }
                } else if (nCurrentPage == 10) {
                    if (bMenuNumOver29) {
                        if (keyCode == Declare.Button.NUMBER_07) {   // 37
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_SmartKeyConfigure);
                        }
                        else if (keyCode == Declare.Button.NUMBER_08) { // 38
                            KeyTimer.cancel();
                            Global.nAdminSetPageNumber = nCurrentPage;
                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_ExternalOnePassLink);
                        }
                        else if (keyCode == Declare.Button.NUMBER_09) { // 39
//                            KeyTimer.cancel();
//                            Global.nAdminSetPageNumber = nCurrentPage;
//                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_OnePassRSSIIndex);
                        }
                    } else if (bMenuNumOver39) {
                        if (keyCode == Declare.Button.NUMBER_00) { // 40
//                            KeyTimer.cancel();
//                            Global.nAdminSetPageNumber = nCurrentPage;
//                            super.setChangeScreen(ID.SCREENS.AdminSet_Setting_OnePassConfigure);
                        }
                    } else {
                        if (!bMenuNumOver29 && !bMenuNumOver39) {
                            if (keyCode == Declare.Button.NUMBER_03) {
                                if (KeyTimer != null) {
                                    KeyTimer.cancel();
                                    KeyTimer = null;
                                }
                                KeyPressTimer();
                                KeyTimer.start();
                                bMenuNumOver29 = true;
                            } else if (keyCode == Declare.Button.NUMBER_04) {
                                if (KeyTimer != null) {
                                    KeyTimer.cancel();
                                    KeyTimer = null;
                                }
                                KeyPressTimer();
                                KeyTimer.start();
                                bMenuNumOver39 = true;
                            }
                        }
                    }
                }
            } else if (keyCode == Declare.Button.STAR) {
                PageDown();
            } else if (keyCode == Declare.Button.SHARP) {
                PageUp();
            } else if (keyCode == Declare.Button.CANCEL || keyCode == Declare.Button.TACT_CANCEL) {
                Global.nAdminSetPageNumber = 1;
                super.setChangeScreen(ID.SCREENS.AdminSet_Main);
            }
            UpdateScreen();
        } catch (Exception e) {
            Log.e(TAG, "[Exception] onKeyDown(...) : " + e);
            e.printStackTrace();
        }
        super.onKeyDown(keyCode, event);
    }

    protected void UpdateScreen() {
        LOG("[updateScreen] Start!!");
        try {
            SetPageScreen();
        } catch (Exception e) {
            Log.e(TAG, "[Exception] updateScreen() : " + e);
            e.printStackTrace();
        }
    }

    protected void PageUp() {
        LOG("[PageUp] Start!!");
        try {
            LOG("[PageUp] nCurrentPage = " + nCurrentPage);
            LOG("[PageUp] nTotalPage = " + nTotalPage);
            if (nCurrentPage < nTotalPage) nCurrentPage++;
            else nCurrentPage = 1;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] PageUp() : " + e);
            e.printStackTrace();
        }
    }

    protected void PageDown() {
        LOG("[PageDown] Start!!");
        try {
            LOG("[PageDown] nCurrentPage = " + nCurrentPage);
            LOG("[PageDown] nTotalPage = " + nTotalPage);
            if (nCurrentPage > 1) nCurrentPage--;
            else nCurrentPage = nTotalPage;
        } catch (Exception e) {
            Log.e(TAG, "[Exception] PageDown() : " + e);
            e.printStackTrace();
        }
    }

    protected void SetPageScreen() {
        try {
            int nMenuIndex = (nCurrentPage * nMenuPerPage) - nMenuPerPage;
            LOG("[SetPageScreen] nCurrentPage = " + nCurrentPage);
            LOG("[SetPageScreen] nMenuIndex = " + nMenuIndex);
            LOG("[SetPageScreen] nMenuCnt = " + nMenuCnt);

            if (nMenuIndex < nMenuCnt) {
                strText_Line_01 = nMenuIndex + 1 + "] " + AstrMenu_AdminSetting[nMenuIndex];
                nMenuIndex++;
            } else {
                strText_Line_01 = "";
            }

            if (nMenuIndex < nMenuCnt) {
                strText_Line_02 = nMenuIndex + 1 + "] " + AstrMenu_AdminSetting[nMenuIndex];
                nMenuIndex++;
            } else {
                strText_Line_02 = "";
            }

            if (nMenuIndex < nMenuCnt) {
                strText_Line_03 = nMenuIndex + 1 + "] " + AstrMenu_AdminSetting[nMenuIndex];
                nMenuIndex++;
            } else {
                strText_Line_03 = "";
            }

            if (nMenuIndex < nMenuCnt) {
                strText_Line_04 = nMenuIndex + 1 + "] " + AstrMenu_AdminSetting[nMenuIndex];
                nMenuIndex++;
            } else {
                strText_Line_04 = "";
            }

            Text_Line_01.setText(strText_Line_01);
            Text_Line_02.setText(strText_Line_02);
            Text_Line_03.setText(strText_Line_03);
            Text_Line_04.setText(strText_Line_04);

        } catch (Exception e) {
            Log.e(TAG, "[Exception] SetPageScreen() : " + e);
            e.printStackTrace();
        }
    }

    protected void KeyPressTimer() {
        Log.d(TAG, "[KeyPressTimer] Start!!");
        try {
            KeyTimer = new CountDownTimer(2000, 2000) {
                @Override
                public void onTick(long millisUntilFinished) {
                    Log.d(TAG, "[KeyPressTimer] onTick!!");
                }

                @Override
                public void onFinish() {
                    Log.d(TAG, "[KeyPressTimer] onFinish!!");
                    bMenuNumOver9 = false;
                    bMenuNumOver19 = false;
                    bMenuNumOver29 = false;
                    bMenuNumOver39 = false;
                    KeyTimer.cancel();
                }
            };
        } catch (Exception e) {
            Log.e(TAG, "[Exception] KeyPressTimer() : " + e);
            e.printStackTrace();
        }
    }

    protected POSITION getPosition(int nID) {
//        LOG"[getPosition] Start!!");
        POSITION position = new POSITION();
        position.SetPosition(0, 0, 480, 272);

        try {
            switch (nID) {
                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.IMAGES.BACKGROUND:
                    position.SetPosition(0, 0, 480, 272);
                    return position;

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

                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.GUIDE:
                    position.SetPosition(350, 25, 130, 40);
                    return position;

                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_01:
                    position.SetPosition(30, 73, 450, 40);
                    return position;

                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_02:
                    position.SetPosition(30, 122, 450, 40);
                    return position;

                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_03:
                    position.SetPosition(30, 171, 450, 40);
                    return position;

                case ID.SCREENS.ADMINSETSETTING.ELEMENTS.TEXTS.LINE_04:
                    position.SetPosition(30, 220, 450, 40);
                    return position;

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


}