Skip to content
Browse files

BlackBerry Samples for Java release 4.6.0.

An Open Source version of the samples as they were released
with the 4.6.0 Java Development Environment release.

The BlackBerry Samples for Java project is an Open Source
repository of samples that in the past were released through
the BlackBerry Developer Knowledge Base or within the
BlackBerry Java Tools.  The samples range in scope from Hello
World, to Advanced UI components and include both samples and
libraries that offer extended functionality.

Copyright (c) 2011 Research In Motion Limited

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
  • Loading branch information...
1 parent 2f42024 commit faad141d92507217265924018d676c6af128d6a5 @slegge slegge committed Dec 1, 2011
Showing with 4,874 additions and 2,967 deletions.
  1. +38 −35 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo.java
  2. +2 −0 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo.jdp
  3. +2 −0 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo_autostartup.jdp
  4. +32 −28 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsDemo.java
  5. +5 −0 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsDemo.jdp
  6. +2 −2 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsScreen.java
  7. +83 −0 com/rim/samples/device/applicationpermissionsdemo/DemoReasonProvider.java
  8. +1 −2 com/rim/samples/device/blackberry/browser/BrowserContentManagerDemo.java
  9. +2 −0 com/rim/samples/device/blackberry/browser/BrowserContentManagerDemo.jdp
  10. +2 −3 com/rim/samples/device/blackberry/browser/BrowserFieldDemo.java
  11. +1 −1 com/rim/samples/device/blackberry/browser/BrowserPlugin.java
  12. +2 −0 com/rim/samples/device/blackberry/browser/BrowserPlugin.jdp
  13. +2 −0 com/rim/samples/device/blackberry/browser/CommonLib.jdp
  14. +2 −2 com/rim/samples/device/blackberry/browser/SecondaryResourceFetchThread.java
  15. +2 −2 com/rim/samples/device/blackberry/browser/Utilities.java
  16. +2 −0 com/rim/samples/device/blackberry/options/OptionsProviderDemo.jdp
  17. +2 −0 com/rim/samples/device/blackberry/pim/PIMDemo.jdp
  18. +10 −8 com/rim/samples/device/blackberrymapsdemo/BlackBerryMapsDemo.java
  19. +2 −0 com/rim/samples/device/blackberrymapsdemo/BlackBerryMapsDemo.jdp
  20. +2 −2 com/rim/samples/device/blackberrymapsdemo/InvokeContactScreen.java
  21. +2 −2 com/rim/samples/device/blackberrymapsdemo/InvokeDefaultScreen.java
  22. +31 −22 com/rim/samples/device/blackberrymapsdemo/InvokeLocationDocumentScreen.java
  23. +2 −2 com/rim/samples/device/blackberrymapsdemo/InvokeMapViewScreen.java
  24. +1 −1 com/rim/samples/device/bluetoothdemo/AppScreen.java
  25. +1 −1 com/rim/samples/device/bluetoothdemo/BluetoothDemo.java
  26. +9 −0 com/rim/samples/device/bluetoothdemo/BluetoothDemo.jdp
  27. +1 −1 com/rim/samples/device/bluetoothdemo/SSPScreen.java
  28. +19 −15 com/rim/samples/device/bluetoothdemo/readme.txt
  29. +2 −2 com/rim/samples/device/bluetoothserialportdemo/BluetoothSerialPortDemo.java
  30. +2 −0 com/rim/samples/device/bluetoothserialportdemo/BluetoothSerialPortDemo.jdp
  31. +353 −0 com/rim/samples/device/bufferedplaybackdemo/BufferedPlayback.java
  32. +708 −0 com/rim/samples/device/bufferedplaybackdemo/LimitedRateStreamingSource.java
  33. +52 −0 com/rim/samples/device/bufferedplaybackdemo/bufferedplaybackdemo.jdp
  34. BIN com/rim/samples/device/bufferedplaybackdemo/img/bufferedplaybackdemo_jde.png
  35. +307 −0 com/rim/samples/device/camerademo/CameraDemo.java
  36. +53 −0 com/rim/samples/device/camerademo/CameraDemo.jdp
  37. +142 −0 com/rim/samples/device/camerademo/EncodingProperties.java
  38. +201 −0 com/rim/samples/device/camerademo/ImageScreen.java
  39. BIN com/rim/samples/device/camerademo/img/camerademo_jde.png
  40. +20 −19 com/rim/samples/device/chapidemo/ChapiDemo.java
  41. +8 −2 com/rim/samples/device/chapidemo/ChapiDemo.jdp
  42. +8 −2 com/rim/samples/device/chapidemo/ChapiDemo_Autostartup.jdp
  43. +0 −99 com/rim/samples/device/contactsdemo/ContactModel.java
  44. +0 −511 com/rim/samples/device/contactsdemo/ContactsDemo.java
  45. +0 −107 com/rim/samples/device/contactsdemo/ContactsPersistentContentListener.java
  46. BIN com/rim/samples/device/contactsdemo/img/contacts_jde.png
  47. +3 −3 com/rim/samples/device/cryptodemo/CryptoDemo.java
  48. +102 −76 com/rim/samples/device/custombuttonsdemo/CustomButtonField.java
  49. +97 −19 com/rim/samples/device/custombuttonsdemo/CustomButtonsDemo.java
  50. +5 −0 com/rim/samples/device/custombuttonsdemo/CustomButtonsDemo.jdp
  51. +168 −0 com/rim/samples/device/custombuttonsdemo/PictureBackgroundButtonField.java
  52. BIN com/rim/samples/device/custombuttonsdemo/img/blue_scribble.bmp
  53. BIN com/rim/samples/device/custombuttonsdemo/img/pink_scribble.bmp
  54. +193 −0 com/rim/samples/device/decordemo/DecorDemo.java
  55. +14 −13 com/rim/samples/device/{syncdemo/SyncDemo.jdp → decordemo/decordemo.jdp}
  56. BIN com/rim/samples/device/decordemo/img/decordemo_jde.png
  57. BIN com/rim/samples/device/decordemo/img/smiley.bmp
  58. +328 −0 com/rim/samples/device/embeddedmapdemo/EmbeddedMapDemo.java
  59. +12 −15 com/rim/samples/device/{contactsdemo/ContactsDemo.jdp → embeddedmapdemo/EmbeddedMapDemo.jdp}
  60. +267 −0 com/rim/samples/device/embeddedmapdemo/ExtendedMapField.java
  61. +322 −0 com/rim/samples/device/embeddedmapdemo/LocatorScreen.java
  62. +184 −0 com/rim/samples/device/embeddedmapdemo/LookupMatchesScreen.java
  63. +64 −0 com/rim/samples/device/embeddedmapdemo/MapLocation.java
  64. +179 −0 com/rim/samples/device/embeddedmapdemo/SavedLocationsScreen.java
  65. BIN com/rim/samples/device/embeddedmapdemo/img/marker.PNG
  66. BIN com/rim/samples/device/embeddedmapdemo/img/pointer.png
  67. +4 −4 com/rim/samples/device/embeddedmediademo/EmbeddedMediaDemo.java
  68. +2 −0 com/rim/samples/device/embeddedmediademo/EmbeddedMediaDemo.jdp
  69. BIN com/rim/samples/device/embeddedmediademo/media/BlackBerry.mp4
  70. +1 −1 com/rim/samples/device/fileexplorerdemo/FileExplorerDemo.java
  71. +2 −0 com/rim/samples/device/fileexplorerdemo/FileExplorerDemo.jdp
  72. +4 −4 com/rim/samples/device/fileexplorerdemo/FileExplorerDemoFileHolder.java
  73. +3 −3 com/rim/samples/device/fileexplorerdemo/FileExplorerDemoListFieldImpl.java
  74. +21 −38 com/rim/samples/device/gpsdemo/GPSDemo.java
  75. +53 −74 com/rim/samples/device/gpsdemo/PointScreen.java
  76. +3 −3 com/rim/samples/device/helloworlddemo/HelloWorldDemo.java
  77. +12 −12 com/rim/samples/device/httpdemo/HTTPDemo.java
  78. +4 −4 com/rim/samples/device/httpdemo/WapOptionsScreen.java
  79. +3 −3 com/rim/samples/device/httppushdemo/HTTPPushDemo.java
  80. +3 −3 com/rim/samples/device/keywordfilterdemo/KeywordFilterDemo.java
  81. +2 −0 com/rim/samples/device/keywordfilterdemo/KeywordFilterDemo.jdp
  82. +3 −3 com/rim/samples/device/keywordfilterdemo/KeywordFilterDemoScreen.java
  83. +5 −5 com/rim/samples/device/localizationdemo/LocalizationDemo.java
  84. +22 −0 com/rim/samples/device/localizationdemo/LocalizationDemo.jdp
  85. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_ar.rrc
  86. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_ca.rrc
  87. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_cs.rrc
  88. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_eu.rrc
  89. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_gl.rrc
  90. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_he.rrc
  91. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_hu.rrc
  92. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_in.rrc
  93. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_ja.rrc
  94. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_ko.rrc
  95. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_nl.rrc
  96. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_pl.rrc
  97. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_pt.rrc
  98. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_pt_BR.rrc
  99. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_ru.rrc
  100. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_th.rrc
  101. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_tr.rrc
  102. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_zh.rrc
  103. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_zh_CN.rrc
  104. +24 −0 com/rim/samples/device/localizationdemo/resource/LocalizationDemo_zh_TW.rrc
  105. +4 −4 com/rim/samples/device/mapfielddemo/DemoMapField.java
  106. +1 −1 com/rim/samples/device/mapfielddemo/MapFieldDemo.java
  107. +2 −0 com/rim/samples/device/mapfielddemo/MapFieldDemo.jdp
  108. +1 −1 com/rim/samples/device/mapfielddemo/MapFieldDemoScreen.java
  109. +14 −14 com/rim/samples/device/mapfielddemo/MapFieldDemoSite.java
  110. +5 −5 com/rim/samples/device/mapfielddemo/MapFieldDemoTokenizer.java
  111. +3 −3 com/rim/samples/device/mapsmenuitemdemo/MapsMenuItemDemo.java
  112. +2 −0 com/rim/samples/device/mapsmenuitemdemo/MapsMenuItemDemo.jdp
  113. BIN com/rim/samples/device/mediaenginedemo/Images/big_cloud_png_copy_3_img_1_4.png
  114. BIN com/rim/samples/device/mediaenginedemo/Images/big_cloud_png_copy_4_img_1_4.png
  115. BIN com/rim/samples/device/mediaenginedemo/Images/bolt1a_png_copy_3_img_1_4.png
  116. BIN com/rim/samples/device/mediaenginedemo/Images/bolt1b_png_copy_3_img_1_4.png
  117. BIN com/rim/samples/device/mediaenginedemo/Images/bolt1c_png_copy_3_img_1_4.png
  118. BIN com/rim/samples/device/mediaenginedemo/Images/bolt2a_png_copy_3_img_1_4.png
  119. BIN com/rim/samples/device/mediaenginedemo/Images/bolt2b_png_copy_3_img_1_4.png
  120. BIN com/rim/samples/device/mediaenginedemo/Images/bolt2c_png_copy_3_img_1_4.png
  121. BIN com/rim/samples/device/mediaenginedemo/Images/cloud1_png_copy_5_img_1_4.png
  122. BIN com/rim/samples/device/mediaenginedemo/Images/cloud1_png_copy_img_1_4.png
  123. BIN com/rim/samples/device/mediaenginedemo/Images/cloud2_png_copy_3_img_1_4.png
  124. BIN com/rim/samples/device/mediaenginedemo/Images/cloud2_png_copy_4_img_1_4.png
  125. BIN com/rim/samples/device/mediaenginedemo/Images/cloud2_png_copy_img_1_4.png
  126. BIN com/rim/samples/device/mediaenginedemo/Images/cloud3_png_copy_3_img_1_4.png
  127. BIN com/rim/samples/device/mediaenginedemo/Images/cloud3_png_copy_img_1_4.png
  128. BIN com/rim/samples/device/mediaenginedemo/Images/cloud4_png_copy_img_1_4.png
  129. BIN com/rim/samples/device/mediaenginedemo/Images/cloud_png_copy_3_img_1_4.png
  130. BIN com/rim/samples/device/mediaenginedemo/Images/footer_png_copy_4_img_1_4.png
  131. BIN com/rim/samples/device/mediaenginedemo/Images/rain_drop_png_copy_9_img_1_4.png
  132. BIN com/rim/samples/device/mediaenginedemo/Images/rays1_png_copy_img_1_4.png
  133. BIN com/rim/samples/device/mediaenginedemo/Images/rays2_png_copy_img_1_4.png
  134. BIN com/rim/samples/device/mediaenginedemo/Images/sky_png_copy_img_1_4.png
  135. BIN com/rim/samples/device/mediaenginedemo/Images/streak1_png_copy_3_img_1_4.png
  136. BIN com/rim/samples/device/mediaenginedemo/Images/streak1_png_copy_img_1_4.png
  137. BIN com/rim/samples/device/mediaenginedemo/Images/streak2_png_copy_3_img_1_4.png
  138. BIN com/rim/samples/device/mediaenginedemo/Images/streak2_png_copy_img_1_4.png
  139. BIN com/rim/samples/device/mediaenginedemo/Images/streak3_png_copy_3_img_1_4.png
  140. BIN com/rim/samples/device/mediaenginedemo/Images/streak3_png_copy_img_1_4.png
  141. BIN com/rim/samples/device/mediaenginedemo/Images/sun1_png_copy_img_1_4.png
  142. BIN com/rim/samples/device/mediaenginedemo/Images/sun2_png_copy_img_1_4.png
  143. BIN com/rim/samples/device/mediaenginedemo/Images/sun_ray01_png_copy_img_1_4.png
  144. BIN com/rim/samples/device/mediaenginedemo/Images/sun_ray02_png_copy_img_1_4.png
  145. BIN com/rim/samples/device/mediaenginedemo/Images/sun_ray03_png_copy_img_1_4.png
  146. BIN com/rim/samples/device/mediaenginedemo/Images/sun_ray04_png_copy_img_1_4.png
  147. BIN com/rim/samples/device/mediaenginedemo/Images/sunny_png_copy_4_img_1_4.png
  148. BIN com/rim/samples/device/mediaenginedemo/Images/sunny_png_copy_5_img_1_4.png
  149. BIN com/rim/samples/device/mediaenginedemo/Images/sunny_png_copy_6_img_1_4.png
  150. BIN com/rim/samples/device/mediaenginedemo/Images/t2_copy_img_1_4.png
  151. BIN com/rim/samples/device/mediaenginedemo/Images/t3_copy_img_1_4.png
  152. BIN com/rim/samples/device/mediaenginedemo/Images/t4_copy_img_1_4.png
  153. BIN com/rim/samples/device/mediaenginedemo/Images/tBK_copy_img_1_4.png
  154. BIN com/rim/samples/device/mediaenginedemo/Images/tnotch_copy_img_1_4.png
  155. BIN com/rim/samples/device/mediaenginedemo/Images/tree1_1_copy_img_1_4.png
  156. BIN com/rim/samples/device/mediaenginedemo/Images/tree1_2_copy_img_1_4.png
  157. BIN com/rim/samples/device/mediaenginedemo/Images/tree1_copy_img_1_4.png
  158. BIN com/rim/samples/device/mediaenginedemo/Images/tree2_1_copy_img_1_4.png
  159. BIN com/rim/samples/device/mediaenginedemo/Images/tree2_2_copy_img_1_4.png
  160. BIN com/rim/samples/device/mediaenginedemo/Images/tree2_copy_img_1_4.png
  161. BIN com/rim/samples/device/mediaenginedemo/Images/tree3_1_copy_img_1_4.png
  162. BIN com/rim/samples/device/mediaenginedemo/Images/tree3_2_copy_img_1_4.png
  163. BIN com/rim/samples/device/mediaenginedemo/Images/tree3_copy_img_1_4.png
  164. BIN com/rim/samples/device/mediaenginedemo/Images/tree4_copy_img_1_4.png
  165. BIN com/rim/samples/device/mediaenginedemo/Images/upper_cloud_png_copy_3_img_1_4.png
  166. +14 −16 com/rim/samples/device/mediaenginedemo/MediaEngineDemo.java
  167. +10 −56 com/rim/samples/device/mediaenginedemo/MediaEngineDemo.jdp
  168. +2 −2 com/rim/samples/device/mediaenginedemo/MediaListenerImpl.java
  169. 0 com/rim/samples/device/mediaenginedemo/{Images → img}/mediaengine_jde.png
  170. BIN com/rim/samples/device/mediaenginedemo/planets.pme
  171. +102 −0 com/rim/samples/device/mediaenginedemo/planets.svg
  172. BIN com/rim/samples/device/mediaenginedemo/runner.pme
  173. +2 −3 com/rim/samples/device/mediaenginedemo/runner.svg
  174. BIN com/rim/samples/device/mediaenginedemo/weather.pme
  175. +0 −962 com/rim/samples/device/mediaenginedemo/weather.svg
  176. +2 −0 com/rim/samples/device/memoapidemo/MemoAPIDemo.jdp
  177. +2 −0 com/rim/samples/device/memoapidemo/MemoAPIDemo_autostartup.jdp
  178. +1 −1 com/rim/samples/device/memoapidemo/MemoApiDemo.java
  179. +4 −4 com/rim/samples/device/memoapidemo/MemoController.java
  180. +0 −297 com/rim/samples/device/memorydemo/CustomerList.java
  181. +0 −123 com/rim/samples/device/memorydemo/CustomerRecord.java
  182. +0 −142 com/rim/samples/device/memorydemo/CustomerRecordController.java
  183. +14 −19 com/rim/samples/device/memorydemo/MemoryDemo.java
  184. +6 −4 com/rim/samples/device/memorydemo/MemoryDemo.jdp
  185. +0 −156 com/rim/samples/device/memorydemo/MemoryDemoCustomerScreen.java
Sorry, we could not display the entire diff because too many files (324) changed.
View
73 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo.java
@@ -30,6 +30,7 @@
import net.rim.blackberry.api.stringpattern.PatternRepository;
import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ApplicationManager;
+import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.ActiveAutoTextEditField;
import net.rim.device.api.ui.component.RichTextField;
@@ -45,7 +46,7 @@
* information corresponding to the matched pattern. This application also
* provides a GUI demo screen with an ActiveAutoTextEditField.
*/
-public class ActiveTextFieldsDemo extends UiApplication {
+class ActiveTextFieldsDemo extends UiApplication {
private static ApplicationMenuItem[] _menuItems =
new ApplicationMenuItem[2];
private RichTextField _trackingNumber;
@@ -113,7 +114,7 @@ else if (args[0].equals("pattern-recognized")) {
* Flag to indicate whether application was invoked explicitly
* from the desktop or by invoking a menu item.
*/
- ActiveTextFieldsDemo(final boolean isDemoApp) {
+ private ActiveTextFieldsDemo(final boolean isDemoApp) {
/*
* Display a MainScreen that simply allows user to type a 9 digit number
@@ -150,7 +151,7 @@ else if (args[0].equals("pattern-recognized")) {
* world situation the application would send the highlighted transaction
* number back to a server and retrieve the status and location information.
*/
- static ApplicationMenuItem statusItem = new ApplicationMenuItem(0) {
+ private static ApplicationMenuItem statusItem = new ApplicationMenuItem(0) {
/**
* Sets the label and text in the display fields of the handler screen.
@@ -160,12 +161,11 @@ else if (args[0].equals("pattern-recognized")) {
* displayed.
*/
public Object run(final Object context) {
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._trackingNumber
- .setLabel("Status for tracking No: ");
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._trackingNumber
- .setText(context.toString());
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._statusLocation
- .setText("< In Progress >");
+ final ActiveTextFieldsDemo app =
+ (ActiveTextFieldsDemo) UiApplication.getUiApplication();
+ app._trackingNumber.setLabel("Status for tracking No: ");
+ app._trackingNumber.setText(context.toString());
+ app._statusLocation.setText("< In Progress >");
return null;
}
@@ -174,37 +174,39 @@ public String toString() {
}
};
- static ApplicationMenuItem locationItem = new ApplicationMenuItem(1) {
- /**
- * Sets the label and text in the display fields of the handler screen.
- *
- * @param context
- * The String representation of the context object is
- * displayed.
- */
- public Object run(final Object context) {
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._trackingNumber
- .setLabel("Location for tracking No: ");
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._trackingNumber
- .setText(context.toString());
- ((ActiveTextFieldsDemo) UiApplication.getUiApplication())._statusLocation
- .setText("< 39.3° N 76.6° W >");
- return null;
- }
-
- public String toString() {
- return "Location";
- }
- };
+ private static ApplicationMenuItem locationItem =
+ new ApplicationMenuItem(1) {
+ /**
+ * Sets the label and text in the display fields of the handler
+ * screen.
+ *
+ * @param context
+ * The String representation of the context object is
+ * displayed.
+ */
+ public Object run(final Object context) {
+ final ActiveTextFieldsDemo app =
+ (ActiveTextFieldsDemo) UiApplication
+ .getUiApplication();
+ app._trackingNumber.setLabel("Location for tracking No: ");
+ app._trackingNumber.setText(context.toString());
+ app._statusLocation.setText("< 39.3° N 76.6° W >");
+ return null;
+ }
+
+ public String toString() {
+ return "Location";
+ }
+ };
/**
* The screen that is displayed when one of our application menu items is
* invoked.
*/
- final class HandlerScreen extends MainScreen {
+ private final class HandlerScreen extends MainScreen {
// Constructor
- public HandlerScreen() {
+ private HandlerScreen() {
// Set the screen title.
setTitle("Active Text Fields Handler");
@@ -223,13 +225,14 @@ public HandlerScreen() {
final class ActiveTextFieldsScreen extends MainScreen {
// Constructor
- public ActiveTextFieldsScreen() {
+ ActiveTextFieldsScreen() {
// Set the screen title.
setTitle("Active Text Fields Demo");
// Add instructions.
add(new RichTextField(
- "Type a nine digit number in the Transaction No. field. Pattern will be hyperlinked and status and location menu items will be available.\n"));
+ "Type a nine digit number in the Transaction No. field. Pattern will be hyperlinked and status and location menu items will be available.\n",
+ Field.NON_FOCUSABLE));
// Add an ActiveAutoTextEditField.
final ActiveAutoTextEditField activeField =
View
2 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo.jdp
@@ -41,3 +41,5 @@ StartupTier=7
SystemModule=0
Title=Active Text Fields Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
2 com/rim/samples/device/activetextfieldsdemo/ActiveTextFieldsDemo_autostartup.jdp
@@ -37,3 +37,5 @@ RunOnStartup=1
StartupTier=7
SystemModule=1
Type=3
+Vendor=Research In Motion Limited
+Version=0.9
View
60 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsDemo.java
@@ -34,6 +34,7 @@
import net.rim.blackberry.api.mail.Transport;
import net.rim.device.api.applicationcontrol.ApplicationPermissions;
import net.rim.device.api.applicationcontrol.ApplicationPermissionsManager;
+import net.rim.device.api.system.ApplicationDescriptor;
import net.rim.device.api.system.ControlledAccessException;
import net.rim.device.api.system.Device;
import net.rim.device.api.system.EventInjector;
@@ -45,7 +46,7 @@
/**
* This sample demonstrates the ApplicationPermissions API available in
- * BlackBerry v4.2.1 handheld software and higher. If the required permissions
+ * BlackBery v4.2.1 handheld software and higher. If the required permissions
* for this application have been denied by the user, the application will
* prompt for access to these resources. The ability to test these capabilities
* is provided as part of the sample.This sample needs to be run on a secure
@@ -55,7 +56,7 @@
* by this project signed with the Signature Tool. For more information on code
* signing please refer to the BlackBerry Signature Tool Development Guide.
*/
-public class ApplicationPermissionsDemo extends UiApplication implements
+class ApplicationPermissionsDemo extends UiApplication implements
FieldChangeListener {
private ButtonField _eventInjectorButton;
private ButtonField _phoneButton;
@@ -71,8 +72,10 @@ public static void main(final String[] args) {
sample.enterEventDispatcher();
}
- // Constructor
- public ApplicationPermissionsDemo() {
+ /**
+ * Constructor.
+ */
+ private ApplicationPermissionsDemo() {
checkPermissions();
showTestScreen();
}
@@ -93,25 +96,30 @@ private void checkPermissions() {
// --Phone
// --Device Settings
// --Email
- // The sample demonstrates how these user defined permissions will cause
- // the
- // respective tests to succeed or fail. Individual applications will
- // require
- // access to different permissions. Please review the Javadocs for the
- // ApplicationPermissions class for a list of all available permissions.
+ // The sample demonstrates how these user defined permissions will
+ // cause the respective tests to succeed or fail. Individual
+ // applications will require access to different permissions.
+ // Please review the Javadocs for the ApplicationPermissions class
+ // for a list of all available permissions
+ // May 13, 2008: updated permissions by replacing deprecated constants.
// Capture the current state of permissions and check against the
// requirements.
- final ApplicationPermissions original =
- ApplicationPermissionsManager.getInstance()
- .getApplicationPermissions();
+ final ApplicationPermissionsManager apm =
+ ApplicationPermissionsManager.getInstance();
+ final ApplicationPermissions original = apm.getApplicationPermissions();
+
+ // Set up and attach a reason provider
+ final DemoReasonProvider drp = new DemoReasonProvider();
+ apm.addReasonProvider(ApplicationDescriptor
+ .currentApplicationDescriptor(), drp);
if (original
- .getPermission(ApplicationPermissions.PERMISSION_EVENT_INJECTOR) == ApplicationPermissions.VALUE_ALLOW
+ .getPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION) == ApplicationPermissions.VALUE_ALLOW
&& original
.getPermission(ApplicationPermissions.PERMISSION_PHONE) == ApplicationPermissions.VALUE_ALLOW
&& original
- .getPermission(ApplicationPermissions.PERMISSION_CHANGE_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW
+ .getPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS) == ApplicationPermissions.VALUE_ALLOW
&& original
.getPermission(ApplicationPermissions.PERMISSION_EMAIL) == ApplicationPermissions.VALUE_ALLOW) {
// All of the necessary permissions are currently available.
@@ -127,10 +135,10 @@ private void checkPermissions() {
// Please only request the permissions needed for your application.
final ApplicationPermissions permRequest = new ApplicationPermissions();
permRequest
- .addPermission(ApplicationPermissions.PERMISSION_EVENT_INJECTOR);
+ .addPermission(ApplicationPermissions.PERMISSION_INPUT_SIMULATION);
permRequest.addPermission(ApplicationPermissions.PERMISSION_PHONE);
permRequest
- .addPermission(ApplicationPermissions.PERMISSION_CHANGE_DEVICE_SETTINGS);
+ .addPermission(ApplicationPermissions.PERMISSION_DEVICE_SETTINGS);
permRequest.addPermission(ApplicationPermissions.PERMISSION_EMAIL);
final boolean acceptance =
@@ -142,16 +150,12 @@ private void checkPermissions() {
return;
} else {
// The user has only accepted some or none of the permissions
- // requested. In this
- // sample, we will not perform any additional actions based on this
- // information.
- // However, there are several scenarios where this information could
- // be used.
- // For example, if the user denied networking capabilities then the
- // application
+ // requested. In this sample, we will not perform any additional
+ // actions based on this information. However, there are several
+ // scenarios where this information could be used. For example,
+ // if the user denied networking capabilities then the application
// could disable that functionality if it was not core to the
- // operation of the
- // application.
+ // operation of the application.
}
}
@@ -253,10 +257,10 @@ public void fieldChanged(final Field field, final int context) {
testEmail();
}
- Dialog.inform("Test Successful");
+ Dialog.inform("Test successful.");
} catch (final ControlledAccessException e) {
// Do not have access to the API. Indicate as such.
- Dialog.inform("Test Failed");
+ Dialog.inform("Test failed!");
}
}
}
View
5 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsDemo.jdp
@@ -19,6 +19,7 @@ ExcludeFromBuildAll=0
[Files
ApplicationPermissionsDemo.java
ApplicationPermissionsScreen.java
+DemoReasonProvider.java
img\apppermissions_jde.png
]
HaveAlxImports=0
@@ -37,8 +38,12 @@ OutputFileName=ApplicationPermissionsDemo
[PackageProtection
]
RibbonPosition=0
+[RolloverIcons
+]
RunOnStartup=0
StartupTier=7
SystemModule=0
Title=Application Permissions Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
4 com/rim/samples/device/applicationpermissionsdemo/ApplicationPermissionsScreen.java
@@ -32,8 +32,8 @@
* An implementation of the MainScreen class which overrides certain
* functionality to provide an optimized user experience.
*/
-public class ApplicationPermissionsScreen extends MainScreen {
- public ApplicationPermissionsScreen() {
+class ApplicationPermissionsScreen extends MainScreen {
+ ApplicationPermissionsScreen() {
super();
}
View
83 com/rim/samples/device/applicationpermissionsdemo/DemoReasonProvider.java
@@ -0,0 +1,83 @@
+/*
+ * DemoReasonProvider.java
+ *
+ * Copyright © 1998-2011 Research In Motion Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Note: For the sake of simplicity, this sample application may not leverage
+ * resource bundles and resource strings. However, it is STRONGLY recommended
+ * that application developers make use of the localization features available
+ * within the BlackBerry development platform to ensure a seamless application
+ * experience across a variety of languages and geographies. For more information
+ * on localizing your application, please refer to the BlackBerry Java Development
+ * Environment Development Guide associated with this release.
+ */
+
+package com.rim.samples.device.applicationpermissionsdemo;
+
+import net.rim.device.api.applicationcontrol.ApplicationPermissions;
+import net.rim.device.api.applicationcontrol.ReasonProvider;
+
+/**
+ * This class implements the ReasonProvider interface in order to provide
+ * detailed permission request messages for the user.
+ *
+ * To test ReasonProvider functionality, when prompted, set the demo's
+ * application permissions to "prompt" and then run those tests. When the pop-up
+ * asking for permission appears, click "Details from the vendor..." to view
+ * your messages. The messages will only appear when access is being requested.
+ *
+ */
+class DemoReasonProvider implements ReasonProvider {
+
+ /**
+ * Gets the message of this listener according to the type of permission.
+ * Must be implemented for this interface.
+ *
+ * @param permissionID
+ * : the ID of the permission requested. Must be in the class
+ * net.rim.device.api.applicationcontrol.ApplicationPermissions
+ * @return The string to be displayed.
+ * @see net.rim.device.api.applicationcontrol.ReasonProvider#getMessage(int)
+ */
+ public String getMessage(final int permissionID) {
+
+ // General message for other permissions
+ String message =
+ "ReasonProviderDemo recieved permissionID: " + permissionID;
+
+ // Set specific messages for specific permission IDs
+ switch (permissionID) {
+
+ case ApplicationPermissions.PERMISSION_INPUT_SIMULATION:
+ message = "Sample message for PERMISSION_INPUT_SIMULATION";
+ break;
+
+ case ApplicationPermissions.PERMISSION_PHONE:
+ message = "Sample message for PERMISSION_PHONE";
+ break;
+
+ case ApplicationPermissions.PERMISSION_DEVICE_SETTINGS:
+ message = "Sample message for PERMISSION_DEVICE_SETTINGS";
+ break;
+
+ case ApplicationPermissions.PERMISSION_EMAIL:
+ message = "Sample message for PERMISSION_EMAIL";
+ break;
+ }
+
+ return message;
+ }
+
+}
View
3 com/rim/samples/device/blackberry/browser/BrowserContentManagerDemo.java
@@ -98,8 +98,7 @@ private BrowserContentManagerDemo() {
thread.start();
}
- public void
- processConnection(final HttpConnection connection, final Event e) {
+ void processConnection(final HttpConnection connection, final Event e) {
// Cancel previous request.
if (_currentConnection != null) {
try {
View
2 com/rim/samples/device/blackberry/browser/BrowserContentManagerDemo.jdp
@@ -47,3 +47,5 @@ StartupTier=7
SystemModule=0
Title=Browser Content Manager Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
5 com/rim/samples/device/blackberry/browser/BrowserFieldDemo.java
@@ -47,7 +47,7 @@
import net.rim.device.api.ui.component.Status;
import net.rim.device.api.ui.container.MainScreen;
-final public class BrowserFieldDemo extends UiApplication implements
+final class BrowserFieldDemo extends UiApplication implements
RenderingApplication {
private static final String REFERER = "referer";
@@ -81,8 +81,7 @@ private BrowserFieldDemo() {
}
- public void
- processConnection(final HttpConnection connection, final Event e) {
+ void processConnection(final HttpConnection connection, final Event e) {
// Cancel previous request.
if (_currentConnection != null) {
try {
View
2 com/rim/samples/device/blackberry/browser/BrowserPlugin.java
@@ -47,7 +47,7 @@
* To test the plugin - create a file with xxxtest extension and associate that
* type with application/x-vnd.rim.xxxtest mime type on any web server.
*/
-public final class BrowserPlugin extends BrowserContentProvider implements
+final class BrowserPlugin extends BrowserContentProvider implements
BrowserPageContext {
private static final String[] ACCEPT = { "application/x-vnd.rim.xxxtest" };
View
2 com/rim/samples/device/blackberry/browser/BrowserPlugin.jdp
@@ -44,3 +44,5 @@ RunOnStartup=1
StartupTier=7
SystemModule=0
Type=2
+Vendor=Research In Motion Limited
+Version=0.9
View
2 com/rim/samples/device/blackberry/browser/CommonLib.jdp
@@ -44,3 +44,5 @@ RunOnStartup=0
StartupTier=7
SystemModule=0
Type=2
+Vendor=Research In Motion Limited
+Version=0.9
View
4 com/rim/samples/device/blackberry/browser/SecondaryResourceFetchThread.java
@@ -68,7 +68,7 @@
* @param referrer
* - call back browsr field.
*/
- public static void enqueue(final RequestedResource resource,
+ static void enqueue(final RequestedResource resource,
final BrowserContent referrer) {
if (resource == null) {
return;
@@ -111,7 +111,7 @@ private SecondaryResourceFetchThread() {
/**
* Indicate that all images have been enqueued for this browser field.
*/
- public static void doneAddingImages() {
+ static void doneAddingImages() {
synchronized (_syncObject) {
if (_currentThread != null) {
_currentThread._done = true;
View
4 com/rim/samples/device/blackberry/browser/Utilities.java
@@ -36,9 +36,9 @@
import net.rim.device.api.io.http.HttpProtocolConstants;
import net.rim.device.api.util.StringUtilities;
-public class Utilities {
+class Utilities {
- public static HttpConnection makeConnection(final String url,
+ static HttpConnection makeConnection(final String url,
final HttpHeaders requestHeaders, final byte[] postData) {
HttpConnection conn = null;
OutputStream out = null;
View
2 com/rim/samples/device/blackberry/options/OptionsProviderDemo.jdp
@@ -44,3 +44,5 @@ RunOnStartup=1
StartupTier=7
SystemModule=0
Type=2
+Vendor=Research In Motion Limited
+Version=0.9
View
2 com/rim/samples/device/blackberry/pim/PIMDemo.jdp
@@ -51,3 +51,5 @@ StartupTier=7
SystemModule=0
Title=PIM Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
18 com/rim/samples/device/blackberrymapsdemo/BlackBerryMapsDemo.java
@@ -51,7 +51,7 @@ public static void main(final String[] args) {
/**
* Constructor
*/
- public BlackBerryMapsDemo() {
+ private BlackBerryMapsDemo() {
final BlackBerryMapsDemoScreen screen = new BlackBerryMapsDemoScreen();
pushScreen(screen);
}
@@ -65,14 +65,13 @@ public BlackBerryMapsDemo() {
BlackBerryMapsDemo _app;
- public BlackBerryMapsDemoScreen() {
+ BlackBerryMapsDemoScreen() {
setTitle("BlackBerry Maps Demo");
_app = (BlackBerryMapsDemo) UiApplication.getUiApplication();
final RichTextField rtf =
- new RichTextField(
- "Select an option from the menu.\n\nNOTE: Using BlackBerry Maps within the BlackBerry simulator requires the MDS simulator to be running.",
+ new RichTextField("Select an option from the menu.",
Field.NON_FOCUSABLE);
add(rtf);
@@ -89,7 +88,8 @@ public BlackBerryMapsDemoScreen() {
/**
* Displays an InvokeContactScreen.
*/
- MenuItem invokeContactItem = new MenuItem("Invoke Contact", 0, 0) {
+ private final MenuItem invokeContactItem = new MenuItem("Invoke Contact",
+ 0, 0) {
public void run() {
final InvokeContactScreen invokeContactScreen =
new InvokeContactScreen();
@@ -100,7 +100,8 @@ public void run() {
/**
* Displays an InvokeDefaultScreen.
*/
- MenuItem invokeDefaultItem = new MenuItem("Invoke Default", 0, 0) {
+ private final MenuItem invokeDefaultItem = new MenuItem("Invoke Default",
+ 0, 0) {
public void run() {
final InvokeDefaultScreen invokeDefaultScreen =
new InvokeDefaultScreen();
@@ -111,7 +112,7 @@ public void run() {
/**
* Displays an InvokeLocationDocumentScreen.
*/
- MenuItem invokeLocationDocumentItem = new MenuItem(
+ private final MenuItem invokeLocationDocumentItem = new MenuItem(
"Invoke Location Document", 0, 0) {
public void run() {
final InvokeLocationDocumentScreen invokeLocationDocumentScreen =
@@ -123,7 +124,8 @@ public void run() {
/**
* Displays an InvokeMapViewScreen.
*/
- MenuItem invokeMapViewItem = new MenuItem("Invoke Map View", 0, 0) {
+ private final MenuItem invokeMapViewItem = new MenuItem("Invoke Map View",
+ 0, 0) {
public void run() {
final InvokeMapViewScreen invokeMapViewScreen =
new InvokeMapViewScreen();
View
2 com/rim/samples/device/blackberrymapsdemo/BlackBerryMapsDemo.jdp
@@ -44,3 +44,5 @@ StartupTier=7
SystemModule=0
Title=BlackBerry Maps Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
4 com/rim/samples/device/blackberrymapsdemo/InvokeContactScreen.java
@@ -51,7 +51,7 @@
/**
* Constructor
*/
- public InvokeContactScreen() {
+ InvokeContactScreen() {
setTitle("Invoke Contact");
final LabelField instructions =
@@ -65,7 +65,7 @@ public InvokeContactScreen() {
/**
* Displays a map based on an address from the address book.
*/
- MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
+ private final MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
/**
* Run() method creates a list of Contacts from the address book and
* searches list for first occurrence of a valid address.
View
4 com/rim/samples/device/blackberrymapsdemo/InvokeDefaultScreen.java
@@ -44,7 +44,7 @@
/**
* Constructor
*/
- public InvokeDefaultScreen() {
+ InvokeDefaultScreen() {
setTitle("Invoke Default");
final LabelField instructions =
@@ -58,7 +58,7 @@ public InvokeDefaultScreen() {
/**
* Displays the default map.
*/
- MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
+ private final MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
// Invoke maps application with default map.
public void run() {
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments());
View
53 com/rim/samples/device/blackberrymapsdemo/InvokeLocationDocumentScreen.java
@@ -45,7 +45,7 @@
/**
* Constructor
*/
- public InvokeLocationDocumentScreen() {
+ InvokeLocationDocumentScreen() {
setTitle("Invoke Location Document");
final RichTextField instructions =
@@ -62,10 +62,11 @@ public InvokeLocationDocumentScreen() {
/**
* Displays a single location on a map.
*/
- MenuItem viewSingleItem = new MenuItem("View Single Location", 1000, 10) {
+ private final MenuItem viewSingleItem = new MenuItem(
+ "View Single Location", 1000, 10) {
public void run() {
final String document =
- "<location-document><location lon='-7938675' lat='4367022' label='Toronto, ON' description='Go Leafs Go!' zoom='10'/></location-document>";
+ "<location-document><lbs clear='ALL'/><location lon='-7938675' lat='4367022' label='Toronto, ON' description='Go Leafs Go!' zoom='10'/></location-document>";
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(
MapsArguments.ARG_LOCATION_DOCUMENT, document));
@@ -75,34 +76,42 @@ public void run() {
/**
* Displays multiple locations on a map.
*/
- MenuItem viewMultipleItem = new MenuItem("View Multiple Locations", 2000,
- 10) {
+ private final MenuItem viewMultipleItem = new MenuItem(
+ "View Multiple Locations", 2000, 10) {
public void run() {
- final String document =
- "<location-document>"
- + "<location lon='-8030000' lat='4326000' label='Kitchener, ON' description='Kitchener, Ontario, Canada' />"
- + "<location lon='-7569792' lat='4542349' label='Ottawa, ON' description='Ottawa, Ontario, Canada' />"
- + "</location-document>";
+ final StringBuffer stringBuffer =
+ new StringBuffer("<location-document>");
+ stringBuffer
+ .append("<location lon='-8030000' lat='4326000' label='Kitchener, ON' description='Kitchener, Ontario, Canada' />");
+ stringBuffer
+ .append("<location lon='-7569792' lat='4542349' label='Ottawa, ON' description='Ottawa, Ontario, Canada' />");
+ stringBuffer.append("</location-document>");
Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(
- MapsArguments.ARG_LOCATION_DOCUMENT, document));
+ MapsArguments.ARG_LOCATION_DOCUMENT, stringBuffer
+ .toString()));
}
};
/**
* Displays a route between locations on a map.
*/
- MenuItem viewRouteItem = new MenuItem("View Route", 3000, 10) {
- public void run() {
- final String document =
- "<location-document><GetRoute>"
- + "<location lon='-8030000' lat='4326000' label='Kitchener, ON' description='Kitchener, Ontario, Canada' />"
- + "<location lon='-7569792' lat='4542349' label='Ottawa, ON' description='Ottawa, Ontario, Canada' />"
- + "</GetRoute></location-document>";
+ private final MenuItem viewRouteItem =
+ new MenuItem("View Route", 3000, 10) {
+ public void run() {
+ final StringBuffer stringBuffer =
+ new StringBuffer("<location-document><GetRoute>");
+ stringBuffer
+ .append("<location lon='-8030000' lat='4326000' label='Kitchener, ON' description='Kitchener, Ontario, Canada' />");
+ stringBuffer
+ .append("<location lon='-7569792' lat='4542349' label='Ottawa, ON' description='Ottawa, Ontario, Canada' />");
+ stringBuffer.append("</GetRoute></location-document>");
- Invoke.invokeApplication(Invoke.APP_TYPE_MAPS, new MapsArguments(
- MapsArguments.ARG_LOCATION_DOCUMENT, document));
- }
- };
+ Invoke.invokeApplication(Invoke.APP_TYPE_MAPS,
+ new MapsArguments(
+ MapsArguments.ARG_LOCATION_DOCUMENT,
+ stringBuffer.toString()));
+ }
+ };
}
View
4 com/rim/samples/device/blackberrymapsdemo/InvokeMapViewScreen.java
@@ -42,7 +42,7 @@
/**
* Constructor
*/
- public InvokeMapViewScreen() {
+ InvokeMapViewScreen() {
setTitle("Invoke Map View");
final LabelField instructions =
@@ -56,7 +56,7 @@ public InvokeMapViewScreen() {
/**
* Invokes BlackBerry Maps application using a MapView object.
*/
- MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
+ private final MenuItem viewMapItem = new MenuItem("View Map", 1000, 10) {
public void run() {
final MapView mapview = new MapView();
mapview.setLatitude(4542349);
View
2 com/rim/samples/device/bluetoothdemo/AppScreen.java
@@ -37,7 +37,7 @@
private BluetoothSerialPortInfo[] _portInfo;
- public AppScreen() {
+ AppScreen() {
setTitle("Bluetooth Sample");
// Determine if this BlackBerry model or simulator supports Bluetooth.
View
2 com/rim/samples/device/bluetoothdemo/BluetoothDemo.java
@@ -28,7 +28,7 @@
import net.rim.device.api.ui.UiApplication;
-public class BluetoothDemo extends UiApplication {
+class BluetoothDemo extends UiApplication {
public static void main(final String[] args) {
final BluetoothDemo app = new BluetoothDemo();
app.enterEventDispatcher();
View
9 com/rim/samples/device/bluetoothdemo/BluetoothDemo.jdp
@@ -1,5 +1,9 @@
## RIM Java Development Environment
# RIM Project file
+#
+# This file is generated and managed by BlackBerry developer tools.
+# It SHOULD NOT BE modified manually.
+#
AddOn=0
AlwaysBuild=0
[AlxImports
@@ -24,6 +28,7 @@ ExcludeFromBuildAll=0
AppScreen.java
BluetoothDemo.java
img\bluetooth_jde.png
+readme.txt
SSPScreen.java
]
HaveAlxImports=0
@@ -43,8 +48,12 @@ OutputFileName=BluetoothDemo
[PackageProtection
]
RibbonPosition=0
+[RolloverIcons
+]
RunOnStartup=0
StartupTier=7
SystemModule=0
Title=Bluetooth Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
2 com/rim/samples/device/bluetoothdemo/SSPScreen.java
@@ -53,7 +53,7 @@
private String _deviceName;
private final DataBuffer _db;
- public SPPScreen(final BluetoothSerialPortInfo info) {
+ SPPScreen(final BluetoothSerialPortInfo info) {
// Fill a 1k array with the a character.
Arrays.fill(_receiveBuffer, (byte) 'a');
View
34 com/rim/samples/device/bluetoothdemo/readme.txt
@@ -10,17 +10,19 @@ Pairing with another BlackBerry device
Note : The following instructions demonstrate how to initiate the connection from BlackBerry 'A' :
-3) Launch the BluetoothDemo sample on BlackBerry 'B', and select "Listen for connections" from the menu.
+3) On BlackBerry 'B', select Options > Bluetooth, and make sure that the Discoverable field is set to 'Yes'.
-4) On BlackBerry 'A', select Options > Bluetooth.
+4) Launch the BluetoothDemo sample on BlackBerry 'B', and select "Listen for connections" from the menu.
-5) Pair BlackBerry 'A' with BlackBerry 'B'.
+5) On BlackBerry 'A', select Options > Bluetooth.
-6) Launch the BluetoothDemo sample on BlackBerry 'A' and initiate the connection by selecting "Connect to <BlackBerry 'B' device name>" from the menu.
+6) Pair BlackBerry 'A' with BlackBerry 'B'.
-7) On BlackBerry 'B', accept the connection request.
+7) Launch the BluetoothDemo sample on BlackBerry 'A' and initiate the connection by selecting "Connect to <BlackBerry 'B' device name>" from the menu.
-8) Type away. Characters typed on BlackBerry 'A' should appear on BlackBerry 'B' and characters typed in BlackBerry 'B' should appear on BlackBerry 'A'.
+8) On BlackBerry 'B', accept the connection request.
+
+9) Type away. Characters typed on BlackBerry 'A' should appear on BlackBerry 'B' and characters typed in BlackBerry 'B' should appear on BlackBerry 'A'.
You can also select various options in the menu to change the serial port state.
@@ -41,17 +43,19 @@ Perform one of the following procedures:
If using a server side connection (i.e. the computer initiates the connection)
-------------------------------------------------------------------------------
-1) Launch the BluetoothDemo sample on the BlackBerry device, and select "Listen for connections" from the menu.
+1) On the BlackBerry device, select Options > Bluetooth, and make sure that the Discoverable field is set to 'Yes'.
+
+2) Launch the BluetoothDemo sample on the BlackBerry device, and select "Listen for connections" from the menu.
-2) Pair the computer with the BlackBerry device. For more information, please refer to the following article:
+3) Pair the computer with the BlackBerry device. For more information, please refer to the following article:
http://www.blackberry.com/btsc/articles/835/KB04132_f.SAL_Public.html#Task%204
-3) From Start/Settings/Control Panel/Bluetooth Devices/COM Ports tab, take note of the outgoing COM Port that was added when the computer was paired with the BlackBerry device (will appear as "Hi there").
+4) From Start/Settings/Control Panel/Bluetooth Devices/COM Ports tab, take note of the outgoing COM Port that was added when the computer was paired with the BlackBerry device (will appear as "Hi there").
-4) Make sure that the sample is running and listening for connections on the BlackBerry device.
+5) Make sure that the sample is running and listening for connections on the BlackBerry device.
-5) Create a new connection using HyperTerminal specifying the (outgoing) COM port that the Bluetooth connection is using.
+6) Create a new connection using HyperTerminal specifying the (outgoing) COM port that the Bluetooth connection is using.
To create a connection in HyperTerminal, please complete the following steps :
a. Select Start > Programs > Accessories > Communications > Hyper Terminal.
@@ -60,11 +64,11 @@ To create a connection in HyperTerminal, please complete the following steps :
c. In the next pop-up window, choose the COM port for the Bluetooth connection from the drop-down list of "Connect using:".
-6) Open the connection to the port (if it is not already opened).
+7) Open the connection to the port (if it is not already opened).
-7) On the BlackBerry device, accept the connection request.
+8) On the BlackBerry device, accept the connection request.
-8) Type away. Characters typed on the BlackBerry should appear in HyperTerminal and characters typed in HyperTerminal should appear on the BlackBerry device. You can also select various options in the menu to change the serial port state.
+9) Type away. Characters typed on the BlackBerry should appear in HyperTerminal and characters typed in HyperTerminal should appear on the BlackBerry device. You can also select various options in the menu to change the serial port state.
If using a client side connection (i.e. the BlackBerry device initiates the connection)
@@ -81,7 +85,7 @@ To create a connection in HyperTerminal, please complete the following steps :
2) Open the connection to the port (if it is not already opened).
-3) Pair the BlackBerry device with the computer. For more information, please refer to the following article:
+3) Pair the BlackBerry device with the computer (make sure that the BlackBerry device is discoverable before pairing). For more information, please refer to the following article:
http://www.blackberry.com/btsc/articles/835/KB04132_f.SAL_Public.html#Task%204
View
4 com/rim/samples/device/bluetoothserialportdemo/BluetoothSerialPortDemo.java
@@ -51,7 +51,7 @@
* The client side of a simple serial port demonstration app. This application
* will listen for text on the serial port and render the data when it arrives.
*/
-public class BluetoothSerialPortDemo extends UiApplication {
+class BluetoothSerialPortDemo extends UiApplication {
// Statics
// ------------------------------------------------------------------
private static final int INSERT = 1;
@@ -118,7 +118,7 @@ public static void main(final String[] args) {
// Constructor
// ---------------------------------------------------------------
- public BluetoothSerialPortDemo() {
+ private BluetoothSerialPortDemo() {
final BluetoothDemoScreen mainScreen = new BluetoothDemoScreen();
mainScreen.setTitle(new LabelField("Bluetooth Serial Port Demo",
Field.USE_ALL_WIDTH));
View
2 com/rim/samples/device/bluetoothserialportdemo/BluetoothSerialPortDemo.jdp
@@ -46,3 +46,5 @@ StartupTier=7
SystemModule=0
Title=Bluetooth Serial Port Demo
Type=0
+Vendor=Research In Motion Limited
+Version=0.9
View
353 com/rim/samples/device/bufferedplaybackdemo/BufferedPlayback.java
@@ -0,0 +1,353 @@
+/*
+ * BufferedPlayback.java
+ *
+ * Copyright © 1998-2011 Research In Motion Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Note: For the sake of simplicity, this sample application may not leverage
+ * resource bundles and resource strings. However, it is STRONGLY recommended
+ * that application developers make use of the localization features available
+ * within the BlackBerry development platform to ensure a seamless application
+ * experience across a variety of languages and geographies. For more information
+ * on localizing your application, please refer to the BlackBerry Java Development
+ * Environment Development Guide associated with this release.
+ */
+
+package com.rim.samples.device.bufferedplaybackdemo;
+
+import javax.microedition.media.Manager;
+import javax.microedition.media.Player;
+
+import net.rim.device.api.ui.Field;
+import net.rim.device.api.ui.FieldChangeListener;
+import net.rim.device.api.ui.UiApplication;
+import net.rim.device.api.ui.component.BasicEditField;
+import net.rim.device.api.ui.component.ButtonField;
+import net.rim.device.api.ui.component.Dialog;
+import net.rim.device.api.ui.component.TextField;
+import net.rim.device.api.ui.container.HorizontalFieldManager;
+import net.rim.device.api.ui.container.MainScreen;
+
+/**
+ * Provides a GUI interface for buffered media playback from a remotely streamed
+ * source.
+ */
+public final class BufferedPlayback extends UiApplication {
+ /**
+ * Entry point for the application.
+ *
+ * @param args
+ * Not used.
+ */
+ public static void main(final String[] args) {
+ final BufferedPlayback app = new BufferedPlayback();
+ app.enterEventDispatcher();
+ }
+
+ /**
+ * Creates the main screen and pushes it.
+ */
+ BufferedPlayback() {
+ final BufferedPlaybackScreen screen = new BufferedPlaybackScreen();
+ pushScreen(screen);
+ }
+
+ /**
+ * The main screen of the application.
+ */
+ private static final class BufferedPlaybackScreen extends MainScreen
+ implements FieldChangeListener {
+ /** A field used to enter the URL of the remote media file. */
+ private final BasicEditField _urlField;
+
+ /** A field used to enter the MIME type of the remote media file. */
+ private final BasicEditField _mimeField;
+
+ /**
+ * A field used to display the number of bytes that have been loaded.
+ */
+ private final TextField _loadStatusField;
+
+ /** A field used to display the current status of the media player. */
+ private final TextField _playStatusField;
+
+ /**
+ * A field which contains the minimum number of bytes that must be
+ * buffered before the media file will begin playing.
+ */
+ private final BasicEditField _startBufferField;
+
+ /**
+ * A field which contains the minimum forward byte buffer which must be
+ * maintained in order for the video to keep playing. If the forward
+ * buffer falls below this number, the playback will pause until the
+ * buffer increases.
+ */
+ private final BasicEditField _pauseBytesField;
+
+ /**
+ * A field which contains the minimum forward byte buffer required to
+ * resume playback after a pause.
+ */
+ private final BasicEditField _resumeBytesField;
+
+ /** A field which contains the maximum byte size of a single read. */
+ private final BasicEditField _readLimitField;
+
+ /** A button which starts the HTTP request and media playback. */
+ private final ButtonField _startPlayingButton;
+
+ /** A button which stops the HTTP request and media playback. */
+ private final ButtonField _stopPlayingButton;
+
+ /** A button which erases current request and playback progress. */
+ private final ButtonField _resetField;
+
+ /** A stream for the resource we are retrieving. */
+ private LimitedRateStreamingSource _source;
+
+ /** A player for the media stream. */
+ private Player _player;
+
+ /** A thread which creates and starts the Player. */
+ private PlayerThread _playerThread;
+
+ /**
+ * Constructor, creates the GUI.
+ */
+ BufferedPlaybackScreen() {
+ // Set the title of the window.
+ setTitle("Buffered Playback Demo");
+
+ // Create and add the field for the URL to be retrieved.
+ _urlField = new BasicEditField("Media URL: ", "");
+ add(_urlField);
+
+ // Create and add the field for the MIME type of the remote file.
+ _mimeField =
+ new BasicEditField("Mime: ", "audio/mpeg", 10,
+ Field.NON_FOCUSABLE);
+ add(_mimeField);
+
+ // Create the START, STOP and RESET buttons.
+ _startPlayingButton =
+ new ButtonField("Play", ButtonField.CONSUME_CLICK);
+ _stopPlayingButton =
+ new ButtonField("Stop", ButtonField.CONSUME_CLICK);
+ _resetField = new ButtonField("Reset", ButtonField.CONSUME_CLICK);
+ _startPlayingButton.setChangeListener(this);
+ _stopPlayingButton.setChangeListener(this);
+ _resetField.setChangeListener(this);
+
+ // Add the player control buttons to the screen.
+ final HorizontalFieldManager buttonlist =
+ new HorizontalFieldManager();
+ buttonlist.add(_startPlayingButton);
+ buttonlist.add(_stopPlayingButton);
+ buttonlist.add(_resetField);
+ add(buttonlist);
+
+ // Create and add the field with the load progress.
+ _loadStatusField =
+ new TextField("Load: ", "0 Bytes", 10, Field.NON_FOCUSABLE);
+ add(_loadStatusField);
+
+ // Create and add the field with the player status.
+ _playStatusField =
+ new TextField("Play: ", "Stopped", 10, Field.NON_FOCUSABLE);
+ add(_playStatusField);
+
+ // Create and add the field with the starting buffer.
+ _startBufferField =
+ new BasicEditField("Starting Buffer: ", "200000", 10,
+ BasicEditField.FILTER_INTEGER | Field.NON_FOCUSABLE);
+ add(_startBufferField);
+
+ // Create and add the field with the minimum pause buffer.
+ _pauseBytesField =
+ new BasicEditField("Pause At: ", "64000", 10,
+ BasicEditField.FILTER_INTEGER | Field.NON_FOCUSABLE);
+ add(_pauseBytesField);
+
+ // Create and add the field with the minimum resume buffer.
+ _resumeBytesField =
+ new BasicEditField("Resume At: ", "128000", 10,
+ BasicEditField.FILTER_INTEGER | Field.NON_FOCUSABLE);
+ add(_resumeBytesField);
+
+ // Create and add the field with the read limit.
+ _readLimitField =
+ new BasicEditField("Read Limit: ", "32000", 10,
+ BasicEditField.FILTER_INTEGER | Field.NON_FOCUSABLE);
+ add(_readLimitField);
+ }
+
+ /**
+ * A common listener for all three player controls.
+ *
+ * @param field
+ * The field that changed.
+ * @param context
+ * Information specifying the origin of the change.
+ */
+ public void fieldChanged(final Field field, final int context) {
+ try {
+ // If the START button was pressed, begin playback.
+ if (field == _startPlayingButton) {
+ // The player does not exist, we must initialize it.
+ if (_player == null) {
+ // Create a stream using the remote file.
+ _source =
+ new LimitedRateStreamingSource(_urlField
+ .getText());
+
+ // Set the attributes of the stream using the
+ // information from the GUI fields.
+ _source.setContentType(_mimeField.getText());
+ _source.setStartBuffer(Integer
+ .parseInt(_startBufferField.getText()));
+ _source.setReadLimit(Integer.parseInt(_readLimitField
+ .getText()));
+ _source.setResumeBytes(Integer
+ .parseInt(_resumeBytesField.getText()));
+ _source.setPauseBytes(Integer.parseInt(_pauseBytesField
+ .getText()));
+ _source.setLoadStatus(_loadStatusField);
+ _source.setPlayStatus(_playStatusField);
+
+ // Acquire the UI lock.
+ UiApplication.getUiApplication().invokeLater(
+ new Runnable() {
+ public void run() {
+ // Update the player status.
+ _playStatusField.setText("Started");
+ }
+ });
+
+ // Create and run the player's thread.
+ _playerThread = new PlayerThread();
+ _playerThread.start();
+ }
+ // The player already exists, simply resume it.
+ else {
+ _player.start();
+ }
+ }
+ // If the STOP button was pressed:
+ else if (field == _stopPlayingButton) {
+ // Acquire the UI lock.
+ UiApplication.getUiApplication().invokeLater(
+ new Runnable() {
+ public void run() {
+ // Update the status fields.
+ _playStatusField.setText("Stopped");
+ }
+ });
+
+ if (_player != null) {
+ // Stop the player.
+ _player.stop();
+ }
+ }
+ // If the RESET button was pressed:
+ else if (field == _resetField) {
+ // Acquire the UI lock.
+ UiApplication.getUiApplication().invokeLater(
+ new Runnable() {
+ public void run() {
+ // Update the status fields.
+ _loadStatusField.setText("0 Bytes");
+ _playStatusField.setText("Stopped");
+ }
+ });
+
+ // Destroy the Player and streams.
+ destroy();
+ }
+ } catch (final Exception e) {
+ System.err.println(e.getMessage());
+ }
+
+ }
+
+ /**
+ * Called when the application exits, ensures that all attributes are
+ * destroyed correctly.
+ */
+ public void close() {
+ try {
+ // Destroy the Player and streams.
+ destroy();
+ } catch (final Exception e) {
+ System.err.println(e.getMessage());
+ } finally {
+ super.close();
+ System.exit(0);
+ }
+ }
+
+ /**
+ * Prevent the save dialog from being displayed.
+ *
+ * @see net.rim.device.api.ui.container.MainScreen#onSavePrompt()
+ */
+ public boolean onSavePrompt() {
+ return true;
+ }
+
+ /**
+ * Destroy the Player and streams.
+ *
+ * @throws Exception
+ */
+ private void destroy() throws Exception {
+ // Destroy the player.
+ if (_player != null) {
+ _player.stop();
+ _player = null;
+ }
+
+ // Destroy the stream.
+ if (_source != null) {
+ _source.stop();
+ _source.disconnect();
+ _source = null;
+ }
+ }
+
+ /**
+ * A thread for the media player.
+ */
+ private class PlayerThread extends Thread {
+ /**
+ * Create and start the player.
+ */
+ public void run() {
+ try {
+ _player = Manager.createPlayer(_source);
+ _player.start();
+ } catch (final Exception e) {
+ // Acquire the UI lock.
+ UiApplication.getUiApplication().invokeLater(
+ new Runnable() {
+ public void run() {
+ _playStatusField.setText("Stopped");
+ Dialog.alert("Error: " + e.getMessage());
+ }
+ });
+ }
+ }
+ }
+ }
+}
View
708 com/rim/samples/device/bufferedplaybackdemo/LimitedRateStreamingSource.java
@@ -0,0 +1,708 @@
+/*
+ * LimitedRateStreaminSource.java
+ *
+ * Copyright © 1998-2011 Research In Motion Limited
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Note: For the sake of simplicity, this sample application may not leverage
+ * resource bundles and resource strings. However, it is STRONGLY recommended
+ * that application developers make use of the localization features available
+ * within the BlackBerry development platform to ensure a seamless application
+ * experience across a variety of languages and geographies. For more information
+ * on localizing your application, please refer to the BlackBerry Java Development
+ * Environment Development Guide associated with this release.
+ */
+
+package com.rim.samples.device.bufferedplaybackdemo;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import javax.microedition.io.Connector;
+import javax.microedition.io.ContentConnection;
+import javax.microedition.io.file.FileConnection;
+import javax.microedition.media.Control;
+import javax.microedition.media.protocol.ContentDescriptor;
+import javax.microedition.media.protocol.DataSource;
+import javax.microedition.media.protocol.SourceStream;
+
+import net.rim.device.api.io.SharedInputStream;
+import net.rim.device.api.system.Application;
+import net.rim.device.api.ui.component.TextField;
+
+/**
+ * The data source used by the BufferedPlayback's media player.
+ */
+public final class LimitedRateStreamingSource extends DataSource {
+ /** The max size to be read from the stream at one time. */
+ private static final int READ_CHUNK = 512; // bytes
+
+ /** A reference to the field which displays the load status. */
+ private TextField _loadStatusField;
+
+ /** A reference to the field which displays the player status. */
+ private TextField _playStatusField;
+
+ /**
+ * The minimum number of bytes that must be buffered before the media file
+ * will begin playing.
+ */
+ private int _startBuffer = 200000;
+
+ /** The maximum size (in bytes) of a single read. */
+ private int _readLimit = 32000;
+
+ /**
+ * The minimum forward byte buffer which must be maintained in order for the
+ * video to keep playing. If the forward buffer falls below this number, the
+ * playback will pause until the buffer increases.
+ */
+ private int _pauseBytes = 64000;
+
+ /**
+ * The minimum forward byte buffer required to resume playback after a
+ * pause.
+ */
+ private int _resumeBytes = 128000;
+
+ /** The stream connection over which media content is passed. */
+ private ContentConnection _contentConnection;
+
+ /** An input stream shared between several readers. */
+ private SharedInputStream _readAhead;
+
+ /** A stream to the buffered resource. */
+ private LimitedRateSourceStream _feedToPlayer;
+
+ /** The MIME type of the remote media file. */
+ private String _forcedContentType;
+
+ /** A counter for the total number of buffered bytes */
+ private volatile int _totalRead;
+
+ /** A flag used to tell the connection thread to stop */
+ private volatile boolean _stop;
+
+ /**
+ * A flag used to indicate that the initial buffering is complete. In other
+ * words, that the current buffer is larger than the defined start buffer
+ * size.
+ */
+ private volatile boolean _bufferingComplete;
+
+ /** A flag used to indicate that the remote file download is complete. */
+ private volatile boolean _downloadComplete;
+
+ /** The thread which retrieves the remote media file. */
+ private ConnectionThread _loaderThread;
+
+ /** The local save file into which the remote file is written. */
+ private FileConnection _saveFile;
+
+ /** A stream for the local save file. */
+ private OutputStream _saveStream;
+
+ /**
+ * Constructor.
+ *
+ * @param locator
+ * The locator that describes the DataSource.
+ */
+ LimitedRateStreamingSource(final String locator) {
+ super(locator);
+ }
+
+ /**
+ * Open a connection to the locator.
+ *
+ * @throws IOException
+ */
+ public void connect() throws IOException {
+ // Open the connection to the remote file.
+ _contentConnection =
+ (ContentConnection) Connector
+ .open(getLocator(), Connector.READ);
+
+ // Cache a reference to the locator.
+ final String locator = getLocator();
+
+ // Report status.
+ System.out.println("Loading: " + locator);
+ System.out.println("Size: " + _contentConnection.getLength());
+
+ // The name of the remote file begins after the last forward slash.
+ final int filenameStart = locator.lastIndexOf('/');
+
+ // The file name ends at the first instance of a semicolon.
+ int paramStart = locator.indexOf(';');
+
+ // If there is no semicolon, the file name ends at the end of the line.
+ if (paramStart < 0) {
+ paramStart = locator.length();
+ }
+
+ // Extract the file name.
+ final String filename = locator.substring(filenameStart, paramStart);
+ System.out.println("Filename: " + filename);
+
+ // Open a local save file with the same name as the remote file.
+ _saveFile =
+ (FileConnection) Connector.open(
+ "file:///SDCard/blackberry/music" + filename,
+ Connector.READ_WRITE);
+
+ // If the file doesn't already exist, create it.
+ if (!_saveFile.exists()) {
+ _saveFile.create();
+ }
+
+ // Open the file for writing.
+ _saveFile.setReadable(true);
+
+ // Open a shared input stream to the local save file to
+ // allow many simultaneous readers.
+ final SharedInputStream fileStream =
+ SharedInputStream.getSharedInputStream(_saveFile
+ .openInputStream());
+
+ // Begin reading at the beginning of the file.
+ fileStream.setCurrentPosition(0);
+
+ // If the local file is smaller than the remote file...
+ if (_saveFile.fileSize() < _contentConnection.getLength()) {
+ // Did not get the entire file, set the system to try again.
+ _saveFile.setWritable(true);
+
+ // A non-null save stream is used as a flag later to indicate that
+ // the file download was incomplete.
+ _saveStream = _saveFile.openOutputStream();
+
+ // Use a new shared input stream for buffered reading.
+ _readAhead =
+ SharedInputStream.getSharedInputStream(_contentConnection
+ .openInputStream());
+ } else {
+ // The download is complete.
+ _downloadComplete = true;
+
+ // We can use the initial input stream to read the buffered media.
+ _readAhead = fileStream;
+
+ // We can close the remote connection.
+ _contentConnection.close();
+ }
+
+ if (_forcedContentType != null) {
+ // Use the user-defined content type if it is set.
+ _feedToPlayer =
+ new LimitedRateSourceStream(_readAhead, _forcedContentType);
+ } else {
+ // Otherwise, use the MIME types of the remote file.
+ _feedToPlayer =
+ new LimitedRateSourceStream(_readAhead, _contentConnection
+ .getType());
+ }
+ }
+
+ /**
+ * Destroy and close all existing connections.
+ */
+ public void disconnect() {
+ try {
+ if (_saveStream != null) {
+ // Destroy the stream to the local save file.
+ _saveStream.close();
+ _saveStream = null;
+ }
+
+ // Close the local save file.
+ _saveFile.close();
+
+ if (_readAhead != null) {
+ // Close the reader stream.
+ _readAhead.close();
+ _readAhead = null;
+ }
+
+ // Close the remote file connection.
+ _contentConnection.close();
+
+ // Close the stream to the player.
+ _feedToPlayer.close();
+ } catch (final Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
+
+ /**
+ * Returns the content type of the remote file.
+ *
+ * @return The content type of the remote file.
+ */
+ public String getContentType() {
+ return _feedToPlayer.getContentDescriptor().getContentType();
+ }
+
+ /**
+ * Returns a stream to the buffered resource.
+ *
+ * @return A stream to the buffered resource.
+ */
+ public SourceStream[] getStreams() {
+ return new SourceStream[] { _feedToPlayer };
+ }
+
+ /**
+ * Starts the connection thread used to download the remote file.
+ */
+ public void start() throws IOException {
+ // If the save stream is null, we have already completely downloaded
+ // the file.
+ if (_saveStream != null) {
+ // Open the connection thread to finish downloading the file.
+ _loaderThread = new ConnectionThread();
+ _loaderThread.start();
+ }
+ }
+
+ /**
+ * Stop the connection thread.
+ */
+ public void stop() throws IOException {
+ // Set the boolean flag to stop the thread.
+ _stop = true;
+ }
+
+ /**
+ * @see javax.microedition.media.Controllable#getControl(String)
+ */
+ public Control getControl(final String controlType) {
+ // No implemented Controls.
+ return null;
+ }
+
+ /**
+ * @see javax.microedition.media.Controllable#getControls()
+ */
+ public Control[] getControls() {
+ // No implemented Controls.
+ return null;
+ }
+
+ /**
+ * Force the lower level stream to a given content type. Must be called
+ * before the connect function in order to work.
+ *
+ * @param contentType
+ * The content type to use.
+ */
+ void setContentType(final String contentType) {
+ _forcedContentType = contentType;
+ }
+
+ /**
+ * A stream to the buffered media resource.
+ */
+ private final class LimitedRateSourceStream implements SourceStream {
+ /** A stream to the local copy of the remote resource. */
+ private final SharedInputStream _baseSharedStream;
+
+ /** Describes the content type of the media file. */
+ private final ContentDescriptor _contentDescriptor;
+
+ /**
+ * Constructor. Creates a LimitedRateSourceStream from the given
+ * InputStream.
+ *
+ * @param inputStream
+ * The input stream used to create a new reader.
+ * @param contentType
+ * The content type of the remote file.
+ */
+ LimitedRateSourceStream(final InputStream inputStream,
+ final String contentType) {
+ _baseSharedStream =
+ SharedInputStream.getSharedInputStream(inputStream);
+ _contentDescriptor = new ContentDescriptor(contentType);
+ }
+
+ /**
+ * Returns the content descriptor for this stream.
+ *
+ * @return The content descriptor for this stream.
+ */
+ public ContentDescriptor getContentDescriptor() {
+ return _contentDescriptor;
+ }
+
+ /**
+ * Returns the length provided by the connection.
+ *
+ * @return long The length provided by the connection.
+ */
+ public long getContentLength() {
+ return _contentConnection.getLength();
+ }
+
+ /**
+ * Returns the seek type of the stream.
+ */
+ public int getSeekType() {
+ return SEEKABLE_TO_START;
+ }
+
+ /**
+ * Returns the maximum size (in bytes) of a single read.
+ */
+ public int getTransferSize() {
+ return _readLimit;
+ }
+
+ /**
+ * Writes bytes from the buffer into a byte array for playback.
+ *
+ * @param bytes
+ * The buffer into which the data is read.
+ * @param off
+ * The start offset in array b at which the data is written.
+ * @param len
+ * The maximum number of bytes to read.
+ * @return the total number of bytes read into the buffer, or -1 if
+ * there is no more data because the end of the stream has been
+ * reached.
+ * @throws IOException
+ */
+ public int read(final byte[] bytes, final int off, final int len)
+ throws IOException {
+ System.out.println("Read Request for: " + len + " bytes");
+
+ // Limit bytes read to our readLimit.
+ int readLength = len;
+ if (readLength > getReadLimit()) {
+ readLength = getReadLimit();
+ }
+
+ // The number of available byes in the buffer.
+ int available;
+
+ // A boolean flag indicating that the thread should pause
+ // until the buffer has increased sufficiently.
+ boolean paused = false;
+
+ for (;;) {
+ available = _baseSharedStream.available();
+
+ if (_downloadComplete) {
+ // Ignore all restrictions if downloading is complete.
+ System.out.println("Complete, Reading: " + len
+ + " - Available: " + available);
+ return _baseSharedStream.read(bytes, off, len);
+ } else if (_bufferingComplete) {
+ if (paused && available > getResumeBytes()) {
+ // If the video is paused due to buffering, but the
+ // number of available byes is sufficiently high,
+ // resume playback of the media.
+ System.out
+ .println("Resuming - Available: " + available);
+ updatePlayStatus("Resuming " + available + " Bytes");
+ paused = false;
+ return _baseSharedStream.read(bytes, off, readLength);
+ } else if (!paused
+ && (available > getPauseBytes() || available > readLength)) {
+ // We have enough information for this media playback.
+
+ if (available < getPauseBytes()) {
+ // If the buffer is now insufficient, set the
+ // pause flag.
+ paused = true;
+ updatePlayStatus("Pausing " + available + " Bytes");
+ }
+
+ System.out.println("Reading: " + readLength
+ + " - Available: " + available);
+ return _baseSharedStream.read(bytes, off, readLength);
+ } else if (!paused) {
+ // Set pause until loaded enough to resume.
+ paused = true;
+ updatePlayStatus("Pausing " + available + " Bytes");
+ }
+ } else {
+ // We are not ready to start yet, try sleeping to allow the
+ // buffer to increase.
+ try {
+ Thread.sleep(500);
+ } catch (final Exception e) {
+ System.err.println(e.getMessage());
+ }
+ }
+ }
+ }
+
+ /**
+ * @see javax.microedition.media.protocol.SourceStream#seek(long)
+ */
+ public long seek(final long where) throws IOException {
+ _baseSharedStream.setCurrentPosition((int) where);
+ return _baseSharedStream.getCurrentPosition();
+ }
+
+ /**
+ * @see javax.microedition.media.protocol.SourceStream#tell()
+ */
+ public long tell() {
+ return _baseSharedStream.getCurrentPosition();
+ }
+
+ /**
+ * Close the stream.