use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.
the class ChatViewerFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
View view = inflater.inflate(R.layout.chat_viewer_fragment, container, false);
contactTitleView = view.findViewById(R.id.contact_title);
abstractContact = RosterManager.getInstance().getBestContact(account, user);
contactTitleView.findViewById(R.id.avatar).setOnClickListener(this);
toolbar = (Toolbar) view.findViewById(R.id.toolbar_default);
toolbar.inflateMenu(R.menu.chat);
toolbar.setOnMenuItemClickListener(this);
toolbar.setNavigationIcon(R.drawable.ic_arrow_left_white_24dp);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
NavUtils.navigateUpFromSameTask(getActivity());
}
});
setHasOptionsMenu(true);
sendButton = (ImageButton) view.findViewById(R.id.button_send_message);
sendButton.setColorFilter(ColorManager.getInstance().getAccountPainter().getGreyMain());
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
securityButton = (ImageButton) view.findViewById(R.id.button_security);
if (abstractChat instanceof RegularChat) {
securityButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showSecurityMenu();
}
});
} else {
securityButton.setVisibility(View.GONE);
}
chatMessageAdapter = new ChatMessageAdapter(getActivity(), account, user, this, this);
recyclerView = (RecyclerView) view.findViewById(R.id.chat_messages_recycler_view);
recyclerView.setAdapter(chatMessageAdapter);
layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setStackFromEnd(true);
recyclerView.setLayoutManager(layoutManager);
// to avoid strange bug on some 4.x androids
view.findViewById(R.id.input_layout).setBackgroundColor(ColorManager.getInstance().getChatInputBackgroundColor());
inputView = (EditText) view.findViewById(R.id.chat_input);
view.findViewById(R.id.button_send_message).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sendMessage();
}
});
inputView.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View view, int keyCode, KeyEvent event) {
if (SettingsManager.chatsSendByEnter() && event.getAction() == KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
sendMessage();
return true;
}
return false;
}
});
inputView.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (!skipOnTextChanges && stopTypingTimer != null) {
stopTypingTimer.cancel();
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void afterTextChanged(Editable text) {
setUpInputViewButtons();
if (skipOnTextChanges) {
return;
}
ChatStateManager.getInstance().onComposing(account, user, text);
stopTypingTimer = new Timer();
stopTypingTimer.schedule(new TimerTask() {
@Override
public void run() {
Application.getInstance().runOnUiThread(new Runnable() {
@Override
public void run() {
ChatStateManager.getInstance().onPaused(account, user);
}
});
}
}, STOP_TYPING_DELAY);
}
});
final ImageButton emojiButton = (ImageButton) view.findViewById(R.id.button_emoticon);
final View rootView = view.findViewById(R.id.root_view);
// Give the topmost view of your activity layout hierarchy. This will be used to measure soft keyboard height
final EmojiconsPopup popup = new EmojiconsPopup(rootView, getActivity());
//Will automatically set size according to the soft keyboard size
popup.setSizeForSoftKeyboard();
//If the emoji popup is dismissed, change emojiButton to smiley icon
popup.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_mood_black_24dp);
}
});
//If the text keyboard closes, also dismiss the emoji popup
popup.setOnSoftKeyboardOpenCloseListener(new EmojiconsPopup.OnSoftKeyboardOpenCloseListener() {
@Override
public void onKeyboardOpen(int keyBoardHeight) {
}
@Override
public void onKeyboardClose() {
if (popup.isShowing())
popup.dismiss();
}
});
//On emoji clicked, add it to edittext
popup.setOnEmojiconClickedListener(new EmojiconGridView.OnEmojiconClickedListener() {
@Override
public void onEmojiconClicked(Emojicon emojicon) {
if (inputView == null || emojicon == null) {
return;
}
int start = inputView.getSelectionStart();
int end = inputView.getSelectionEnd();
if (start < 0) {
inputView.append(emojicon.getEmoji());
} else {
inputView.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
}
}
});
//On backspace clicked, emulate the KEYCODE_DEL key event
popup.setOnEmojiconBackspaceClickedListener(new EmojiconsPopup.OnEmojiconBackspaceClickedListener() {
@Override
public void onEmojiconBackspaceClicked(View v) {
KeyEvent event = new KeyEvent(0, 0, 0, KeyEvent.KEYCODE_DEL, 0, 0, 0, 0, KeyEvent.KEYCODE_ENDCALL);
inputView.dispatchKeyEvent(event);
}
});
// To toggle between text keyboard and emoji keyboard keyboard(Popup)
emojiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//If popup is not showing => emoji keyboard is not visible, we need to show it
if (!popup.isShowing()) {
//If keyboard is visible, simply show the emoji popup
if (popup.isKeyBoardOpen()) {
popup.showAtBottom();
changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
} else //else, open the text keyboard first and immediately after that show the emoji popup
{
inputView.setFocusableInTouchMode(true);
inputView.requestFocus();
popup.showAtBottomPending();
final InputMethodManager inputMethodManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
inputMethodManager.showSoftInput(inputView, InputMethodManager.SHOW_IMPLICIT);
changeEmojiKeyboardIcon(emojiButton, R.drawable.ic_keyboard_black_24dp);
}
} else //If popup is showing, simply dismiss it to show the undelying text keyboard
{
popup.dismiss();
}
}
});
attachButton = (ImageButton) view.findViewById(R.id.button_attach);
attachButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onAttachButtonPressed();
}
});
return view;
}
use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.
the class AttentionManager method sendAttention.
public void sendAttention(String account, String user) throws NetworkException {
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(account, user);
if (!(chat instanceof RegularChat)) {
throw new NetworkException(R.string.ENTRY_IS_NOT_FOUND);
}
String to = chat.getTo();
if (Jid.getResource(to) == null || "".equals(Jid.getResource(to))) {
final Presence presence = RosterManager.getInstance().getPresence(account, user);
if (presence == null) {
to = null;
} else {
to = presence.getFrom();
}
}
if (to == null) {
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
}
ClientInfo clientInfo = CapabilitiesManager.getInstance().getClientInfo(account, to);
if (clientInfo == null)
throw new NetworkException(R.string.ENTRY_IS_NOT_AVAILABLE);
if (!clientInfo.getFeatures().contains(Attention.NAMESPACE))
throw new NetworkException(R.string.ATTENTION_IS_NOT_SUPPORTED);
Message message = new Message();
message.setTo(to);
message.setType(Message.Type.headline);
message.addExtension(new Attention());
ConnectionManager.getInstance().sendStanza(account, message);
chat.newAction(null, null, ChatAction.attention_called);
}
use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.
the class OTRManager method sessionStatusChanged.
@Override
public void sessionStatusChanged(SessionID sessionID) {
removeSMRequest(sessionID.getAccountID(), sessionID.getUserID());
removeSMProgress(sessionID.getAccountID(), sessionID.getUserID());
Session session = sessions.get(sessionID.getAccountID(), sessionID.getUserID());
SessionStatus sStatus = session.getSessionStatus();
LogManager.i(this, "session status changed " + sessionID.getUserID() + " status: " + sStatus);
if (sStatus == SessionStatus.ENCRYPTED) {
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
PublicKey remotePublicKey = session.getRemotePublicKey();
String value;
try {
OtrCryptoEngine otrCryptoEngine = new OtrCryptoEngineImpl();
value = otrCryptoEngine.getFingerprint(remotePublicKey);
} catch (OtrCryptoException e) {
LogManager.exception(this, e);
value = null;
}
if (value != null) {
actives.put(sessionID.getAccountID(), sessionID.getUserID(), value);
if (fingerprints.get(sessionID.getAccountID(), sessionID.getUserID(), value) == null) {
fingerprints.put(sessionID.getAccountID(), sessionID.getUserID(), value, false);
requestToWrite(sessionID.getAccountID(), sessionID.getUserID(), value, false);
}
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, isVerified(sessionID.getAccountID(), sessionID.getUserID()) ? ChatAction.otr_verified : ChatAction.otr_encryption);
AbstractChat chat = getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.sendMessages();
}
} else if (sStatus == SessionStatus.PLAINTEXT) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.remove(sessionID.getAccountID(), sessionID.getUserID());
try {
session.endSession();
} catch (OtrException e) {
LogManager.exception(this, e);
}
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_plain);
} else if (sStatus == SessionStatus.FINISHED) {
actives.remove(sessionID.getAccountID(), sessionID.getUserID());
sessions.remove(sessionID.getAccountID(), sessionID.getUserID());
finished.put(sessionID.getAccountID(), sessionID.getUserID(), true);
newAction(sessionID.getAccountID(), sessionID.getUserID(), null, ChatAction.otr_finish);
// if session was finished then clear OTR-resource for this chat
RegularChat chat = (RegularChat) getChat(sessionID.getAccountID(), sessionID.getUserID());
if (chat != null) {
chat.setOTRresource(null);
}
} else {
throw new IllegalStateException();
}
onContactChanged(sessionID);
}
use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.
the class ChatActivity method handleOtrIntent.
private void handleOtrIntent(Intent intent) {
String account = intent.getStringExtra(KEY_ACCOUNT);
String user = intent.getStringExtra(KEY_USER);
String question = intent.getStringExtra(KEY_QUESTION);
if (account != null && user != null) {
try {
AccountJid accountJid = AccountJid.from(account);
UserJid userJid = UserJid.from(user);
AbstractChat chat = MessageManager.getInstance().getOrCreateChat(accountJid, userJid);
if (chat != null && chat instanceof RegularChat) {
if (intent.getBooleanExtra(EXTRA_OTR_PROGRESS, false)) {
((RegularChat) chat).setIntent(QuestionActivity.createCancelIntent(Application.getInstance(), accountJid, userJid));
} else {
((RegularChat) chat).setIntent(QuestionActivity.createIntent(Application.getInstance(), accountJid, userJid, question != null, true, question));
}
}
} catch (UserJid.UserJidCreateException | XmppStringprepException e) {
e.printStackTrace();
}
}
getIntent().removeExtra(EXTRA_OTR_REQUEST);
getIntent().removeExtra(EXTRA_OTR_PROGRESS);
}
use of com.xabber.android.data.message.RegularChat in project xabber-android by redsolution.
the class ChatActivity method setUpOptionsMenu.
private void setUpOptionsMenu(Menu menu) {
AbstractChat abstractChat = MessageManager.getInstance().getChat(account, user);
if (abstractChat != null) {
menu.clear();
MenuInflater inflater = getMenuInflater();
if (selectedPagePosition == PAGE_POSITION_RECENT_CHATS) {
inflater.inflate(R.menu.menu_chat_recent_list, menu);
setUpRecentChatsMenu(menu, abstractChat);
return;
} else if (CrowdfundingChat.USER.equals(user.getBareJid().toString())) {
menu.clear();
return;
}
if (selectedPagePosition == PAGE_POSITION_CHAT_INFO) {
inflater.inflate(R.menu.toolbar_contact, menu);
setUpContactInfoMenu(menu, abstractChat);
if (abstractChat instanceof RoomChat)
setUpMUCInfoMenu(menu, abstractChat);
return;
}
if (abstractChat instanceof RoomChat) {
inflater.inflate(R.menu.menu_chat_muc, menu);
setUpMUCMenu(menu, abstractChat);
return;
}
if (abstractChat instanceof RegularChat) {
inflater.inflate(R.menu.menu_chat_regular, menu);
setUpRegularChatMenu(menu, abstractChat);
return;
}
}
}
Aggregations