Skip to content

Instantly share code, notes, and snippets.

View soulfly's full-sized avatar

Mr. software craftsman soulfly

View GitHub Profile
@soulfly
soulfly / gist:4148120
Created November 26, 2012 13:12
BlackBerry 5,6,7 Chat sample: Create session, User Sign Up, User Sign In
// Make request
public void doRequest(int type)
{
switch(type)
{
// Create session request
case REQUEST_SESSION:
{
String time = new Long(new Date().getTime()).toString();
String timestamp = time.substring(0, time.length()-3);
@soulfly
soulfly / gist:4148141
Created November 26, 2012 13:17
BlackBerry chat sample 5,6,7: Add the new contacts to the contact list
chat_manager.internal_state = chat_manager.ONLINE;
boolean changes = false; // test if there are changes
boolean onlyphone = false;
boolean isNew = true;
if (chat_manager.currentjid == null ||
!jid.getText().equals(chat_manager.currentjid.getFullJid()) ||
!group.getText().equals(chat_manager.currentjid.group) || (phone.getText() != null &&
!phone.getText().equals(chat_manager.currentjid.phone))) {
if (chat_manager.currentjid != null &&
jid.getText().equals(chat_manager.currentjid.getFullJid()) &&
@soulfly
soulfly / gist:4148156
Created November 26, 2012 13:19
BlackBerry 5,6,7 Chat sample: Change status of the chat
if (field == bOnline) {
if (chat_manager.internal_state != chat_manager.OFFLINE &&
chat_manager.internal_state != chat_manager.WAIT_CONNECT && Datas.jid != null) {
Presence.changePresence(Presence.getPresence("online"),
Datas.jid.status_message);
Datas.jid.setPresence(Presence.getPresence("online"),
Datas.jid.status_message);
chat_manager.getGuiOnlineMenu();
}
} else if (field == bAway) {
@soulfly
soulfly / gist:4148169
Created November 26, 2012 13:22
BlackBerry 5,6,7 Chat sample: Send message
// 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++) {
@soulfly
soulfly / BlackBerry 5,6,7 Chat sample: Login to Chat
Created November 26, 2012 13:50
BlackBerry 5,6,7 Chat sample: Login to Chat
public void LoginToChat(final String _jid, final String _password, final String _userid)
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
jidName = _jid;
String jid = "";
String password = "";
String server = SERVER;
@soulfly
soulfly / gist:4153456
Created November 27, 2012 10:11
BlackBerry 5,6,7 Messages sample: Reception notifications (TURN ON)
try {
System.out.println("----- Successfully subsribed on Push notifications");
// Push Notification ON = 0
// Push Notification OFF = 1
OptionStorage.getInstance().getOption("Push notifications").setCurrentValueIndex(0);
} catch (Exception ex) {
DebugStorage.getInstance().Log(0, "<PushQbAuth> ProcessAnswer REQUEST_PUSH_SUBSCRIBE
Exception ", ex);
}
break;
@soulfly
soulfly / gist:4153464
Created November 27, 2012 10:13
BlackBerry 5,6,7 Messages sample: Reception notifications (TURN OFF)
try {
System.out.println("----- Successfullly UNSUBSCRIBED FROM PUSH");
// Push Notification ON = 0
// Push Notification OFF = 1
OptionStorage.getInstance().getOption("Push notifications").setCurrentValueIndex(1);
} catch (Exception ex) {
DebugStorage.getInstance().Log(0, "<UnsubscribeQbPush> ProcessAnswer
REQUEST_PUSH_UNSUBSCRIBE ", ex);
}
break;
@soulfly
soulfly / gist:4153469
Created November 27, 2012 10:15
BlackBerry 5,6,7 Messages sample: Review the notifications
LabelField pushressievedLabel = new LabelField("Message ressieved on:") {
public void paint(Graphics g) {
g.setColor(0xffffff);
super.paint(g);
}
};
pushressievedLabel.setPadding(5, 5, 0, 5);
pushressievedLabel.setFont(pushressievedLabel.getFont().derive(Font.BOLD));
add(pushressievedLabel);
@soulfly
soulfly / gist:4153474
Created November 27, 2012 10:15
BlackBerry 5,6,7 Messages sample: Remove the notifications
try {
PushNotificationsStorage.getInstance().removePushNotification(pNO);
onClose();
} catch (Exception ex) {
System.out.println("removePushNotification exception = " + ex);
}
@soulfly
soulfly / Java HMAC_SHA1_ALGORITHM
Created December 12, 2012 13:25
Java HMAC_SHA1_ALGORITHM
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.security.SignatureException;
/**
* @author Igor Khomenko
* injoit.com
*
* This class defines common routines for generating