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

    // If there's no data (because the user didn't select a number and
    // just hit BACK, for example), there's nothing to do.
    if (requestCode != REQUEST_CODE_KICK_MEMBER) {
      if (data == null) {
        return;
      }
    } else if (resultCode != RESULT_OK) {

      return;
    }

    switch (requestCode) {
      case REQUEST_CODE_KICK_MEMBER:
        if (data.hasExtra("isKicked")) {
          Bundle extras = data.getExtras();
          if (extras != null) {
            boolean isKicked = extras.getBoolean("isKicked");

            if (isKicked) {
              VoiceHelper.getInstance().setHandler(mChatRoomHandler);
              VoiceHelper.getInstance().getDevice().queryMembersWithChatroom(mCurrentRoomNum);
            }
          }
        }

        break;
      default:
        break;
    }
  }
 @Override
 public void onClick(View v) {
   switch (v.getId()) {
     case R.id.chatroom_mike:
       try {
         mChatRoomMike.setEnabled(false);
         VoiceHelper.getInstance().getDevice().setMute(isMikeEnable);
         isMikeEnable = VoiceHelper.getInstance().getDevice().getMuteStatus();
         if (isMikeEnable) {
           initBottomStatus(0);
         } else {
           synchronized (mChatRoomHandler) {
             new Thread(mikeAnimRunnable).start();
             mChatRoomHandler.notify();
           }
         }
         mChatRoomMike.setEnabled(true);
       } catch (Exception e) {
         e.printStackTrace();
       }
       break;
     default:
       break;
   }
 }
 public void exitOrDismissChatroom(boolean exit) {
   if (!exit) {
     VoiceHelper.getInstance().getDevice().exitChatroom();
     finish();
   } else {
     showConnectionProgress(getString(R.string.str_dialog_message_default));
     VoiceHelper.getInstance().setHandler(null);
     VoiceHelper.getInstance().getDevice().dismissChatroom(CCPConfig.App_ID, mCurrentRoomNum);
   }
 }
 @Override
 protected void onResume() {
   if (VoiceHelper.getInstance() != null && mChatRoomHandler != null) {
     VoiceHelper.getInstance().setHandler(mChatRoomHandler);
     lockScreen();
   } else {
     finish();
   }
   super.onResume();
 }
  private void initialize(Bundle savedInstanceState) {
    Intent intent = getIntent();
    String roomName = null;
    String creator = null;
    if (intent.hasExtra(ChatRoomName.CHATROOM_NAME)) {
      modeType = MODE_CHATROOM_INITIATED_INTERCOM;
      Bundle extras = intent.getExtras();
      if (extras != null) {
        roomName = extras.getString(ChatRoomName.CHATROOM_NAME);
        if (TextUtils.isEmpty(roomName)) {
          finish();
        } else {
          creator = extras.getString(ChatRoomName.CHATROOM_CREATOR);
          if (CCPConfig.VoIP_ID.equals(creator)) {
            handleTitleDisplay(
                getString(R.string.btn_title_back),
                roomName,
                getString(R.string.app_title_right_button_pull_down));
          } else {
            handleTitleDisplay(getString(R.string.btn_title_back), roomName, null);
          }
        }
      }
    }

    if (intent.hasExtra(Device.CONFNO)) {
      // To invite voice group chat
      modeType = MODE_CHATROOM_INVITATION;
      Bundle extras = intent.getExtras();
      if (extras != null) {
        mCurrentRoomNum = extras.getString(Device.CONFNO);
        if (TextUtils.isEmpty(mCurrentRoomNum)) {
          finish();
        }
      }
    }
    mNoticeTips.setText(R.string.top_tips_connecting_wait);

    // Launched a group chat room request, waiting for SDK to return.
    if (modeType == MODE_CHATROOM_INITIATED_INTERCOM) {
      VoiceHelper.getInstance()
          .getDevice()
          .startChatroom(CCPConfig.App_ID, roomName, 8, null, null);
    } else if (modeType == MODE_CHATROOM_INVITATION) {

      // Initiate a join group chat room request, waiting for SDK to return.
      VoiceHelper.getInstance().getDevice().joinChatroom(mCurrentRoomNum);
    }
  }
 @Override
 public void onPopClick(int index) {
   VoiceHelper.getInstance().setHandler(mChatRoomHandler);
   switch (index) {
     case R.string.pull_invited_phone_member:
       showEditTextDialog(
           DIALOG_SHOW_KEY_INVITE,
           getString(R.string.dialog_title_invite),
           getString(R.string.dialog_title_summary));
       break;
     case R.string.pull_manager_member:
       Intent intent =
           new Intent(ChatRoomActivity.this, ChatroomMemberManagerActivity.class);
       intent.putExtra(Device.CONFNO, mCurrentRoomNum);
       startActivityForResult(intent, REQUEST_CODE_KICK_MEMBER);
       break;
     case R.string.pull_dissolution_room:
       showAlertTipsDialog(
           DIALOG_SHOW_KEY_DISSMISS_CHATROOM,
           getString(R.string.dialog_title_dissmiss_chatroom),
           getString(R.string.dialog_message_dissmiss_chatroom),
           getString(R.string.dailog_button_dissmiss_chatroom),
           getString(R.string.dialog_cancle_btn));
       break;
   }
   xQuickActionBar.dismissBar();
 }
  private void initResourceRefs() {
    mVideoTipsLy = (RelativeLayout) findViewById(R.id.video_call_in_ly);
    mVideoIcon = (ImageView) findViewById(R.id.video_icon);

    mVideoTopTips = (TextView) findViewById(R.id.notice_tips);
    mVideoCallTips = (TextView) findViewById(R.id.video_call_tips);

    mVideoCancle = (Button) findViewById(R.id.video_botton_cancle);
    mVideoBegin = (Button) findViewById(R.id.video_botton_begin);
    mVideoStop = (Button) findViewById(R.id.video_stop);
    mVideoStop.setEnabled(false);
    mVideoCancle.setOnClickListener(this);
    mVideoBegin.setOnClickListener(this);
    mVideoStop.setOnClickListener(this);

    mVideoView = (SurfaceView) findViewById(R.id.video_view);
    mVideoView.getHolder().setFixedSize(240, 320);
    mLoaclVideoView = (RelativeLayout) findViewById(R.id.localvideo_view);
    mVideoLayout = (FrameLayout) findViewById(R.id.Video_layout);
    mCameraSwitch = (ImageButton) findViewById(R.id.camera_switch);
    mCameraSwitch.setOnClickListener(this);

    mCallStatus = (TextView) findViewById(R.id.call_status);
    mCallStatus.setVisibility(View.GONE);
    // mVideoView.getHolder().setFixedSize(width, height);
    VoiceHelper.getInstance().getDevice().setVideoView(mVideoView, null);

    // Create a RelativeLayout container that will hold a SurfaceView,
    // and set it as the content of our activity.
    SurfaceView localView = ViERenderer.CreateLocalRenderer(this);
    mLoaclVideoView.addView(localView);
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // add by able for soft keyboard show

    setContentView(R.layout.layout_chatroom_activity);

    initResourceRefs();

    if (VoiceHelper.getInstance().getDevice() == null) {
      CCPUtil.registDialog(this);
      // finish();
    } else {
      VoiceHelper.getInstance().setHandler(mChatRoomHandler);
      initialize(savedInstanceState);
    }
    registerReceiver(new String[] {VoiceHelper.INTENT_CHAT_ROOM_DISMISS});
    isMikeEnable = VoiceHelper.getInstance().getDevice().getMuteStatus();
    new Thread(mikeAnimRunnable).start();
  }
  @Override
  public void onClick(View v) {
    switch (v.getId()) {
      case R.id.video_botton_begin:
        break;

      case R.id.video_stop:
      case R.id.video_botton_cancle:
        handleTitleAction(TITLE_LEFT_ACTION);
        break;

      case R.id.camera_switch:
        mCameraSwitch.setEnabled(false);
        // check for availability of multiple cameras
        if (cameraInfos.length == 1) {
          AlertDialog.Builder builder = new AlertDialog.Builder(this);
          builder
              .setMessage(this.getString(R.string.camera_alert))
              .setNeutralButton(R.string.dialog_alert_close, null);
          AlertDialog alert = builder.create();
          alert.show();
          return;
        }

        // OK, we have multiple cameras.
        // Release this camera -> cameraCurrentlyLocked
        if (cameraInfos != null) {
          defaultCameraId = (defaultCameraId + 1) % cameraInfos.length;
          /*for (int i = 0; i < cameraInfos.length; i++) {
          if(defaultCameraId != cameraInfos[i].index){
          	defaultCameraId = cameraInfos[i].index;
          	break;
          }
            }*/
        }
        /* if(defaultCameraId == android.hardware.Camera.CameraInfo.CAMERA_FACING_FRONT) {
        	Toast.makeText(VideoActivity.this, R.string.camera_switch_front, Toast.LENGTH_SHORT).show();
        } else {
        	Toast.makeText(VideoActivity.this,  R.string.camera_switch_back, Toast.LENGTH_SHORT).show();

        }*/
        VoiceHelper.getInstance()
            .getDevice()
            .selectCamera(defaultCameraId, 0, 15, Rotate.Rotate_Auto);
        mCameraSwitch.setEnabled(true);
        break;
      default:
        break;
    }
  }
  @Override
  protected void onDestroy() {
    super.onDestroy();
    if (VoiceHelper.getInstance().getDevice() != null) {
      // getDevice().exitChatroom();
      VoiceHelper.getInstance().getDevice().enableLoudsSpeaker(false);
    }
    if (isMikeEnable && VoiceHelper.getInstance().getDevice() != null) {
      VoiceHelper.getInstance().getDevice().setMute(isMikeEnable);
    }

    if (mChatRoomHandler != null) {
      mChatRoomHandler = null;
    }

    if (mCRoomMembers != null) {
      mCRoomMembers.clear();
      mCRoomMembers = null;
    }

    isMikeEnable = false;
    isJion = false;
    mCurrentRoomNum = null;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_video_activity);

    handleTitleDisplay(
        getString(R.string.btn_title_back), getString(R.string.app_title_video), null);
    VoiceHelper.getInstance().setHandler(mHandler);
    initResourceRefs();
    initialize();

    cameraInfos = VoiceHelper.getInstance().getDevice().getCameraInfo();

    // Find the ID of the default camera
    if (cameraInfos != null && cameraInfos.length != 0) {
      defaultCameraId = cameraInfos[cameraInfos.length - 1].index;
    }
    VoiceHelper.getInstance().getDevice().selectCamera(defaultCameraId, 0, 15, Rotate.Rotate_Auto);
    mCurrentCallId =
        VoiceHelper.getInstance().getDevice().makeCall(Device.CallType.VIDEO, mVoipAccount);

    registerReceiver(new String[] {SettingsActivity.INTENT_P2P_ENABLED});
  }
  @Override
  protected void handleEditDialogOkEvent(int requestKey, String editText, boolean checked) {
    super.handleEditDialogOkEvent(requestKey, editText, checked);

    if (DIALOG_SHOW_KEY_INVITE == requestKey) {
      String mPhoneNumber = editText;
      if (mPhoneNumber != null && !TextUtils.isEmpty(mPhoneNumber)) {
        // invite this phone call ...
        VoiceHelper.getInstance()
            .getDevice()
            .inviteMembersJoinChatroom(
                new String[] {mPhoneNumber}, mCurrentRoomNum, CCPConfig.App_ID);
        mNoticeTips.setText(
            getString(R.string.str_invite_join_room, CCPConfig.VoIP_ID, mPhoneNumber));
      }
    }
  }
  @Override
  protected void handleTitleAction(int direction) {
    if (direction == TITLE_LEFT_ACTION) {
      // Hang up the video call...
      Log4Util.d(
          VoiceHelper.DEMO_TAG,
          "[VideoActivity] onClick: Voip talk hand up, CurrentCallId " + mCurrentCallId);
      isSelfReject = true;
      try {
        if (mCurrentCallId != null) {
          VoiceHelper.getInstance().getDevice().releaseCall(mCurrentCallId);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      finish();
    } else {

      super.handleTitleAction(direction);
    }
  }
        @SuppressWarnings("unchecked")
        @Override
        public void handleMessage(Message msg) {
          super.handleMessage(msg);
          Bundle b = null;
          int reason = 0;
          ChatroomMsg crmsg = null;
          ArrayList<ChatroomMember> members = null;
          if (msg.obj instanceof Bundle) {
            b = (Bundle) msg.obj;
            reason = b.getInt(Device.REASON);
            if (b.getString(Device.CONFNO) != null) mCurrentRoomNum = b.getString(Device.CONFNO);

            if (b.getSerializable(Device.CHATROOM_MSG) != null)
              crmsg = (ChatroomMsg) b.getSerializable(Device.CHATROOM_MSG);

            if (b.getSerializable(Device.CHATROOM_MEMBERS) != null)
              members = (ArrayList<ChatroomMember>) b.getSerializable(Device.CHATROOM_MEMBERS);
          }

          switch (msg.what) {
            case VoiceHelper.WHAT_ON_CHATROOM:
              if (reason == 0) {
                synchronized (mChatRoomHandler) {
                  this.notifyAll();
                }
                // join chatroom success ..
                VoiceHelper.getInstance().getDevice().enableLoudsSpeaker(true);
                VoiceHelper.getInstance().getDevice().queryMembersWithChatroom(mCurrentRoomNum);
                mNoticeTips.setText(
                    CCPConfig.VoIP_ID + getString(R.string.str_join_chatroom_success));

                isJion = true;
                new Thread(CenterAnimRunnable).start();

                if (modeType == ChatRoomActivity.MODE_CHATROOM_INITIATED_INTERCOM) {
                  Chatroom chatRoomInfo = new Chatroom();
                  chatRoomInfo.setCreator(CCPConfig.VoIP_ID);
                  chatRoomInfo.setJoined("1");
                  chatRoomInfo.setRoomNo(mCurrentRoomNum);
                  chatRoomInfo.setRoomName(getActivityTitle());
                  chatRoomInfo.setSquare("8");
                  chatRoomInfo.setValidate("0");
                  Intent intent = new Intent(VoiceHelper.INTENT_CHAT_ROOM_RECIVE);
                  intent.putExtra("ChatRoomInfo", chatRoomInfo);
                  sendBroadcast(intent);
                }
              } else {
                //  failed ..
                isJion = false;
                Log4Util.d(
                    VoiceHelper.DEMO_TAG,
                    "[InterPhoneRoomActivity] handleMessage: Sorry ,invite member inter phone failed ...");
                VoiceHelper.getInstance().getDevice().exitChatroom();
                VoiceApplication.getInstance()
                    .showToast(getString(R.string.str_join_chatroom_failed, reason));
                finish();
              }
              break;
            case VoiceHelper.WHAT_ON_CHATROOM_INVITE:
              if (reason == 0) {
                // invite chatroom success ..
                Toast.makeText(
                        ChatRoomActivity.this,
                        R.string.toast_invite_join_room_success,
                        Toast.LENGTH_SHORT)
                    .show();
              } else {
                //  failed ..
                Toast.makeText(
                        ChatRoomActivity.this,
                        getString(R.string.toast_invite_join_room_failed, reason),
                        Toast.LENGTH_SHORT)
                    .show();
              }

              Message obtainMessage =
                  mChatRoomHandler.obtainMessage(VoiceHelper.WHAT_ON_CHATROOMING);
              mChatRoomHandler.sendMessageDelayed(obtainMessage, 2000);

              break;
            case VoiceHelper.WHAT_ON_CHATROOM_MEMBERS:
              if (members != null) {
                if (mCRoomMembers == null) {
                  mCRoomMembers = new ArrayList<ChatroomMember>();
                }
                mCRoomMembers.clear();
                for (ChatroomMember i : members) {
                  if (i.getNumber().equals(CCPConfig.VoIP_ID)) {
                    mCRoomMembers.add(0, i);
                  } else {
                    mCRoomMembers.add(i);
                  }
                }
                mPersonCount.setText(members.size() + "");
                initChatRoomListView(mCRoomMembers);
              }
              break;
            case VoiceHelper.WHAT_ON_CHATROOM_SIP_MESSAGE:
              try {
                if (crmsg != null) {
                  if (crmsg instanceof ChatroomJoinMsg) {
                    ChatroomJoinMsg crj = (ChatroomJoinMsg) crmsg;
                    if (mCRoomMembers != null) {
                      StringBuilder builder = new StringBuilder();
                      String[] whos = crj.getWhos();
                      for (int i = 0; i < whos.length; i++) {
                        builder.append(whos[i]).append(",");

                        //
                        boolean isHas = false;
                        for (ChatroomMember cm : mCRoomMembers) {
                          if (cm.getNumber().equals(whos[i])) {
                            isHas = true;
                            break;
                          }
                        }
                        if (!isHas) {
                          mCRoomMembers.add(new ChatroomMember(whos[i], "0"));
                        }
                      }

                      String joinV = builder.toString();
                      if (joinV != null && joinV.length() > 0) {
                        joinV = joinV.substring(0, joinV.length() - 1);
                      }
                      mNoticeTips.setText(getString(R.string.str_chatroom_join, joinV));
                      initChatRoomListView(mCRoomMembers);
                    }
                  } else if (crmsg instanceof ChatroomExitMsg) {
                    ChatroomExitMsg cre = (ChatroomExitMsg) crmsg;
                    if (mCRoomMembers != null) {
                      StringBuilder builder = new StringBuilder();
                      ArrayList<ChatroomMember> mExitMember = new ArrayList<ChatroomMember>();
                      String[] whos = cre.getWhos();
                      for (int i = 0; i < whos.length; i++) {
                        builder.append(whos[i]).append(",");
                        for (ChatroomMember eMember : mCRoomMembers) {
                          if (eMember.getNumber().equals(whos[i])) {
                            mExitMember.add(eMember);
                            break;
                          }
                        }
                      }

                      mCRoomMembers.removeAll(mExitMember);
                      initChatRoomListView(mCRoomMembers);
                      String joinV = builder.toString();
                      if (joinV != null && joinV.length() > 0) {
                        joinV = joinV.substring(0, joinV.length() - 1);
                      }
                      mNoticeTips.setText(getString(R.string.str_chatroom_exit, joinV));
                    }
                  } else if (crmsg instanceof ChatroomDismissMsg) {
                    ChatroomDismissMsg dismissMsg = (ChatroomDismissMsg) crmsg;
                    if (dismissMsg.getRoomNo().equals(mCurrentRoomNum)) {
                      showAlertTipsDialog(
                          DIALOG_SHOW_KEY_DISSMISS_CHATROOM,
                          getString(R.string.dialog_title_be_dissmiss_chatroom),
                          getString(R.string.dialog_message_be_dissmiss_chatroom),
                          getString(R.string.dialog_btn),
                          null);
                    }
                  } else if (crmsg instanceof ChatroomRemoveMemberMsg) {
                    ChatroomRemoveMemberMsg crRemoveMemberMsg = (ChatroomRemoveMemberMsg) crmsg;
                    if (CCPConfig.VoIP_ID.equals(crRemoveMemberMsg.getWho())
                        && mCurrentRoomNum.equals(crRemoveMemberMsg.getRoomNo())) {
                      // if sel..
                      showAlertTipsDialog(
                          DIALOG_SHOW_KEY_REMOVE_CHATROOM,
                          getString(R.string.dialog_title_be_kick_chatroom),
                          getString(R.string.dialog_message_be_kick_chatroom),
                          getString(R.string.dialog_btn),
                          null);
                    } else {
                      mNoticeTips.setText(
                          getString(R.string.str_chatroom_kick, crRemoveMemberMsg.getWho()));
                      VoiceHelper.getInstance()
                          .getDevice()
                          .queryMembersWithChatroom(mCurrentRoomNum);
                    }
                  }
                }
              } catch (Exception e) {
                e.printStackTrace();
              }
              break;

            case VoiceHelper.WHAT_ON_MIKE_ANIM:
              int abs = randomNum(6);
              initBottomStatus(abs);
              break;

            case VoiceHelper.WHAT_ON_CNETER_ANIM:
              initCenterStatus(15);
              break;
            case VoiceHelper.WHAT_ON_CHATROOMING:
              mNoticeTips.setText(R.string.top_tips_chatroom_ing);
              break;
            default:
              break;
          }
        }
        @Override
        public void handleMessage(Message msg) {
          super.handleMessage(msg);
          String callid = null;
          Reason reason;
          Bundle b = null;
          // 获取通话ID
          if (msg.obj instanceof String) {
            callid = (String) msg.obj;
          } else if (msg.obj instanceof Bundle) {
            b = (Bundle) msg.obj;
            callid = b.getString(Device.CALLID);
          }
          switch (msg.what) {
            case VoiceHelper.WHAT_ON_CALL_ALERTING:
              // 连接到对端用户,播放铃音
              Log4Util.d(VoiceHelper.DEMO_TAG, "[VideoActivity] handleMessage: voip alerting!!");
              if (callid != null && mCurrentCallId.equals(callid)) { // 等待对方接受邀请...
                mVideoCallTips.setText(getString(R.string.str_tips_wait_invited));
              }
              break;
            case VoiceHelper.WHAT_ON_CALL_PROCEEDING:
              // 连接到服务器
              Log4Util.d(
                  VoiceHelper.DEMO_TAG, "[VideoActivity] handleMessage: voip on call proceeding!!");
              if (callid != null && mCurrentCallId.equals(callid)) {
                mVideoCallTips.setText(getString(R.string.voip_call_connect));
              }
              break;
            case VoiceHelper.WHAT_ON_CALL_ANSWERED:
              // 对端应答
              Log4Util.d(
                  VoiceHelper.DEMO_TAG, "[VideoActivity] handleMessage: voip on call answered!!");
              if (callid != null && mCurrentCallId.equals(callid) && !isConnect) {
                initResVideoSuccess();
                if (mHandler != null) {
                  //
                  // mHandler.sendMessage(mHandler.obtainMessage(WHAT_ON_CODE_CALL_STATUS));
                }
              }
              break;

            case VoiceHelper.WHAT_ON_CALL_RELEASED:
              // 远端挂断,本地挂断在onClick中处理
              Log4Util.d(
                  VoiceHelper.DEMO_TAG, "[VideoActivity] handleMessage: voip on call released!!");
              if (callid != null && mCurrentCallId.equals(callid) && !isSelfReject) {
                finishCalling();
              }
              break;
            case VoiceHelper.WHAT_ON_CALL_MAKECALL_FAILED:
              // 发起通话失败
              Log4Util.d(
                  VoiceHelper.DEMO_TAG,
                  "[VideoActivity] handleMessage: voip on call makecall failed!!");
              if (b != null && b.get(Device.REASON) != null) {
                reason = (Reason) b.get(Device.REASON);
                if (callid != null && mCurrentCallId.equals(callid) && !isSelfReject) {
                  finishCalling(reason);
                }
              }
              break;
            case WHAT_ON_CODE_CALL_STATUS:
              CallStatisticsInfo callStatistics =
                  VoiceHelper.getInstance().getDevice().getCallStatistics(Device.CallType.VIDEO);
              if (callStatistics != null) {
                int fractionLost = callStatistics.getFractionLost();
                int rttMs = callStatistics.getRttMs();
                mCallStatus.setText(getString(R.string.str_call_status, fractionLost, rttMs));
              }
              if (isConnect && mHandler != null) {
                Message callMessage = mHandler.obtainMessage(WHAT_ON_CODE_CALL_STATUS);
                mHandler.sendMessageDelayed(callMessage, 4000);
              }
              break;
            default:
              break;
          }
        }