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

package com.ntels.onecable.view.rules;

import com.ntels.onecable.R;
import com.ntels.onecable.common.Constants;
import com.ntels.onecable.common.util.Util;
import com.ntels.onecable.common.widget.CustomActivity;
import com.ntels.onecable.view.dialog.CustomDialog;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * <pre>
 * 1. ClassName :   RulesTriggersTime
 * 2. FileName  :   RulesTriggersTime.java
 * 3. Package   :   com.ntels.onecable.view.rules
 * 4. Date      :   2016-11-30
 * 5. Author    :   aaron
 * 6. Comment   :   Initialize
 * </pre>
 */
public class RulesTriggersTime extends CustomActivity implements View.OnClickListener,
    CustomDialog.OnMsgAlterToResult {

  private Util mUtil = new Util();
  private Intent intent;
  private Activity mActivity;
  private DecimalFormat decimalFormat = new DecimalFormat("00");

  private CustomDialog customDialog = new CustomDialog();
  private String hour = "";
  private String minute = "";
  private String ampm = "";
  private String dayOfWeek = "";
  private ArrayList<HashMap<String, Object>> triggers = new ArrayList<HashMap<String, Object>>();
  private ArrayList<HashMap<String, Object>> conditions = new ArrayList<HashMap<String, Object>>();
  private HashMap<String, Object> itemSubMap = new HashMap<String, Object>();
  /*private TextView tvUpHour;
  private TextView tvUpMinute;
  private TextView tvUpAmpm;
  private TextView tvAmpm;
  private TextView tvDownHour;
  private TextView tvDownMinute;
  private TextView tvDownAmpm;*/
  private int hourStart = 1;
  private int hourEnd = 12;
  private int minuteStart = 0;
  private int minuteEnd = 59;

  @BindView(R.id.tvAm) TextView mAm;
  @BindView(R.id.tvPm) TextView mPm;
  @BindView(R.id.edtHour) EditText mHour;
  @BindView(R.id.edtMinuet) EditText mMinuet;
  @BindView(R.id.llMon) LinearLayout mMon;
  @BindView(R.id.llTue) LinearLayout mTue;
  @BindView(R.id.llWed) LinearLayout mWed;
  @BindView(R.id.llThu) LinearLayout mThu;
  @BindView(R.id.llFri) LinearLayout mFri;
  @BindView(R.id.llSat) LinearLayout mSat;
  @BindView(R.id.llSun) LinearLayout mSun;

  @SuppressWarnings("unchecked")
  @Override
  public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    mActivity = RulesTriggersTime.this;
    customDialog.setOnMsgAlterToResultEvent(this);

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

    ButterKnife.bind(this);

    if (null != getIntent()) {
      Intent intent = getIntent();
      triggers = (ArrayList<HashMap<String, Object>>)
          intent.getSerializableExtra(Constants.EXTRA_TRIGGERS);
      conditions = (ArrayList<HashMap<String, Object>>)
          intent.getSerializableExtra(Constants.EXTRA_CONDITIONS);
    }

    displayListView();
  }

  /**
   * UI display.
   */
  private void displayListView() {

    /*tvUpHour = (TextView) findViewById(R.id.tvUpHH);
    tvUpMinute = (TextView) findViewById(R.id.tvUpMM);
    tvUpAmpm = (TextView) findViewById(R.id.tvUpAMPM);
    mHour = (EditText) findViewById(R.id.edtHH);
    mMinuet = (EditText) findViewById(R.id.edtMM);
    tvAmpm = (TextView) findViewById(R.id.tvAMPM);
    tvDownHour = (TextView) findViewById(R.id.tvDownHH);
    tvDownMinute = (TextView) findViewById(R.id.tvDownMM);
    tvDownAmpm = (TextView) findViewById(R.id.tvDownAMPM);
    Button btnUpHour = (Button) findViewById(R.id.btnUpHH);
    btnUpHour.setOnClickListener(this);
    tvUpHour.setOnClickListener(this);
    tvDownHour.setOnClickListener(this);
    Button btnDownHour = (Button) findViewById(R.id.btnDownHH);
    btnDownHour.setOnClickListener(this);
    Button btnUpMinute = (Button) findViewById(R.id.btnUpMM);
    btnUpMinute.setOnClickListener(this);
    tvUpMinute.setOnClickListener(this);
    tvDownMinute.setOnClickListener(this);
    Button btnDownMinute = (Button) findViewById(R.id.btnDownMM);
    btnDownMinute.setOnClickListener(this);
    Button btnUpAmpm = (Button) findViewById(R.id.btnUpAMPM);
    btnUpAmpm.setOnClickListener(this);
    tvUpAmpm.setOnClickListener(this);
    tvDownAmpm.setOnClickListener(this);
    Button btnDownAmpm = (Button) findViewById(R.id.btnDownAMPM);
    btnDownAmpm.setOnClickListener(this);*/

    /*mUtil.getView(mActivity, R.id.llMon).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llTue).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llWed).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llThu).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llFri).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llSat).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llSun).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llBtn1).setOnClickListener(this);
    mUtil.getView(mActivity, R.id.llBtn2).setOnClickListener(this);*/
    mMon.setSelected(true);
    mTue.setSelected(true);
    mWed.setSelected(true);
    mThu.setSelected(true);
    mFri.setSelected(true);
    mSat.setSelected(true);
    mSun.setSelected(true);

    getTriggersTime();

    getDayOfWeek();

    setKeyDisp();
    if (hour.equals("")) {
      mHour.setText(mUtil.getTimeHOUR());
    } else {
      mHour.setText(hour);
    }

    if (minute.equals("")) {
      mMinuet.setText(mUtil.getTimeMINUTE());
    } else {
      mMinuet.setText(minute);
    }

    if (ampm.equals("")) {
      if ("PM".equals(mUtil.getTimeAmPm())) {
        mPm.setSelected(true);
        mAm.setSelected(false);
      } else {
        mAm.setSelected(true);
        mPm.setSelected(false);
      }
    }

  }

  /**
   * trigger time 가져오기.
   */
  @SuppressWarnings("unchecked")
  void getTriggersTime() {

    if (triggers.size() > 0) {
      String itemSubTypeCode = mUtil.null2string(triggers.get(0)
          .get(Constants.KEY_ITEM_SUB_TYPE_CODE));
      ArrayList<HashMap<String, Object>> itemSubList;
      if (!mUtil.null2string(triggers.get(0).get(Constants.KEY_ITEM_SUB)).equals("")) {
        itemSubList = (ArrayList<HashMap<String, Object>>) triggers.get(0)
            .get(Constants.KEY_ITEM_SUB);
        if (itemSubTypeCode.equals("05")) {
          itemSubMap = itemSubList.get(0);

          String tempHour = "";
          dayOfWeek = mUtil.null2string(itemSubMap.get(Constants.KEY_DAYOFWEEK));
          tempHour = mUtil.null2string(itemSubMap.get(Constants.KEY_HOUR));
          minute = mUtil.null2string(itemSubMap.get(Constants.KEY_MINUTE));
          String[] saTime = mUtil.UTCtoLocal6(tempHour + minute);
          if (mUtil.str2int(saTime[0]) >= 12) {
            ampm = mUtil.getString(mActivity, R.string.layout_pm);
            mPm.setSelected(true);
            mAm.setSelected(false);
          } else {
            ampm = mUtil.getString(mActivity, R.string.layout_am);
            mAm.setSelected(true);
            mPm.setSelected(false);
          }
          /*ampm = (mUtil.str2int(saTime[0]) >= 12
              ? mUtil.getString(mActivity, R.string.layout_pm) : mUtil.getString(mActivity, R.string.layout_am));*/
          hour = (mUtil.str2int(saTime[0]) >= 12
              ? decimalFormat.format((mUtil.str2int(saTime[0]) - 12)) : saTime[0]);
        }
      }
    }
  }

  /**
   * 요일 가져오기.
   */
  @SuppressWarnings("unchecked")
  void getDayOfWeek() {

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

        String itemSubTypeCode = mUtil.null2string(hmTemp.get(Constants.KEY_ITEM_SUB_TYPE_CODE));
        if (itemSubTypeCode.equals("22")) {
          //요일
          ArrayList<HashMap<String, Object>> itemSubList;
          if (!mUtil.null2string(hmTemp.get(Constants.KEY_ITEM_SUB)).equals("")) {
            itemSubList = (ArrayList<HashMap<String, Object>>) hmTemp.get(Constants.KEY_ITEM_SUB);
            if (itemSubList.size() > 0) {
              HashMap<String, Object> tempItemSubMap;
              tempItemSubMap = itemSubList.get(0);

              String cmdclsValue = mUtil.null2string(tempItemSubMap.get(
                  Constants.KEY_CMDCLS_VALUE));

              dayOfWeek = cmdclsValue;
            }
          }
          mMon.setSelected(false);
          mTue.setSelected(false);
          mWed.setSelected(false);
          mThu.setSelected(false);
          mFri.setSelected(false);
          mSat.setSelected(false);
          mSun.setSelected(false);
          if (!dayOfWeek.equals("")) {
            String[] strArray = dayOfWeek.split("\\,", 100);
            for (String s : strArray) {
              if (s.equals("MON")) {
                mMon.setSelected(true);
              } else if (s.equals("TUE")) {
                mTue.setSelected(true);
              } else if (s.equals("WED")) {
                mWed.setSelected(true);
              } else if (s.equals("THU")) {
                mThu.setSelected(true);
              } else if (s.equals("FRI")) {
                mFri.setSelected(true);
              } else if (s.equals("SAT")) {
                mSat.setSelected(true);
              } else if (s.equals("SUN")) {
                mSun.setSelected(true);
              }
            }
          }
          break;
        }
      }
    }
  }

  /**
   * 요일 셋팅.
   *
   * @return 셋팅할 요일
   */
  private Boolean setsDayOfWeek() {



    String tempDayOfWeek = "";
    if (mMon.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "MON";
    }
    if (mTue.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "TUE";
    }
    if (mWed.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "WED";
    }
    if (mThu.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "THU";
    }
    if (mFri.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "FRI";
    }
    if (mSat.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "SAT";
    }
    if (mSun.isSelected()) {
      if (!tempDayOfWeek.equals("")) {
        tempDayOfWeek = tempDayOfWeek + ",";
      }
      tempDayOfWeek = tempDayOfWeek + "SUN";
    }
    if (tempDayOfWeek.equals("")) {
      customDialog.msgAlert(mActivity, Constants.MSG855);
      return false;
    }

    String[] alItem = mUtil.getStringArrayValues(mActivity, "DAYOFWEEK_ITEM");
    String[] alText = mUtil.getStringArrayValues(mActivity, "DAYOFWEEK_TEXT");
    String tempDayOfWeek1 = "";
    tempDayOfWeek1 = tempDayOfWeek;
    String[] strArray = tempDayOfWeek.split("\\,", 100);
    for (String s : strArray) {
      int idx = mUtil.getArraryFind(alItem, s);
      tempDayOfWeek1 = tempDayOfWeek1.replaceAll(s, alText[idx]);
    }

    HashMap<String, Object> tempItemSubMap = new HashMap<String, Object>();
    String tempSourceId = "";
    String tempSourceSubId = "";
    String tempConditionTypeCode = "09";
    String tempCmdclsValue = tempDayOfWeek;
    String tempCmdclsValueMsg = tempDayOfWeek1;

    tempItemSubMap.put(Constants.KEY_SOURCE_ID, tempSourceId);
    tempItemSubMap.put(Constants.KEY_SOURCE_SUB_ID, tempSourceSubId);
    tempItemSubMap.put(Constants.KEY_CONDITION_TYPE_CODE, tempConditionTypeCode);
    tempItemSubMap.put(Constants.KEY_CMDCLS_VALUE, tempCmdclsValue);
    tempItemSubMap.put(Constants.KEY_CMDCLS_VALUE_MSG, tempCmdclsValueMsg);

    ArrayList<HashMap<String, Object>> tempItemSubList = new ArrayList<>();
    tempItemSubList.add(tempItemSubMap);

    HashMap<String, Object> hmTempCondition = new HashMap<String, Object>();
    hmTempCondition.put(Constants.KEY_ITEM_NAME, "");
    hmTempCondition.put(Constants.KEY_ITEM_SUB_TYPE_CODE, "22");
    hmTempCondition.put(Constants.KEY_ITEM_SUB, tempItemSubList);

    boolean isSet = false;
    if (conditions.size() > 0) {
      for (int row = 0; row < conditions.size(); row++) {
        HashMap<String, Object> hmTemp;
        hmTemp = conditions.get(row);

        String itemSubTypeCode = mUtil.null2string(hmTemp.get(Constants.KEY_ITEM_SUB_TYPE_CODE));
        if (itemSubTypeCode.equals("22")) {
          conditions.set(row, hmTempCondition);
          isSet = true;
          break;
        }
      }

      if (!isSet) {
        conditions.add(hmTempCondition);
      }
    } else {
      conditions.add(hmTempCondition);
    }

    return true;
  }

  /**
   * keyboard display.
   */
  void setKeyDisp() {

    mHour.setImeOptions(EditorInfo.IME_ACTION_DONE); // 키보드 확인 버튼 클릭시
    mHour.setOnEditorActionListener(new TextView.OnEditorActionListener() {
      @Override
      public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {

        if (actionId == EditorInfo.IME_ACTION_DONE) {
          mHour.clearFocus();
          InputMethodManager imm = (InputMethodManager) view.getContext()
              .getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
        return false;
      }
    });
    mHour.setOnFocusChangeListener(new View.OnFocusChangeListener() {
      public void onFocusChange(View view, boolean hasFocus) {

        if (!hasFocus) {
          if (mHour.getText().toString().length() == 1) {
            mHour.setText("0" + mHour.getText());
          }
        }
      }
    });
    mHour.addTextChangedListener(new TextWatcher() {

      @Override
      public void onTextChanged(CharSequence chars, int start, int before, int count) {

      }

      @Override
      public void beforeTextChanged(CharSequence chars, int start, int count, int after) {

      }

      @Override
      public void afterTextChanged(Editable editable) {

        if (mUtil.null2int(editable.toString()) > 12) {
          mHour.setText("12");
        } else if (mUtil.null2string(editable.toString()).equals("")) {
          mHour.setText("12");
        } else if (editable.toString().length() > 1) {
          if (mUtil.null2int(editable.toString()) == 0) {
            mHour.setText("12");
          } else {
            int currentHour = mUtil.null2int(editable.toString());
            if (currentHour <= hourEnd) {
              if (currentHour == hourStart) {
//                tvUpHour.setText(decimalFormat.format(hourEnd));
              } else {
//                tvUpHour.setText(decimalFormat.format(currentHour - 1));
              }
              if (currentHour < hourEnd) {
//                tvDownHour.setText(decimalFormat.format(currentHour + 1));
              } else {
//                tvDownHour.setText(decimalFormat.format(hourStart));
              }
            } else {
              currentHour = hourStart;
//              tvUpHour.setText(decimalFormat.format(hourEnd));
//              tvDownHour.setText(decimalFormat.format(currentHour + 1));
            }
            mHour.selectAll();
          }
        } else {
          if (mUtil.null2int(editable.toString()) > 1) {
            mHour.setText("0" + editable.toString());
          } else if (mUtil.null2int(editable.toString()) > 0) {
            int currentHour = mUtil.null2int(editable.toString());
            if (currentHour <= hourEnd) {
              if (currentHour == hourStart) {
//                tvUpHour.setText(decimalFormat.format(hourEnd));
              } else {
//                tvUpHour.setText(decimalFormat.format(currentHour - 1));
              }
              if (currentHour < hourEnd) {
//                tvDownHour.setText(decimalFormat.format(currentHour + 1));
              } else {
//                tvDownHour.setText(decimalFormat.format(hourStart));
              }
            } else {
              currentHour = hourStart;
//              tvUpHour.setText(decimalFormat.format(hourEnd));
//              tvDownHour.setText(decimalFormat.format(currentHour + 1));
            }
          }
        }
      }
    });
    mMinuet.setImeOptions(EditorInfo.IME_ACTION_DONE); // 키보드 확인 버튼 클릭시
    mMinuet.setOnEditorActionListener(new TextView.OnEditorActionListener() {
      @Override
      public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {

        if (actionId == EditorInfo.IME_ACTION_DONE) {
          mMinuet.clearFocus();
          InputMethodManager imm = (InputMethodManager) view.getContext()
              .getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
        }
        return false;
      }
    });
    mMinuet.setOnFocusChangeListener(new View.OnFocusChangeListener() {
      public void onFocusChange(View view, boolean hasFocus) {

        if (!hasFocus) {
          if (mMinuet.getText().toString().length() == 1) {
            mMinuet.setText("0" + mMinuet.getText());
          }
        }
      }
    });
    mMinuet.addTextChangedListener(new TextWatcher() {

      @Override
      public void onTextChanged(CharSequence chars, int start, int before, int count) {

      }

      @Override
      public void beforeTextChanged(CharSequence chars, int start, int count, int after) {

      }

      @Override
      public void afterTextChanged(Editable editable) {

        if (mUtil.null2int(editable.toString()) > 59) {
          mMinuet.setText("59");
        } else if (mUtil.null2string(editable.toString()).equals("")) {
          mMinuet.setText("00");
        } else if (editable.toString().length() > 1) {
          int currentMinute = mUtil.null2int(editable.toString());
          if (currentMinute > minuteStart) {
//            tvUpMinute.setText(decimalFormat.format(currentMinute - 1));
            if (currentMinute < minuteEnd) {
//              tvDownMinute.setText(decimalFormat.format(currentMinute + 1));
            } else {
//              tvDownMinute.setText(decimalFormat.format(minuteStart));
            }
          } else {
            currentMinute = minuteStart;
//            tvUpMinute.setText(decimalFormat.format(minuteEnd));
//            tvDownMinute.setText(decimalFormat.format(currentMinute + 1));
          }
          mMinuet.selectAll();
        } else {
          if (mUtil.null2int(editable.toString()) > 5) {
            mMinuet.setText("0" + editable.toString());
          } else if (mUtil.null2int(editable.toString()) > 0) {
            int currentMinute = mUtil.null2int(editable.toString());
            if (currentMinute <= minuteEnd) {
              if (currentMinute == hourStart) {
//                tvUpMinute.setText(decimalFormat.format(minuteEnd));
              } else {
//                tvUpMinute.setText(decimalFormat.format(currentMinute - 1));
              }
              if (currentMinute < minuteEnd) {
//                tvDownMinute.setText(decimalFormat.format(currentMinute + 1));
              } else {
//                tvDownMinute.setText(decimalFormat.format(minuteStart));
              }
            } else {
              currentMinute = minuteStart;
//              tvUpMinute.setText(decimalFormat.format(minuteEnd));
//              tvDownMinute.setText(decimalFormat.format(currentMinute + 1));
            }
          }
        }
      }
    });
  }

  @OnClick({R.id.llBtn1, R.id.llBtn2, R.id.tvAm, R.id.tvPm, R.id.llMon, R.id.llTue, R.id.llWed, R.id.llThu, R.id.llFri, R.id.llSat,
          R.id.llSun})
  public void onClick(View view) {

    int currentHour = mUtil.null2int(mHour.getText());
    int currentMinute = mUtil.null2int(mMinuet.getText());
    String ampm = mAm.isSelected() ? getString(R.string.layout_am) : getString(R.string.layout_pm);
//    String ampm = mUtil.null2string(tvAmpm.getText());
    switch (view.getId()) {
      case R.id.llBtn1:
        if (setsDayOfWeek()) {

          String hour = "";
          hour = decimalFormat.format(currentHour + (ampm.equals(
              mUtil.getString(mActivity, R.string.layout_pm)) ? (currentHour == 12 ? 0 : 12) : (currentHour == 12 ? -12 : 0)));
          String minute = "";
          minute = decimalFormat.format(currentMinute);
          String[] saTime = mUtil.LocaltoUTC3(hour + minute);
          String sourceId = "";
          itemSubMap.put(Constants.KEY_SOURCE_ID, sourceId);
          String sourceSubId = "";
          itemSubMap.put(Constants.KEY_SOURCE_SUB_ID, sourceSubId);
          String conditionTypeCode = "";
          itemSubMap.put(Constants.KEY_CONDITION_TYPE_CODE, conditionTypeCode);
          String cmdclsValue = "";
          itemSubMap.put(Constants.KEY_CMDCLS_VALUE, cmdclsValue);
          String dataTypeCode = "";
          itemSubMap.put(Constants.KEY_DATA_TYPE_CODE, dataTypeCode);
          String dayOfWeek = "";
          itemSubMap.put(Constants.KEY_DAYOFWEEK, dayOfWeek);
          String repeatable = "";
          itemSubMap.put(Constants.KEY_REPEATABLE, repeatable);
          itemSubMap.put(Constants.KEY_HOUR, saTime[0]);
          itemSubMap.put(Constants.KEY_MINUTE, saTime[1]);

          ArrayList<HashMap<String, Object>> itemSubList = new ArrayList<>();
          itemSubList.clear();
          itemSubList.add(itemSubMap);

          triggers.clear();

          HashMap<String, Object> hmTriggers = new HashMap<>();
          hmTriggers.put(Constants.KEY_ITEM_SUB, itemSubList);
          hmTriggers.put(Constants.KEY_ITEM_NAME,
              mUtil.getString(mActivity, R.string.layout_rules_triggers_select_02));
          hmTriggers.put(Constants.KEY_ITEM_SUB_TYPE_CODE, "05");

          triggers.add(hmTriggers);

          intent = new Intent();
          intent.putExtra(Constants.EXTRA_TRIGGERS, triggers);
          intent.putExtra(Constants.EXTRA_CONDITIONS, conditions);
          mActivity.setResult(RESULT_OK, intent);
          finish();
        }
        break;
      case R.id.llBtn2:
        onBackPressed();
        break;
      /*case R.id.btnUpHH:
      case R.id.tvUpHH:
        if (currentHour > hourStart) {
          currentHour--;
          mHour.setText(decimalFormat.format(currentHour));
        } else {
          currentHour = hourEnd;
          mHour.setText(decimalFormat.format(currentHour));
        }

        break;*/
      /*case R.id.tvDownHH:
      case R.id.btnDownHH:
        if (currentHour < hourEnd) {
          currentHour++;
          mHour.setText(decimalFormat.format(currentHour));
        } else {
          currentHour = hourStart;
          mHour.setText(decimalFormat.format(currentHour));
        }
        break;*/
      /*case R.id.btnUpMM:
      case R.id.tvUpMM:
        if (currentMinute > minuteStart) {
          currentMinute--;
          mMinuet.setText(decimalFormat.format(currentMinute));
        } else {
          currentMinute = minuteEnd;
          mMinuet.setText(decimalFormat.format(currentMinute));
        }
        break;*/
      /*case R.id.tvDownMM:
      case R.id.btnDownMM:
        if (currentMinute < minuteEnd) {
          currentMinute++;
          mMinuet.setText(decimalFormat.format(currentMinute));
        } else {
          currentMinute = minuteStart;
          mMinuet.setText(decimalFormat.format(currentMinute));
        }
        break;*/
      /*case R.id.btnUpAMPM:
      case R.id.tvUpAMPM:
      case R.id.tvDownAMPM:
      case R.id.btnDownAMPM:
        if (ampm.equals(mUtil.getString(mActivity, R.string.layout_am))) {
          tvUpAmpm.setText(mUtil.getString(mActivity, R.string.layout_am));
          tvAmpm.setText(mUtil.getString(mActivity, R.string.layout_pm));
          tvDownAmpm.setText(mUtil.getString(mActivity, R.string.layout_am));
        } else {
          tvUpAmpm.setText(mUtil.getString(mActivity, R.string.layout_pm));
          tvAmpm.setText(mUtil.getString(mActivity, R.string.layout_am));
          tvDownAmpm.setText(mUtil.getString(mActivity, R.string.layout_pm));
        }
        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 (view.isSelected()) {
          view.setSelected(false);
        } else {
          view.setSelected(true);
        }
        break;
      case R.id.tvAm:
        mAm.setSelected(true);
        mPm.setSelected(false);
        break;
      case R.id.tvPm:
        mPm.setSelected(true);
        mAm.setSelected(false);
        break;
      default:
        break;
    }
  }

  @Override
  public void resultCustomDialogResponse(int msgId, int btnResult) {

    switch (msgId) {

      case Constants.MSG998:
        mUtil.callApp_Start(mActivity, "LOGOUT");
        break;
      case Constants.MSG997:
        mUtil.callApp_Start(mActivity, "HOME_RELOAD");
        break;
      case Constants.MSG805:
        if (btnResult == 1) {
          // mComHandler.sendMessage(mComHandler.obtainMessage(MSG_COM_DOLOGOUT));
        }
        break;
      default:
        break;
    }
  }

  @Override
  public void onBackPressed() {

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