@Override
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (isFinishing()) {
      return true;
    }

    if (keyCode == KeyEvent.KEYCODE_MENU) {}

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
      LogFactory.d(TAG, "KEYCODE_BACK has clicked .");

      if (mStructNavView.getViewGroupChildCount() == 2) {
        mStructNavView.removeAllItemView();
        adapter.showChildNodes(rootNodeDept);
      } else {
        Node node = mStructNavView.getLastChildNode();
        if (node != null) {
          adapter.showChildNodes(node);
        } else {
          boolean keepOnline =
              (Boolean)
                  PreferenceManager.get(
                      Globe.SP_FILE, new Object[] {LoginActivity.LOGIN_KEEPONLINE, false});
          if (!keepOnline) {
            DialogFactory.promptExit(mContext).show();
          } else {
            IMOApp.getApp().hasRunInBackground = true;
            NoticeManager.updateRecoverAppNotice(notificationManager);
            Functions.backToDesk(this);
          }
        }
      }
      return true;
    }

    if (keyCode == KeyEvent.KEYCODE_SEARCH) {}

    return super.onKeyDown(keyCode, event);
  }
  @Override
  protected void registerEvents() {
    String isFirstLoading =
        (String) PreferenceManager.get("IMOLoading", new String[] {"isFirstLoading", "no"});
    MainActivityGroup.getActivityGroup().updateTipShow(!isFirstLoading.equals("yes"));

    if (getTcpConnection() == null) {
      resetConnection();
      if (getTcpConnection() != null) {
        IMOApp.getDataEngine().addToObserverList(this);
      }
    } else {
      IMOApp.getDataEngine().addToObserverList(this);
    }

    // //1- 更新自己的状态 login over
    doRequestOwnState();
    // / 2- 发送CrashReport
    sendCrashMSG();

    getOrganizeTree();

    getContactTree();

    mTitleBar.setSystemSetListener(
        new OnTouchListener() {

          @Override
          public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
              return true;
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
              SystemSetActivity.launch(OrganizeActivity.this);
              return true;
            }

            return true;
          }
        });

    mTitleBar.setFaceOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            UserConfigActivity.launch(mContext);
          }
        });

    // ///状态弹窗显示
    mTitleBar.setStateOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            mChangeStatePop.popUp(getWindow().getDecorView());
          }
        });

    mChangeStatePop.setListener(
        new OnStateClickListener() {

          @Override
          public void onClickAction() {
            Globe.canConnect = false;
            requestLogOut(false);
          }
        });

    mChangeStatePop.setReLoginListener(
        new OnStateClickListener() {

          @Override
          public void onClickAction() {
            if (EngineConst.isNetworkValid && EngineConst.isReloginSuccess) {
              return;
            } else if (ConnectionChangeReceiver.pingAddress()) {
              System.out.println("shoudong old connection id = " + EngineConst.IMO_CONNECTION_ID);
              EngineConst.isReloginSuccess = false;
              String oldConnectionID = EngineConst.IMO_CONNECTION_ID;

              EngineConst.IMO_CONNECTION_ID = EngineConst.GenerateRandomString();

              System.out.println(
                  "shoudong new connection id :"
                      + EngineConst.IMO_CONNECTION_ID
                      + ",old connectionID :"
                      + oldConnectionID);

              AppService.getService()
                  .setTcpConnection(
                      (TCPConnection)
                          AppService.getService()
                              .getNIOThreadInstance()
                              .newTCPConnection(
                                  EngineConst.IMO_CONNECTION_ID,
                                  EngineConst.IMO_SERVER_ADDRESS,
                                  true));

              AppService.getService().getNIOThreadInstance().release(oldConnectionID, false);

              ReloginOutPacket out =
                  new ReloginOutPacket(
                      ByteBuffer.wrap(EngineConst.sessionKey),
                      IMOCommand.IMO_GET_RELOGIN,
                      EngineConst.cId,
                      EngineConst.uId);
              AppService.getService()
                  .getNIOThreadInstance()
                  .send(EngineConst.IMO_CONNECTION_ID, out, false);
            }
          }
        });

    mSearchBar.setOnClickEvent();

    mSearchBar.setOnSearchListener(
        new OnSearchListener() {

          @Override
          public void onSearch(View v) {
            LogFactory.d(TAG, "Dynamic key = " + ((EditText) v).getText());

            doSearch(((EditText) v).getText().toString().trim());
          }

          private void doSearch(String key) {
            // 查询的结果UIDList
            update2State(true);
            // 数据库中查询结果
            ArrayList<Integer> deptUserId = IMOApp.imoStorage.search(key);

            if (deptUserId != null) {
              mSearchResultAdapter.setShowData(getSearchResult(deptUserId));
              mSearchRestltListView.setAdapter(mSearchResultAdapter);
            } else {
              mSearchResultAdapter.setEmpty();
            }
          }

          @Override
          public void initState() {
            update2State(false);
          }
        });

    mSearchRestltListView.setOnItemClickListener(
        new OnItemClickListener() {

          @Override
          public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
            if (mSearchResultAdapter.getItem(position).getId() == EngineConst.uId) {
              EmployeeDetailActivity.launch(mContext);

            } else {
              Intent intent = new Intent(mContext, DialogueActivity.class);
              Bundle data = new Bundle();
              Node curNode = mSearchResultAdapter.getItem(position);
              data.putInt("cid", curNode.getCid());
              data.putInt("uid", curNode.getId());
              data.putString("name", curNode.getNodeData().nodeName);
              data.putBoolean("sex", curNode.getNodeData().isBoy);
              startActivity(intent.putExtras(data));
            }
          }
        });
  }