Created
November 26, 2012 13:22
-
-
Save soulfly/4148169 to your computer and use it in GitHub Desktop.
BlackBerry 5,6,7 Chat sample: Send message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Method sends and gets messages | |
public void run() { | |
try { | |
if (chat_manager.currentConversation.isMulti) { | |
vman.add(new SeparatorField()); | |
GroupChat chat = | |
(GroupChat)Datas.multichat.get(chat_manager.currentConversation.name); | |
vman.add(new LabelField("Room Members:")); | |
if (chat != null) { | |
for (int j = 0; j < chat.jids.size(); j++) { | |
String temp = (String)chat.jids.elementAt(j); | |
if | |
(temp.equals(chat_manager.currentConversation.name)) { | |
continue; | |
} else { | |
temp = chat_manager.getNickByJid(temp); | |
if (temp.indexOf('@') != -1) { | |
participants_man.add(new | |
MessageLabelField(Jid.getNickUser(temp.substring(0, temp.indexOf('@'))), 0x696969)); | |
} else { | |
participants_man.add(new | |
MessageLabelField(Jid.getNickUser(temp), 0x696969)); | |
} | |
} | |
} | |
} | |
vman.add(participants_man); | |
vman.add(new SeparatorField()); | |
inv = new ButtonField("Invite a contact"); | |
inv.setChangeListener(me); | |
vman.add(inv); | |
} | |
Vector msgs = chat_manager.currentConversation.messages; | |
Message msg; | |
if (msgs != null && printMessages == true) { | |
if (msgs.size() > 0) { | |
int maxText = msgs.size(); //all texts | |
int lin = 0; //links count | |
for (int i = 0; i < maxText; i++) { | |
msg = (Message)msgs.elementAt(i); | |
int j, | |
p = -1; | |
String m; | |
if (chat_manager.currentConversation.isMulti) { | |
m = msg.getTextNick(); | |
} else { | |
m = msg.getText(); | |
} | |
String name = m.substring(0, m.indexOf(">")); | |
if (name.length() > 0) { | |
int color = CHAT_COLOR_CONTACT; | |
if (name.equals(Datas.jid.getUsername()) == | |
true) { | |
color = CHAT_COLOR_MY; | |
name = "Me:"; | |
} else { | |
System.out.println(name); | |
int firstLine = name.indexOf("-"); | |
if (firstLine != -1) { | |
int secLine = name.indexOf('-', | |
firstLine + 1); | |
if (secLine != -1) { | |
name = | |
name.substring(secLine + 1) + ":"; | |
} | |
} | |
if (name.length() == 0) { | |
name = m.substring(0, | |
m.indexOf(">")); | |
} | |
} | |
ContactLabelField txtName = new | |
ContactLabelField(name, msg.getStamp(), color, font); | |
messages_man.add(txtName); | |
m = m.substring(m.indexOf(">") + 1, | |
m.length()); | |
String next = Util.processSmilesForDevice(m); | |
p = m.indexOf(SYM); | |
if (p != -1) { | |
FlowFieldManager fm = new | |
FlowFieldManager(); | |
int xOff = 0; | |
while (p >= 0) { | |
String part = next.substring(0, | |
p); | |
fm.add(new MessageLabelField(part, | |
CHAT_COLOR_TEXT)); | |
BitmapField smile = new | |
BitmapField(Contents.displayBitmap(next.substring(p, p + 3))); | |
smile.setPadding(0, 2, 0, 0); | |
fm.add(smile); | |
next = next.substring(p + 3, | |
next.length()); | |
p = next.indexOf(SYM); | |
} | |
if (next.length() > 0) { | |
fm.add(new MessageLabelField(next, | |
CHAT_COLOR_TEXT)); | |
} | |
messages_man.add(fm); | |
} | |
else if ((j = m.indexOf("+url+")) != -1) { | |
//check links | |
vman.add(txtName); | |
String name_link = "link"; | |
if (lin == 0) { | |
lin++; | |
} else { | |
name_link += lin; | |
lin++; | |
} | |
int k = m.indexOf("-url-"); | |
messages_man.add(new | |
MessageLabelField(m.substring(0, j), CHAT_COLOR_TEXT)); | |
j = j + 5; | |
String link = new String(m.substring(j, | |
k)); | |
chat_manager.infopool.put(name_link, | |
link); | |
messages_man.add(new | |
MessageLabelField(link)); | |
k = k + 5; | |
messages_man.add(new | |
MessageLabelField(m.substring(k, m.length()), CHAT_COLOR_TEXT)); | |
} else if (j == -1 && p == -1) { | |
MessageLabelField message = new | |
MessageLabelField(m, CHAT_COLOR_TEXT); | |
messages_man.add(message); | |
} | |
} | |
} | |
} | |
} | |
vman.add(messages_man); | |
if (vman.getFieldCount() > 0) { | |
int scroll = vman.getVirtualHeight() - vman.getVisibleHeight(); | |
if (scroll > 0) {17 | |
vman.setVerticalScroll(scroll); | |
} | |
} | |
} catch (Exception ex) { | |
DebugStorage.getInstance().Log(0, "<ConversationScreen> updateScreen ", | |
ex); | |
Datas.multichat.clear(); | |
Datas.conversations.removeAllElements(); | |
Datas.conversations.trimToSize(); | |
Datas.server_services.removeAllElements(); | |
Datas.conversations.trimToSize(); | |
Datas.readRoster = false; | |
chat_manager.cm.terminateStream(); | |
chat_manager.onlineScreen = null; | |
chat_manager.waitScreen = null; | |
chat_manager.multichatScreen = null; | |
chat_manager.conversationScreen = null; | |
chat_manager.internal_state = chat_manager.OFFLINE; | |
chat_manager.getGuiOfflineMenu(); | |
me.close(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment