private void showContactInfo() { Intent intent; if (MUCManager.getInstance().hasRoom(account, user)) { intent = ContactViewer.createIntent(getActivity(), account, user); } else { intent = ContactEditor.createIntent(getActivity(), account, user); } startActivity(intent); }
private void createShortcut(AbstractContact abstractContact) { Intent intent = new Intent(); intent.putExtra( Intent.EXTRA_SHORTCUT_INTENT, ChatViewer.createShortCutIntent( this, abstractContact.getAccount(), abstractContact.getUser())); intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, abstractContact.getName()); Bitmap bitmap; if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) { bitmap = AvatarManager.getInstance().getRoomBitmap(abstractContact.getUser()); } else { bitmap = AvatarManager.getInstance().getUserBitmap(abstractContact.getUser()); } intent.putExtra( Intent.EXTRA_SHORTCUT_ICON, AvatarManager.getInstance().createShortcutBitmap(bitmap)); setResult(RESULT_OK, intent); }
@Override public void onContactClick(AbstractContact abstractContact) { if (action == null) { startActivity( ChatViewer.createSpecificChatIntent( this, abstractContact.getAccount(), abstractContact.getUser())); return; } switch (action) { case ACTION_ROOM_INVITE: { action = null; Intent intent = getIntent(); String account = getRoomInviteAccount(intent); String user = getRoomInviteUser(intent); if (account != null && user != null) { try { MUCManager.getInstance().invite(account, user, abstractContact.getUser()); } catch (NetworkException e) { Application.getInstance().onError(e); } } finish(); break; } case Intent.ACTION_SEND: action = null; startActivity( ChatViewer.createSendIntent( this, abstractContact.getAccount(), abstractContact.getUser(), sendText)); finish(); break; case Intent.ACTION_CREATE_SHORTCUT: { createShortcut(abstractContact); finish(); break; } default: startActivity( ChatViewer.createSpecificChatIntent( this, abstractContact.getAccount(), abstractContact.getUser())); break; } }
@Override public void onMessageClick(View caller, int position) { int itemViewType = chatMessageAdapter.getItemViewType(position); if (itemViewType == ChatMessageAdapter.VIEW_TYPE_INCOMING_MESSAGE || itemViewType == ChatMessageAdapter.VIEW_TYPE_OUTGOING_MESSAGE) { clickedMessageItem = chatMessageAdapter.getMessageItem(position); PopupMenu popup = new PopupMenu(getActivity(), caller); popup.inflate(R.menu.chat_context_menu); popup.setOnMenuItemClickListener(this); final Menu menu = popup.getMenu(); if (clickedMessageItem.isError()) { menu.findItem(R.id.action_message_repeat).setVisible(true); } if (clickedMessageItem.isUploadFileMessage()) { menu.findItem(R.id.action_message_copy).setVisible(false); menu.findItem(R.id.action_message_quote).setVisible(false); menu.findItem(R.id.action_message_remove).setVisible(false); } final File file = clickedMessageItem.getFile(); if (file != null && file.exists()) { menu.findItem(R.id.action_message_open_file).setVisible(true); menu.findItem(R.id.action_message_save_file).setVisible(true); } if (clickedMessageItem.isIncoming() && MUCManager.getInstance().hasRoom(account, user)) { menu.findItem(R.id.action_message_open_muc_private_chat).setVisible(true); } popup.show(); } }
private void leaveConference(String account, String user) { MUCManager.getInstance().leaveRoom(account, user); closeChat(account, user); }
@Override public boolean onMenuItemClick(MenuItem item) { switch (item.getItemId()) { /* security menu */ case R.id.action_start_encryption: startEncryption(account, user); return true; case R.id.action_restart_encryption: restartEncryption(account, user); return true; case R.id.action_stop_encryption: stopEncryption(account, user); return true; case R.id.action_verify_with_fingerprint: startActivity(FingerprintViewer.createIntent(getActivity(), account, user)); return true; case R.id.action_verify_with_question: startActivity(QuestionViewer.createIntent(getActivity(), account, user, true, false, null)); return true; case R.id.action_verify_with_shared_secret: startActivity( QuestionViewer.createIntent(getActivity(), account, user, false, false, null)); return true; /* regular chat options menu */ case R.id.action_view_contact: showContactInfo(); return true; case R.id.action_chat_settings: startActivity(ChatContactSettings.createIntent(getActivity(), account, user)); return true; case R.id.action_show_history: showHistory(account, user); return true; case R.id.action_authorization_settings: startActivity(ConferenceAdd.createIntent(getActivity(), account, user)); return true; case R.id.action_close_chat: closeChat(account, user); return true; case R.id.action_clear_history: clearHistory(account, user); return true; case R.id.action_export_chat: onExportChatClick(); return true; case R.id.action_call_attention: callAttention(); return true; case R.id.action_block_contact: BlockContactDialog.newInstance(account, user) .show(getFragmentManager(), BlockContactDialog.class.getName()); return true; /* conference specific options menu */ case R.id.action_join_conference: MUCManager.getInstance().joinRoom(account, user, true); return true; case R.id.action_invite_to_chat: startActivity(ContactList.createRoomInviteIntent(getActivity(), account, user)); return true; case R.id.action_leave_conference: leaveConference(account, user); return true; case R.id.action_list_of_occupants: startActivity(OccupantList.createIntent(getActivity(), account, user)); return true; /* message popup menu */ case R.id.action_message_repeat: if (clickedMessageItem.isUploadFileMessage()) { uploadFile(clickedMessageItem.getFile().getPath()); } else { sendMessage(clickedMessageItem.getText()); } return true; case R.id.action_message_copy: ((ClipboardManager) getActivity().getSystemService(Context.CLIPBOARD_SERVICE)) .setPrimaryClip( ClipData.newPlainText( clickedMessageItem.getSpannable(), clickedMessageItem.getSpannable())); return true; case R.id.action_message_quote: setInputText("> " + clickedMessageItem.getText() + "\n"); return true; case R.id.action_message_remove: MessageManager.getInstance().removeMessage(clickedMessageItem); updateChat(); return true; case R.id.action_message_open_file: FileManager.openFile(getActivity(), clickedMessageItem.getFile()); return true; case R.id.action_message_save_file: OnSaveFileToDownloadsClick(); return true; case R.id.action_message_open_muc_private_chat: String occupantFullJid = user + "/" + clickedMessageItem.getResource(); MessageManager.getInstance().openChat(account, occupantFullJid); startActivity(ChatViewer.createSpecificChatIntent(getActivity(), account, occupantFullJid)); return true; default: return false; } }