/*
 * 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.Toolbar;
import android.view.LayoutInflater;
import android.view.View;

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.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.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;

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

    /** 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 String                             sCallType         = "";
    private String                             sTime             = "";
    private String                             sHour             = "";
    private String                             sMinute           = "";
    private String                             sAMPM             = "";
    private String                             sRepeatble        = "";
    private String                             sDayOfWeek        = "";
    private String                             sDayOfWeek1       = "";
    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 HashMap<String, Object>            hmItem_Sub        = new HashMap<String, Object>();

    /*통신 관련*/
    private              ArrayList<HashMap<String, Object>> alTotalList                             = new ArrayList<HashMap<String, Object>>();
    private              int                                iType                                   = 0;
    private static final int                                MSG_COM_G_COMMON_WEATHER_LOCATION_CODES = 1;

    private              CustomDialog      customDialog     = new CustomDialog();
//    private static final int               ACT_SPINNER_AREA = 8016;
    private              int               iAreaPosition    = -1;
    private              String            sArea            = "";
    private              String            sArea_Code       = "";
    private              ArrayList<String> alAreaTitle      = new ArrayList<String>();
    private              ArrayList<String> alAreaId         = new ArrayList<String>();

    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

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

        View viewToLoad = LayoutInflater.from(act).inflate(R.layout.rules_triggers_sun, null);
        this.setContentView(viewToLoad);

        this.setContentView(viewToLoad);
        if ( savedInstanceState != null ) {

        } else {
            Intent intent = getIntent();
            //            sCallType = util.null2string(intent.getStringExtra(Constants.EXTRA_CALL_TYPE));

            alList_Triggers = (ArrayList<HashMap<String, Object>>) intent.getSerializableExtra(Constants.EXTRA_TRIGGERS);
            alList_Conditions = (ArrayList<HashMap<String, Object>>) intent.getSerializableExtra(Constants.EXTRA_CONDITIONS);
        }

        displayListView();
    }

    void getTriggers_Sun() {

        if ( alList_Triggers.size() > 0 ) {
            int iRow = 0;
            int iRow1 = 0;
            String sHTTP_item_sub_type_code = util.null2string(alList_Triggers.get(iRow).get(Constants.HTTP_item_sub_type_code));
            ArrayList<HashMap<String, Object>> alList_Item_Sub = new ArrayList<HashMap<String, Object>>();
            if ( !util.null2string(alList_Triggers.get(iRow).get(Constants.HTTP_item_sub)).equals("") ) {
                alList_Item_Sub = (ArrayList<HashMap<String, Object>>) alList_Triggers.get(iRow).get(Constants.HTTP_item_sub);
                if ( sHTTP_item_sub_type_code.equals("32") ) {
                    hmItem_Sub = alList_Item_Sub.get(iRow1);

                    String sHTTP_source_id = util.null2string(hmItem_Sub.get(Constants.HTTP_source_id));
                    String sHTTP_source_name = util.null2string(hmItem_Sub.get(Constants.HTTP_source_name));
                    String sHTTP_source_sub_id = util.null2string(hmItem_Sub.get(Constants.HTTP_source_sub_id));
                    String sHTTP_source_sub_name = util.null2string(hmItem_Sub.get(Constants.HTTP_source_sub_name));

                    Dlog.v("sunriseUtcTime sHTTP_source_sub_id=" + sHTTP_source_sub_id);
                    if ( sHTTP_source_sub_id.equals("sunriseUtcTime") ) {
                        util.getView(act, R.id.btnSun1).setSelected(true);
                        util.getView(act, R.id.btnSun2).setSelected(false);
                    } else if ( sHTTP_source_sub_id.equals("sunsetUtcTime") ) {
                        util.getView(act, R.id.btnSun1).setSelected(false);
                        util.getView(act, R.id.btnSun2).setSelected(true);
                    }
                    sArea_Code = sHTTP_source_id;
                    sArea = sHTTP_source_name;
                    util.getTextView(act, R.id.tvArea).setText(sArea);
                    util.getViewUnderline(act, R.id.tvArea);
                }
            }
        }
    }

    void getDayOfWeek() {

        if ( alList_Conditions.size() > 0 ) {
            for ( int iRow = 0; iRow < alList_Conditions.size(); iRow++ ) {
                HashMap<String, Object> hmTemp = new HashMap<String, Object>();
                hmTemp = alList_Conditions.get(iRow);

                String sHTTP_item_sub_type_code = util.null2string(hmTemp.get(Constants.HTTP_item_sub_type_code));
                if ( sHTTP_item_sub_type_code.equals("22") ) {
                    //요일
                    ArrayList<HashMap<String, Object>> alList_Item_Sub = new ArrayList<HashMap<String, Object>>();
                    if ( !util.null2string(hmTemp.get(Constants.HTTP_item_sub)).equals("") ) {
                        alList_Item_Sub = (ArrayList<HashMap<String, Object>>) hmTemp.get(Constants.HTTP_item_sub);
                        if ( alList_Item_Sub.size() > 0 ) {
                            HashMap<String, Object> hmTempItem_sub = new HashMap<String, Object>();
                            hmTempItem_sub = alList_Item_Sub.get(0);

                            String sHTTP_cmdcls_value = util.null2string(hmTempItem_sub.get(Constants.HTTP_cmdcls_value));
                            String sHTTP_cmdcls_value_msg = util.null2string(hmTempItem_sub.get(Constants.HTTP_cmdcls_value_msg));

                            sDayOfWeek = sHTTP_cmdcls_value;
                            sDayOfWeek1 = sHTTP_cmdcls_value_msg;
                        }
                    }

                    util.getView(act, R.id.llMon).setSelected(false);
                    util.getView(act, R.id.llTue).setSelected(false);
                    util.getView(act, R.id.llWed).setSelected(false);
                    util.getView(act, R.id.llThu).setSelected(false);
                    util.getView(act, R.id.llFri).setSelected(false);
                    util.getView(act, R.id.llSat).setSelected(false);
                    util.getView(act, R.id.llSun).setSelected(false);
                    if ( !sDayOfWeek.equals("") ) {
                        String[] strArray = sDayOfWeek.split("\\,", 100);
                        for ( int iRow1 = 0; iRow1 < strArray.length; iRow1++ ) {
                            if ( strArray[iRow1].equals("MON") ) {
                                util.getView(act, R.id.llMon).setSelected(true);
                            } else if ( strArray[iRow1].equals("TUE") ) {
                                util.getView(act, R.id.llTue).setSelected(true);
                            } else if ( strArray[iRow1].equals("WED") ) {
                                util.getView(act, R.id.llWed).setSelected(true);
                            } else if ( strArray[iRow1].equals("THU") ) {
                                util.getView(act, R.id.llThu).setSelected(true);
                            } else if ( strArray[iRow1].equals("FRI") ) {
                                util.getView(act, R.id.llFri).setSelected(true);
                            } else if ( strArray[iRow1].equals("SAT") ) {
                                util.getView(act, R.id.llSat).setSelected(true);
                            } else if ( strArray[iRow1].equals("SUN") ) {
                                util.getView(act, R.id.llSun).setSelected(true);
                            }
                        }
                    }
                    break;
                }
            }
        }
    }

    private Boolean setsDayOfWeek() {

        Boolean bResult = true;
        String sTempDayOfWeek = "";
        String sTempDayOfWeek1 = "";

        if ( util.getView(act, R.id.llMon).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "MON";
        }
        if ( util.getView(act, R.id.llTue).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "TUE";
        }
        if ( util.getView(act, R.id.llWed).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "WED";
        }
        if ( util.getView(act, R.id.llThu).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "THU";
        }
        if ( util.getView(act, R.id.llFri).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "FRI";
        }
        if ( util.getView(act, R.id.llSat).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "SAT";
        }
        if ( util.getView(act, R.id.llSun).isSelected() ) {
            if ( !sTempDayOfWeek.equals("") ) {
                sTempDayOfWeek = sTempDayOfWeek + ",";
            }
            sTempDayOfWeek = sTempDayOfWeek + "SUN";
        }
        if ( sTempDayOfWeek.equals("") ) {
            customDialog.MsgAlert(act, Constants.MSG855);
            bResult = false;
            return bResult;
        }

        String[] alItem = util.getStringArrayValues(act, "DAYOFWEEK_ITEM");
        String[] alText = util.getStringArrayValues(act, "DAYOFWEEK_TEXT");
        sTempDayOfWeek1 = sTempDayOfWeek;
        String[] strArray = sTempDayOfWeek.split("\\,", 100);
        for ( int iRow1 = 0; iRow1 < strArray.length; iRow1++ ) {
            String sTemp = strArray[iRow1];
            int iIdx = util.getArraryFind(alItem, sTemp);
            sTempDayOfWeek1 = sTempDayOfWeek1.replaceAll(sTemp, alText[iIdx]);
        }

        ArrayList<HashMap<String, Object>> alTempItem_sub = new ArrayList<HashMap<String, Object>>();
        HashMap<String, Object> hmTempItem_sub = new HashMap<String, Object>();
        String sTempSOURCE_ID = "";
        String sTempSOURCE_SUB_ID = "";
        String sTempCONDITION_TYPE_CODE = "09";
        String sTempCMDCLS_VALUE = sTempDayOfWeek;
        String sTempCMDCLS_VALUE_MSG = sTempDayOfWeek1;

        hmTempItem_sub.put(Constants.HTTP_source_id, sTempSOURCE_ID);
        hmTempItem_sub.put(Constants.HTTP_source_sub_id, sTempSOURCE_SUB_ID);
        hmTempItem_sub.put(Constants.HTTP_condition_type_code, sTempCONDITION_TYPE_CODE);
        hmTempItem_sub.put(Constants.HTTP_cmdcls_value, sTempCMDCLS_VALUE);
        hmTempItem_sub.put(Constants.HTTP_cmdcls_value_msg, sTempCMDCLS_VALUE_MSG);
        alTempItem_sub.add(hmTempItem_sub);

        HashMap<String, Object> hmTempCondition = new HashMap<String, Object>();
        //        hmTempCondition.put(Constants.HTTP_pred_rule_id, "");
        //        hmTempCondition.put(Constants.HTTP_pred_item_sequence, "");
        hmTempCondition.put(Constants.HTTP_item_name, "");
        hmTempCondition.put(Constants.HTTP_item_sub_type_code, "22");
        hmTempCondition.put(Constants.HTTP_item_sub, alTempItem_sub);

        boolean bSet = false;
        if ( alList_Conditions.size() > 0 ) {
            for ( int iRow = 0; iRow < alList_Conditions.size(); iRow++ ) {
                HashMap<String, Object> hmTemp = new HashMap<String, Object>();
                hmTemp = alList_Conditions.get(iRow);

                String sHTTP_item_sub_type_code = util.null2string(hmTemp.get(Constants.HTTP_item_sub_type_code));
                if ( sHTTP_item_sub_type_code.equals("22") ) {
                    alList_Conditions.set(iRow, hmTempCondition);
                    bSet = true;
                    break;
                }
            }

            if ( !bSet ) {
                alList_Conditions.add(hmTempCondition);
            }
        } else {
            alList_Conditions.add(hmTempCondition);
        }

        return bResult;
    }


    private void displayListView() {

        util.getTextView(act, R.id.tvArea).setText(util.getString(act, R.string.layout_selected));
        util.getViewUnderline(act, R.id.tvArea);
        util.getView(act, R.id.btnSun1).setSelected(true);
        util.getView(act, R.id.btnSun2).setSelected(false);
        util.getView(act, R.id.tvArea).setOnClickListener(this);
        util.getView(act, R.id.btnSun1).setOnClickListener(this);
        util.getView(act, R.id.btnSun2).setOnClickListener(this);
        util.getView(act, R.id.llMon).setOnClickListener(this);
        util.getView(act, R.id.llTue).setOnClickListener(this);
        util.getView(act, R.id.llWed).setOnClickListener(this);
        util.getView(act, R.id.llThu).setOnClickListener(this);
        util.getView(act, R.id.llFri).setOnClickListener(this);
        util.getView(act, R.id.llSat).setOnClickListener(this);
        util.getView(act, R.id.llSun).setOnClickListener(this);
        util.getView(act, R.id.llBtn1).setOnClickListener(this);
        util.getView(act, R.id.llBtn2).setOnClickListener(this);
        util.getView(act, R.id.llMon).setSelected(true);
        util.getView(act, R.id.llTue).setSelected(true);
        util.getView(act, R.id.llWed).setSelected(true);
        util.getView(act, R.id.llThu).setSelected(true);
        util.getView(act, R.id.llFri).setSelected(true);
        util.getView(act, R.id.llSat).setSelected(true);
        util.getView(act, R.id.llSun).setSelected(true);

        getTriggers_Sun();

        getDayOfWeek();



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

    @Override public void onClick(View v) {

        switch (v.getId()) {
            case R.id.llBtn1:
                if (iAreaPosition==-1) {
                    customDialog.MsgAlert(act, Constants.MSG860);
                    return;
                }
                if ( setsDayOfWeek() ) {
                    ArrayList<HashMap<String, Object>> alList_Item_Sub = new ArrayList<HashMap<String, Object>>();
                    String sSOURCE_ID = "";
                    String sSOURCE_NAME = "";
                    String sSOURCE_SUB_ID = "";
                    String sSOURCE_SUB_NAME = "";
                    String sCONDITION_TYPE_CODE = "";
                    String sCMDCLS_VALUE = "";
                    String sDATA_TYPE_CODE = "";
                    String sDAYOFWEEK = "";
                    String sREPEATABLE = "";
                    String sHOUR = "";
                    String sMINUTE = "";

                    if (iAreaPosition>-1) {
                        sSOURCE_ID = util.null2string(alAreaId.get(iAreaPosition));
                        sSOURCE_NAME = util.null2string(alAreaTitle.get(iAreaPosition));
                    } else {
                        customDialog.MsgAlert(act, Constants.MSG860);
                        return;
                    }

                    if (util.getView(act, R.id.btnSun1).isSelected()){
                        sSOURCE_SUB_ID= "sunriseUtcTime";
                        sSOURCE_SUB_NAME= util.getString(act, R.string.layout_rules_triggers_sun_02);
                    } else {
                        sSOURCE_SUB_ID= "sunsetUtcTime";
                        sSOURCE_SUB_NAME= util.getString(act, R.string.layout_rules_triggers_sun_03);
                    }

                    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_cmdcls_value, sCMDCLS_VALUE);
                    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);
                    alList_Item_Sub.clear();
                    alList_Item_Sub.add(hmItem_Sub);

                    alList_Triggers.clear();

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

                    alList_Triggers.add(hmTriggers);

                    intent = new Intent();
                    intent.putExtra(Constants.EXTRA_TRIGGERS, alList_Triggers);
                    intent.putExtra(Constants.EXTRA_CONDITIONS, alList_Conditions);
                    act.setResult(RESULT_OK, intent);
                    finish();
                }
                break;
            case R.id.llBtn2:
                onBackPressed();
                break;
            case R.id.btnSun1:
                util.getView(act, R.id.btnSun1).setSelected(true);
                util.getView(act, R.id.btnSun2).setSelected(false);
                break;
            case R.id.btnSun2:
                util.getView(act, R.id.btnSun1).setSelected(false);
                util.getView(act, R.id.btnSun2).setSelected(true);
                break;
            case R.id.tvArea:
                intent = new Intent();
                intent.setClass(act, Dialog_Spinner.class);
                intent.putExtra(Constants.EXTRA_SPINNER_LIST1, alAreaTitle);
                intent.putExtra(Constants.EXTRA_SPINNER_TITLE, "기준 지역");
                intent.putExtra(Constants.EXTRA_SPINNER_TYPE, 0);
                intent.putExtra(Constants.EXTRA_SPINNER_POSITION, iAreaPosition);
                util.callActivityForResultNoAnim(act, intent, Constants.ACT_SPINNER);
                break;
            case R.id.llMon:
            case R.id.llTue:
            case R.id.llWed:
            case R.id.llThu:
            case R.id.llFri:
            case R.id.llSat:
            case R.id.llSun:
                if ( v.isSelected() ) {
                    v.setSelected(false);
                } else {
                    v.setSelected(true);
                }
                break;
            default:
                break;
        }
    }

    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_COMMON_WEATHER_LOCATION_CODES:
                    //dialog_show();
                    send_G_common_weather_location_codes();
                    break;

                default:
                    break;
            }
            return true;
        }
    }

    /**
     * <PRE>
     * 1. MethodName: send_G_common_weather_location_codes
     * 2. ClassName :
     * 3. Comment   : [Send][GET]야후날씨 지역코드 목록 조회(야후 날씨에 사용할 지역코드목록을 조회한다.)
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    private void send_G_common_weather_location_codes() {

        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_common_weather_location_codes(result);
                }
            });
            httpSend.G_common_weather_location_codes();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

    /**
     * <PRE>
     * 1. MethodName: result_G_common_weather_location_codes
     * 2. ClassName :
     * 3. Comment   : [Result][GET]야후날씨 지역코드 목록 조회(야후 날씨에 사용할 지역코드목록을 조회한다.)
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    private void result_G_common_weather_location_codes(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);
                        String sCOMMON_CODE = util.null2string(hmTemp.get(Constants.HTTP_common_code));
                        String sCOMMON_CODE_NAME = util.null2string(hmTemp.get(Constants.HTTP_common_code_name));
                        alAreaId.add(sCOMMON_CODE);
                        alAreaTitle.add(sCOMMON_CODE_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);
                        }
                    }
                }
            } 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 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.MSG805:
                if ( iBtnResult == 1 ) {
                    // ComHandler.sendMessage(ComHandler.obtainMessage(MSG_COM_DOLOGOUT));
                }
                break;

            default:
                break;
        }
    }

    @Override protected void onSaveInstanceState(Bundle outState) {

        super.onSaveInstanceState(outState);
    }

    @Override public void onBackPressed() {

        intent = new Intent();
        act.setResult(RESULT_CANCELED, intent);
        finish();
    }

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

        super.onActivityResult(requestCode, resultCode, data);
        if ( resultCode == RESULT_OK ) {
            switch (requestCode) {
                case Constants.ACT_SPINNER:
                    if ( iAreaPosition != data.getIntExtra(Constants.EXTRA_SPINNER_RESULT, 0) ) {
                        iAreaPosition = data.getIntExtra(Constants.EXTRA_SPINNER_RESULT, 0);
                        sArea = util.null2string(alAreaTitle.get(iAreaPosition));
                        util.getTextView(act, R.id.tvArea).setText(sArea);
                        util.getViewUnderline(act, R.id.tvArea);
                    }
                    break;
            }
        } else {
            switch (requestCode) {
                default:
                    break;
            }
        }
    }
}
