@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 protected void handleDialogCancelEvent(int requestKey) { super.handleDialogCancelEvent(requestKey); if (requestKey == DIALOG_REQUEST_KEY_EXIT_CHATROOM) { exitOrDismissChatroom(false); } }
@Override protected void onResume() { if (VoiceHelper.getInstance() != null && mChatRoomHandler != null) { VoiceHelper.getInstance().setHandler(mChatRoomHandler); lockScreen(); } else { finish(); } super.onResume(); }
@Override protected void onReceiveBroadcast(Intent intent) { super.onReceiveBroadcast(intent); closeConnectionProgress(); if (intent.getAction().equals(VoiceHelper.INTENT_CHAT_ROOM_DISMISS)) { if (intent.hasExtra("roomNo")) { String roomNo = intent.getStringExtra("roomNo"); if (!TextUtils.isEmpty(roomNo) && roomNo.equals(mCurrentRoomNum)) { finish(); } } } }
@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 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 protected void handleDialogOkEvent(int requestKey) { super.handleDialogOkEvent(requestKey); if (DIALOG_SHOW_KEY_DISSMISS_CHATROOM == requestKey || DIALOG_REQUEST_KEY_EXIT_CHATROOM == requestKey) { if (getTitleRightButton().getVisibility() == View.VISIBLE) { // getDevice().dismissChatroom(CCPConfig.App_ID, mCurrentRoomNum); exitOrDismissChatroom(true); } else { // Here is the receipt dissolution news, not so directly off the Page Creator finish(); Intent intent = new Intent(VoiceHelper.INTENT_CHAT_ROOM_DISMISS); intent.putExtra("roomNo", mCurrentRoomNum); sendBroadcast(intent); } } else if (DIALOG_SHOW_KEY_REMOVE_CHATROOM == requestKey) { // Here is the receipt dissolution news, not so directly off the Page Creator finish(); } }
@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; }
@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 onBackPressed() { super.onBackPressed(); isJion = false; }
@Override protected void onPause() { super.onPause(); releaseLockScreen(); }