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

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

import android.app.Activity;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
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.db.SQLManager;
import com.ntels.kneet.v3.common.c_interface.Main_Interface;
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.CommonProgressDialog;
import com.ntels.kneet.v3.view.dialog.CustomDialog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ScheduledFuture;

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

    /*툴바 관련*/
    private Toolbar toolbar;

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

    /*공통*/
    private Activity             act;
    private AppConfig            appConfig;
    private Main_Interface       mCallback;
    private Intent               intent;
    private CommonProgressDialog mDialog;
    private ScheduledFuture      scheduledFuture;
    private Util         util              = new Util();
    private CustomDialog customDialog      = new CustomDialog();
    private String       sCallType         = "";
    private SQLManager   sqlManager        = new SQLManager();
    private boolean      bReloadFinishFlag = false;
    private String       sDEVICE_NAME      = "";
    private String       sCOMPANY_NAME     = "";
    private String       sCOMPANY_DESC     = "";
    private String       sHTTP_command_id  = "";
    private Boolean      bEnd              = false;
    private Boolean      bCancel           = false;
    private Boolean      bPollingSend      = false;
    private Boolean      bPollingPause     = false;
    private Boolean      bPollingCancel    = false;
    private Boolean      bActStop          = false;
    private int          iMaxTime          = 60;
    private int          iTotal            = 0;

    @Override public void onStop() {

        super.onStop();
        Dlog.v("onStop()");
    }

    @Override public void onDestroy() {

        super.onDestroy();
        Dlog.v("onDestroy()");
    }

    @Override public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

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

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

        setDisp();
    }

    private void setDisp() {

        util.getView(act, R.id.llBtn1).setOnClickListener(this);
        util.getView(act, R.id.llPageRoot).setVisibility(View.VISIBLE);

    }

    @Override public void onConfigurationChanged(Configuration newConfig) {

        super.onConfigurationChanged(newConfig);
    }

    @Override public void onClick(View v) {

        switch (v.getId()) {
            case R.id.llBtn1:
                onBackPressed();
                break;
            default:
                break;
        }
    }
    @Override public void resultCustomDialogResponse(int iMsgID, int iBtnResult) {

        switch (iMsgID) {
//            case Constants.MSG998:
//                intent = new Intent();
//                intent.putExtra(Constants.EXTRA_LOGOUT_FLAG, true);
//                act.setResult(RESULT_CANCELED, intent);
//                finish();
//                break;
//            case Constants.MSG807:
//                if ( iBtnResult == 1 ) {
//                    //                    ComHandler.sendMessageDelayed(ComHandler.obtainMessage(iType), 10);
//                }
//                break;
            default:
                break;
        }
    }
    /**
     * <PRE>
     * 1. MethodName: onBackPressed
     * 2. ClassName :
     * 3. Comment   : 뒤로가기 버튼
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    @Override public void onBackPressed() {

        intent = new Intent();
        intent.putExtra(Constants.EXTRA_RELOAD_FLAG, true);
        act.setResult(RESULT_OK, intent);
        finish();
        return;
    }

    /**
     * <PRE>
     * 1. MethodName: onResume
     * 2. ClassName :
     * 3. Comment   : onResume
     * 4. Developer : 최진오
     * 5. Created   : 2015. 10.
     * </PRE>
     */
    @Override public void onResume() {

        super.onResume();

        Dlog.v("onResume()");
        //        bPollingPause = false;
        //        bActStop = false;
    }

}

