Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Integrated BBM change.

  • Loading branch information...
commit f0c25e47b45f6b81a5584a0829b26704a6a02348 1 parent 7fc7c7d
@qingbiao qingbiao authored
View
BIN  api/bbm/lib/net_rim_bb_qm_platform.jar
Binary file not shown
View
52 api/bbm/src/main/java/blackberry/bbm/platform/BBMPlatformContextListenerImpl.java
@@ -17,9 +17,15 @@
import net.rim.blackberry.api.bbm.platform.BBMPlatformContext;
import net.rim.blackberry.api.bbm.platform.BBMPlatformContextListener;
+import net.rim.blackberry.api.bbm.platform.profile.BBMPlatformContact;
+import net.rim.blackberry.api.bbm.platform.profile.Presence;
+import net.rim.blackberry.api.bbm.platform.profile.UserProfile;
import net.rim.blackberry.api.bbm.platform.profile.UserProfileBoxItem;
+import net.rim.device.api.script.Scriptable;
import net.rim.device.api.script.ScriptableFunction;
+import blackberry.bbm.platform.self.SelfNamespace;
import blackberry.bbm.platform.self.profilebox.ScriptableProfileBoxItem;
+import blackberry.bbm.platform.users.BBMPlatformUser;
import blackberry.bbm.platform.util.ConstantsUtil;
import blackberry.bbm.platform.util.Util;
@@ -60,7 +66,7 @@ public void accessChanged(boolean isAccessAllowed, int code) {
Util.dispatchCallback(callback, args);
}
- public void appInvoked(int reason, Object param) {
+ public void appInvoked(int reason, Object param, Presence user) {
final ScriptableFunction callback;
try {
callback = (ScriptableFunction) _platform.getField(BBMPlatformNamespace.EVENT_ON_APP_INVOKED);
@@ -68,15 +74,47 @@ public void appInvoked(int reason, Object param) {
return;
}
- final Object[] args;
- if(reason == BBMPlatformContext.INVOKE_PROFILE_BOX_ITEM) {
- final ScriptableProfileBoxItem scriptItem =
- new ScriptableProfileBoxItem(_platform.getProfileBox(), (UserProfileBoxItem) param);
- args = new Object[] { "profilebox", scriptItem };
+ // Get reason string and scriptable param
+ final String reasonStr;
+ final Object scriptableParam;
+ switch(reason) {
+ case BBMPlatformContext.INVOKE_PROFILE_BOX_ITEM:
+ reasonStr = "profilebox";
+ scriptableParam = new ScriptableProfileBoxItem(_platform.getProfileBox(), (UserProfileBoxItem) param);
+ break;
+ case BBMPlatformContext.INVOKE_PROFILE_BOX:
+ reasonStr = "profileboxtitle";
+ scriptableParam = Scriptable.UNDEFINED;
+ break;
+ case BBMPlatformContext.INVOKE_PERSONAL_MESSAGE:
+ reasonStr = "personalmessage";
+ scriptableParam = (String) param;
+ break;
+ case BBMPlatformContext.INVOKE_CHAT_MESSAGE:
+ reasonStr = "chatmessage";
+ scriptableParam = Scriptable.UNDEFINED;
+ break;
+ default:
+ // Don't invoke if we don't know what to do with the reason
+ return;
+ }
+
+ // Get scriptable user: either self namespace of BBMPlatformUser instance
+ final Object scriptableUser;
+ if(user instanceof UserProfile) {
+ scriptableUser = SelfNamespace.getInstance();
+ } else if(user instanceof BBMPlatformContact) {
+ scriptableUser = new BBMPlatformUser(user);
} else {
- return;
+ scriptableUser = Scriptable.UNDEFINED;
}
+ final Object[] args = {
+ reasonStr,
+ scriptableParam,
+ scriptableUser,
+ };
Util.dispatchCallback(callback, args);
}
+
}
View
63 api/bbm/src/main/java/blackberry/bbm/platform/BBMPlatformNamespace.java
@@ -27,6 +27,7 @@
import blackberry.bbm.platform.io.IONamespace;
import blackberry.bbm.platform.io.MessagingServiceListenerImpl;
import blackberry.bbm.platform.self.SelfNamespace;
+import blackberry.bbm.platform.settings.SettingsNamespace;
import blackberry.bbm.platform.ui.UINamespace;
import blackberry.bbm.platform.users.UsersNamespace;
import blackberry.bbm.platform.util.ConstantsUtil;
@@ -43,6 +44,7 @@
public static final String FUNC_REGISTER = "register";
public static final String FUNC_REQUEST_USER_PERMISSION = "requestUserPermission";
+ public static final String FUNC_SHOW_OPTIONS = "showBBMAppOptions";
public static final String FIELD_ENVIRONMENT = "environment";
public static final String EVENT_ON_APP_INVOKED = "onappinvoked";
public static final String EVENT_ON_ACCESS_CHANGED = "onaccesschanged";
@@ -99,6 +101,8 @@ public Object getField(String name) throws Exception {
return new RegisterFunction();
} else if(name.equals(BBMPlatformNamespace.FUNC_REQUEST_USER_PERMISSION)) {
return new RequestUserPermissionFunction();
+ } else if(name.equals(BBMPlatformNamespace.FUNC_SHOW_OPTIONS)) {
+ return new ShowOptionsFunction();
} else if(name.equals(SelfNamespace.NAME)) {
return SelfNamespace.getInstance();
} else if(name.equals(UsersNamespace.NAME)) {
@@ -107,6 +111,8 @@ public Object getField(String name) throws Exception {
return IONamespace.getInstance();
} else if(name.equals(UINamespace.NAME)) {
return UINamespace.getInstance();
+ } else if(name.equals(SettingsNamespace.NAME)) {
+ return SettingsNamespace.getInstance();
} else if(_wFields.hasField(name)){
return _wFields.getField(name);
} else if(name.equals(FIELD_ENVIRONMENT)) {
@@ -126,22 +132,42 @@ private Object getEnvironment() {
} catch(ControlledAccessException e) {
return UNDEFINED;
}
-
}
private class RegisterFunction extends ScriptableFunctionBase {
- public static final String OPTIONS_FIELD_UUID = "uuid";
+ public static final String OPTIONS_FIELD_UUID = "uuid";
+ public static final String OPTIONS_FIELD_SHARECONTENTSPLAT = "shareContentSplat";
protected Object execute(Object thiz, Object[] args) throws Exception {
final Object onAccessChanged = BBMPlatformNamespace.this.getField(EVENT_ON_ACCESS_CHANGED);
if(onAccessChanged.equals(UNDEFINED)) {
- throw new IllegalStateException("blackberry.bbm.platform.onAccessChanged == undefined");
+ throw new IllegalStateException("blackberry.bbm.platform.onaccesschanged == undefined");
}
final Scriptable options = (Scriptable) args[0];
final String uuid = (String) options.getField(OPTIONS_FIELD_UUID);
- final BBMPlatformApplication bbmApp = new BBMPlatformApplication(uuid);
+
+ // Get optional shareContentSplat property
+ final Object shareContentSplatObj = options.getField(OPTIONS_FIELD_SHARECONTENTSPLAT);
+ boolean shareContentSplat;
+ try {
+ shareContentSplat = ((Boolean) shareContentSplatObj).booleanValue();
+ } catch(Exception e) {
+ shareContentSplat = false;
+ }
+ final boolean finalShareContentSplat = shareContentSplat;
+
+ final BBMPlatformApplication bbmApp = new BBMPlatformApplication(uuid) {
+ public int getDefaultSettings() {
+ if(finalShareContentSplat) {
+ return super.getDefaultSettings() | BBMPlatformContext.SETTING_SHARECONTENT_SPLAT;
+ } else {
+ return super.getDefaultSettings();
+ }
+
+ }
+ };
Dispatcher.getInstance().dispatch(new DispatchableEvent(null) {
protected void dispatch() {
@@ -196,4 +222,33 @@ public void run() {
};
}
} // RequestUserPermissionFunction
+
+ private class ShowOptionsFunction extends ScriptableFunctionBase {
+
+ protected Object execute(Object thiz, Object[] args) throws Exception {
+
+ final ScriptableFunction onComplete = (ScriptableFunction) args[0];
+
+ UiApplication.getUiApplication().invokeLater(new Runnable() {
+ public void run() {
+ UiApplication.getUiApplication().invokeLater(new Runnable() {
+ public void run() {
+ _bbmpContext.requestAppSettings();
+ Util.dispatchCallback(onComplete, null);
+ }
+ });
+ }
+ });
+
+ return UNDEFINED;
+ }
+
+ protected FunctionSignature[] getFunctionSignatures() {
+ FunctionSignature sig1 = new FunctionSignature(1);
+ sig1.addParam(ScriptableFunction.class, true);
+ return new FunctionSignature[] {
+ sig1
+ };
+ }
+ } // ShowOptionsFunction
}
View
19 api/bbm/src/main/java/blackberry/bbm/platform/io/MessagingServiceListenerImpl.java
@@ -15,6 +15,7 @@
*/
package blackberry.bbm.platform.io;
+import java.util.Date;
import java.util.Hashtable;
import net.rim.blackberry.api.bbm.platform.io.BBMPlatformChannel;
@@ -28,6 +29,7 @@
import net.rim.blackberry.api.bbm.platform.service.MessagingServiceListener;
import net.rim.device.api.script.ScriptableFunction;
import blackberry.bbm.platform.users.BBMPlatformUser;
+import blackberry.bbm.platform.users.UsersNamespace;
import blackberry.bbm.platform.util.ConstantsUtil;
import blackberry.bbm.platform.util.Util;
import blackberry.core.threading.DispatchableEvent;
@@ -230,4 +232,21 @@ public void onMessagesExpired(BBMPlatformContact contact, BBMPlatformData[] data
};
Util.dispatchCallback(callback, args);
}
+
+ public void onShareContentReceived(BBMPlatformContact contact, String description, BBMPlatformData content, long timestamp) {
+ final ScriptableFunction callback;
+ try {
+ callback = (ScriptableFunction) UsersNamespace.getInstance().getField(UsersNamespace.EVENT_ON_SHARE_CONTENT);
+ } catch(Exception e) {
+ return;
+ }
+ final Object[] args = {
+ new BBMPlatformUser(contact),
+ content.getDataAsString(),
+ description,
+ new Date(timestamp),
+ };
+ Util.dispatchCallback(callback, args);
+ }
+
}
View
2  api/bbm/src/main/java/blackberry/bbm/platform/self/SelfNamespace.java
@@ -107,7 +107,7 @@ protected void dispatch() {
protected FunctionSignature[] getFunctionSignatures() {
FunctionSignature sig1 = new FunctionSignature(2);
- sig1.addParam(String.class, true);
+ sig1.addNullableParam(String.class, true);
sig1.addParam(ScriptableFunction.class, true);
return new FunctionSignature[] {
View
7 api/bbm/src/main/java/blackberry/bbm/platform/self/profilebox/ProfileBoxNamespace.java
@@ -15,6 +15,8 @@
*/
package blackberry.bbm.platform.self.profilebox;
+import java.nio.ByteBuffer;
+
import net.rim.blackberry.api.bbm.platform.profile.UserProfile;
import net.rim.blackberry.api.bbm.platform.profile.UserProfileBox;
import net.rim.blackberry.api.bbm.platform.profile.UserProfileBoxAccessException;
@@ -117,8 +119,9 @@ protected Object execute(Object thiz, Object[] args) throws Exception {
if(iconURI.equals(UNDEFINED)) {
iconID = -1;
} else {
- final Bitmap icon = Util.requestBitmap((String) iconURI);
- iconID = Math.abs(icon.hashCode()); // icon ID is hash code of bitmap
+ final byte[] iconBytes = Util.requestBitmapBytes((String) iconURI);
+ final Bitmap icon = Bitmap.createBitmapFromBytes(iconBytes, 0, iconBytes.length, 1);
+ iconID = Math.abs(ByteBuffer.wrap(iconBytes).hashCode()); // icon ID is hash code of bitmap
if(! _profileBox.isIconRegistered(iconID)) {
_profileBox.registerIcon(iconID, PNGEncodedImage.encode(icon));
}
View
39 api/bbm/src/main/java/blackberry/bbm/platform/settings/SettingsNamespace.java
@@ -0,0 +1,39 @@
+package blackberry.bbm.platform.settings;
+
+import blackberry.bbm.platform.BBMPlatformNamespace;
+import net.rim.blackberry.api.bbm.platform.SettingsManager;
+import net.rim.device.api.script.Scriptable;
+
+public class SettingsNamespace extends Scriptable {
+
+ public static final String NAME = "settings";
+
+ private static final String FIELD_PROFILE_BOX = "profileboxEnabled";
+ private static final String FIELD_PUBLIC_CONNS = "alwaysAllowPublicConns";
+
+ private static SettingsNamespace _instance;
+
+ private final SettingsManager _settings;
+
+ public SettingsNamespace(SettingsManager settings) {
+ _settings = settings;
+ }
+
+ public static SettingsNamespace getInstance() {
+ if(_instance == null) {
+ final SettingsManager settings = BBMPlatformNamespace.getInstance().getContext().getSettingsManager();
+ _instance = new SettingsNamespace(settings);
+ }
+ return _instance;
+ }
+
+ public Object getField(String name) throws Exception {
+ if(name.equals(FIELD_PROFILE_BOX)) {
+ return new Boolean(_settings.getSetting(SettingsManager.SETTING_PROFILE_BOX) == SettingsManager.VALUE_ENABLED);
+ } else if(name.equals(FIELD_PUBLIC_CONNS)) {
+ return new Boolean(_settings.getSetting(SettingsManager.SETTING_ALWAYS_ALLOW_PUBLIC_CONN) == SettingsManager.VALUE_ENABLED);
+ } else {
+ return UNDEFINED;
+ }
+ }
+}
View
22 api/bbm/src/main/java/blackberry/bbm/platform/users/BBMPlatformUser.java
@@ -23,14 +23,16 @@
public class BBMPlatformUser extends Scriptable {
- public static final String FIELD_DISPLAY_PIC = "displayPicture";
- public static final String FIELD_DISPLAY_NAME = "displayName";
- public static final String FIELD_PERSONAL_MSG = "personalMessage";
- public static final String FIELD_STATUS = "status";
- public static final String FIELD_STATUS_MSG = "statusMessage";
- public static final String FIELD_HANDLE = "handle";
- public static final String FIELD_PPID = "ppid";
- public static final String FIELD_TYPE = "type";
+ public static final String FIELD_DISPLAY_PIC = "displayPicture";
+ public static final String FIELD_DISPLAY_NAME = "displayName";
+ public static final String FIELD_PERSONAL_MSG = "personalMessage";
+ public static final String FIELD_STATUS = "status";
+ public static final String FIELD_STATUS_MSG = "statusMessage";
+ public static final String FIELD_HANDLE = "handle";
+ public static final String FIELD_PPID = "ppid";
+ public static final String FIELD_TYPE = "type";
+ public static final String FIELD_APP_VERSION = "appVersion";
+ public static final String FIELD_BBM_SDK_VERSION = "bbmsdkVersion";
public static final String STATUS_STR_AVAILABLE = "available";
public static final String STATUS_STR_BUSY = "busy";
@@ -57,6 +59,10 @@ public Object getField(String name) throws Exception {
return BBMPlatformUser.statusToString(_presence.getStatus());
} else if(name.equals(BBMPlatformUser.FIELD_STATUS_MSG)) {
return _presence.getStatusMessage();
+ } else if(name.equals(BBMPlatformUser.FIELD_APP_VERSION)) {
+ return _presence.getAppVersion();
+ } else if(name.equals(BBMPlatformUser.FIELD_BBM_SDK_VERSION)) {
+ return new Integer(_presence.getBBMSDKVersion());
} else if(name.equals(BBMPlatformUser.FIELD_TYPE)) {
return "BBM";
} else if(name.equals(BBMPlatformUser.FIELD_HANDLE)) {
View
80 api/bbm/src/main/java/blackberry/bbm/platform/users/UsersNamespace.java
@@ -17,6 +17,7 @@
import net.rim.blackberry.api.bbm.platform.BBMPlatformContext;
import net.rim.blackberry.api.bbm.platform.io.BBMPlatformConnection;
+import net.rim.blackberry.api.bbm.platform.io.BBMPlatformData;
import net.rim.blackberry.api.bbm.platform.io.IOErrorCode;
import net.rim.blackberry.api.bbm.platform.profile.BBMInvitationRequest;
import net.rim.blackberry.api.bbm.platform.profile.BBMPlatformContact;
@@ -52,6 +53,8 @@
private static final String FUNC_SEND_FILE = "sendFile";
private static final String FIELD_CONTACTS_WITH_APP = "contactsWithApp";
private static final String EVENT_ON_UPDATE = "onupdate";
+ private static final String FUNC_SHARE_CONTENT = "shareContent";
+ public static final String EVENT_ON_SHARE_CONTENT = "onsharecontent";
private static UsersNamespace instance;
@@ -62,6 +65,7 @@
private UsersNamespace() {
_wFields = new ScriptableFieldManager();
_wFields.addField(EVENT_ON_UPDATE);
+ _wFields.addField(EVENT_ON_SHARE_CONTENT);
}
public static UsersNamespace getInstance() {
@@ -98,6 +102,8 @@ public Object getField(String name) throws Exception {
return new InviteToBBMConnFunction();
} else if(name.equals(FUNC_SEND_FILE)) {
return new SendFileFunction();
+ } else if(name.equals(FUNC_SHARE_CONTENT)) {
+ return new ShareContentFunction();
} else if(_wFields.hasField(name)) {
return _wFields.getField(name);
} else {
@@ -485,6 +491,80 @@ protected Object execute(Object thiz, Object[] args) throws Exception {
};
}
} // SendFileFunction
+
+ private static class ShareContentFunction extends ScriptableFunctionBase {
+
+ protected Object execute(Object thiz, Object[] args) throws Exception {
+ final String content = (String) args[0];
+ final String description = (String) args[1];
+ final ScriptableFunction onComplete = (ScriptableFunction) args[2];
+ final Object options;
+ if(args.length >= 4) {
+ options = args[3];
+ } else {
+ options = null;
+ }
+
+ // Throw exceptions for too long parameters
+ final int maxContentLength = 61124;
+ if(content.length() > maxContentLength) {
+ throw new IllegalArgumentException("content.length > " + maxContentLength);
+ }
+ final int maxDescLength = 128;
+ if(description.length() > maxDescLength) {
+ throw new IllegalArgumentException("description.length > " + maxDescLength);
+ }
+
+ // Parse options object for title and contacts
+ final String title;
+ final ContactListProvider contacts;
+ if(options == null || options.equals(UNDEFINED)) {
+ title = null;
+ contacts = null;
+ } else {
+ // Title
+ final Scriptable optionsObj = (Scriptable) options;
+ final Object titleObj = optionsObj.getField("title");
+ if(titleObj.equals(UNDEFINED)) {
+ title = null;
+ } else {
+ title = (String) titleObj;
+ }
+
+ // Contacts
+ Object contactsObj = optionsObj.getField("users");
+ if(contactsObj.equals(UNDEFINED)) {
+ contacts = null;
+ } else {
+ final BBMPlatformUser[] users = Util.scriptableUsersArrayToUserArray((Scriptable) contactsObj);
+ contacts = new Util.SimpleContactListProvider(users);
+ }
+ }
+
+ // Call API
+ final BBMPlatformNamespace bbmpNpsc = BBMPlatformNamespace.getInstance();
+ final MessagingService msgService = bbmpNpsc.getMessagingService();
+ UiApplication.getUiApplication().invokeLater(new Runnable() {
+ public void run() {
+ msgService.shareContent(description, new BBMPlatformData(content), contacts, title);
+ Util.dispatchCallback(onComplete, null);
+ }
+ });
+
+ return UNDEFINED;
+ }
+
+ protected FunctionSignature[] getFunctionSignatures() {
+ FunctionSignature sig1 = new FunctionSignature(4);
+ sig1.addParam(String.class, true);
+ sig1.addParam(String.class, true);
+ sig1.addParam(ScriptableFunction.class, true);
+ sig1.addParam(Scriptable.class, false);
+ return new FunctionSignature[] {
+ sig1
+ };
+ }
+ } // ShareContentFunction
private static String eventTypeToString(int eventType) {
switch(eventType) {
View
7 api/bbm/src/main/java/blackberry/bbm/platform/util/Util.java
@@ -73,6 +73,11 @@ public static String bitmapToBase64Str(Bitmap bitmap) {
}
public static Bitmap requestBitmap(String uri) throws Exception {
+ byte[] bmpBytes = requestBitmapBytes(uri);
+ return Bitmap.createBitmapFromBytes(bmpBytes, 0, bmpBytes.length, 1);
+ }
+
+ public static byte[] requestBitmapBytes(String uri) throws Exception {
BrowserField browserField = (BrowserField) BBMPlatformExtension._browserField.get();
final BrowserFieldConfig bfConfig = browserField.getConfig();
final BrowserFieldController bfController =
@@ -94,7 +99,7 @@ public static Bitmap requestBitmap(String uri) throws Exception {
} catch(EOFException e) {
}
- return Bitmap.createBitmapFromBytes(bmpBytes.getArray(), 0, bmpBytes.size(), 1);
+ return bmpBytes.getArray();
} finally {
try {
ic.close();
Please sign in to comment.
Something went wrong with that request. Please try again.