Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added text entry ability.

  • Loading branch information...
commit 207c80663fd0e567f3e13826335546074c42b830 1 parent 9ffa169
@oros oros authored
Showing with 75 additions and 11 deletions.
  1. +1 −0  bbm/config.xml
  2. +1 −1  bbm/index.html
  3. +70 −10 bbm/js/bbm.js
  4. +3 −0  bbm/notes.htm
View
1  bbm/config.xml
@@ -39,6 +39,7 @@
<feature id="blackberry.invoke" />
<feature id="blackberry.invoke.card" />
<feature id="blackberry.system" />
+ <feature id="blackberry.ui.toast" />
<!-- Required permissions. -->
<rim:permissions>
View
2  bbm/index.html
@@ -90,7 +90,7 @@
/* Start Chat. */
element.querySelector('#startchat').addEventListener('click', function () {
- bbm.startChat();
+ bbm.startChat('');
}, false);
/* Share Text. */
View
80 bbm/js/bbm.js
@@ -104,22 +104,82 @@ var bbm = {
*
* Specifying no PIN should invoke the Contact Picker, but currently does not. However, shareText with empty data string should do the job.
*/
- startChat: function () {
- blackberry.invoke.invoke({
- action: 'bb.action.BBMCHAT'
- });
+ startChat: function (pin) {
+ pin = prompt('Contact PIN (Ex. 2100000A)', pin);
+
+ /* null is returned on Cancel or empty string; check valid text first. */
+ if (pin !== null) {
+ if (/^[A-Fa-f0-9]{8}$/.test(pin)) {
+ /* Valid PIN format: Invoke Chat/Invite. */
+ blackberry.invoke.invoke({
+ action: 'bb.action.BBMCHAT',
+ uri: 'pin:' + pin
+ });
+ } else {
+ /* Invalid PIN: Prompt to Retry. */
+ blackberry.ui.toast.show(
+ 'Invalid PIN',
+ {
+ buttonText: 'Retry',
+ buttonCallback: function () {
+ bbm.startChat(pin);
+ },
+ dismissCallback: function () {
+ }
+ }
+ );
+ }
+ } else {
+ /* Confirm Cancel or empty string. */
+ blackberry.ui.toast.show(
+ 'Invoke chat with empty string?',
+ {
+ buttonText: 'Yes',
+ buttonCallback: function () {
+ /* Empty PIN: Invoke Contact Picker. */
+ blackberry.invoke.invoke({
+ action: 'bb.action.BBMCHAT'
+ });
+ },
+ dismissCallback: function () {
+ }
+ }
+ );
+ }
},
/**
* shareText: Starts a chat session with pre-populated text.
*/
shareText: function () {
- blackberry.invoke.invoke({
- target: 'sys.bbm.sharehandler',
- action: 'bb.action.SHARE',
- data: 'This is some text.',
- mimeType: 'text/plain'
- });
+ var text = prompt('Default Text', '');
+
+ if (text !== null) {
+ blackberry.invoke.invoke({
+ target: 'sys.bbm.sharehandler',
+ action: 'bb.action.SHARE',
+ data: text,
+ mimeType: 'text/plain'
+ });
+ } else {
+ /* Confirm Cancel or empty string. */
+ blackberry.ui.toast.show(
+ 'Invoke share with empty string?',
+ {
+ buttonText: 'Yes',
+ buttonCallback: function () {
+ blackberry.invoke.invoke({
+ target: 'sys.bbm.sharehandler',
+ action: 'bb.action.SHARE',
+ data: '',
+ mimeType: 'text/plain'
+ });
+ },
+ dismissCallback: function () {
+ }
+ }
+ );
+ }
},
/**
View
3  bbm/notes.htm
@@ -18,5 +18,8 @@
<div style="background-color: #202020" data-bb-type="round-panel">
<div style="color: white;"><b>Start Chat</b> will immediately start a chat session if the provided PIN <b>exists</b> in your <b>Contact List</b>; working as intended.</div>
</div>
+ <div style="background-color: #202020" data-bb-type="round-panel">
+ <div style="color: white;">Currently, some <b>Toast magic</b> is being used to distinguish between <b>Cancel</b> and <b>empty strings</b> in the <b>Start Chat</b> and <b>Share Text</b> prompts.</div>
+ </div>
<div data-bb-type="action-bar" data-bb-back-caption="Back"></div>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.