This repository has been archived by the owner on Sep 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BlackBerry Samples for Java release 7.0.0.
An Open Source version of the samples as they were released with the 7.0.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
Showing
284 changed files
with
16,047 additions
and
4,808 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
com/rim/samples/device/augmentedrealitydemo/ARDemoCameraScreen.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* ARDemoCameraScreen.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.augmentedrealitydemo; | ||
|
||
import javax.microedition.media.Player; | ||
import javax.microedition.media.control.GUIControl; | ||
import javax.microedition.media.control.VideoControl; | ||
|
||
import net.rim.device.api.system.Display; | ||
import net.rim.device.api.ui.Field; | ||
import net.rim.device.api.ui.UiApplication; | ||
import net.rim.device.api.ui.component.Dialog; | ||
import net.rim.device.api.ui.component.RichTextField; | ||
import net.rim.device.api.ui.container.ComponentCanvas; | ||
import net.rim.device.api.ui.container.MainScreen; | ||
|
||
/** | ||
* MainScreen subclass for the Augmented Reality Demo application. This screen | ||
* positions a rotating 3D cube on top of the camera view finder. The cube | ||
* changes its axis of rotation when the orientation of the device changes. | ||
*/ | ||
public final class ARDemoCameraScreen extends MainScreen { | ||
private Field _cameraField; | ||
private Player _player; | ||
private DemoGLField _glField; | ||
private static final int GL_FIELD_HEIGHT = Display.getHeight() / 3; | ||
private static final int GL_FIELD_WIDTH = GL_FIELD_HEIGHT; | ||
private static final int GL_FRAME_RATE = 60; | ||
|
||
/** | ||
* Creates a new ARDemoCameraScreen object | ||
*/ | ||
public ARDemoCameraScreen() { | ||
// Set the title of the screen | ||
setTitle("Augmented Reality Demo"); | ||
|
||
// Initialize the camera object and camera field | ||
initializeCamera(); | ||
|
||
// If the camera field was constructed successfully, create the UI | ||
if (_cameraField != null) { | ||
// Add the camera field to a new ComponentCanvas | ||
final ComponentCanvas compCanvas = | ||
new ComponentCanvas(Display.getWidth(), Display.getHeight()); | ||
compCanvas.add(_cameraField, 0, 0); | ||
|
||
// Initialize GLField | ||
_glField = new DemoGLField(GL_FIELD_WIDTH, GL_FIELD_HEIGHT); | ||
_glField.setTargetFrameRate(GL_FRAME_RATE); | ||
|
||
// Add the GLField to the canvas | ||
compCanvas.add(_glField, 100, 100); | ||
|
||
// Add the ComponentCanvas to the screen | ||
add(compCanvas); | ||
} else { | ||
add(new RichTextField("Error connecting to camera")); | ||
} | ||
} | ||
|
||
/** | ||
* @see net.rim.device.api.ui.Screen#close() | ||
*/ | ||
public void close() { | ||
if (_player != null) { | ||
try { | ||
_player.close(); | ||
} catch (final Exception e) { | ||
} | ||
} | ||
|
||
_glField.cleanUp(); | ||
|
||
super.close(); | ||
} | ||
|
||
/** | ||
* Initializes the Player, VideoControl and camera field | ||
*/ | ||
private void initializeCamera() { | ||
try { | ||
// Create a player for the camera view finder | ||
_player = | ||
javax.microedition.media.Manager | ||
.createPlayer("capture://video"); | ||
|
||
// Set the player to the REALIZED state | ||
_player.realize(); | ||
|
||
// Get the video control | ||
final VideoControl videoControl = | ||
(VideoControl) _player.getControl("VideoControl"); | ||
|
||
if (videoControl != null) { | ||
// Create the video field as a GUI primitive | ||
_cameraField = | ||
(Field) videoControl.initDisplayMode( | ||
GUIControl.USE_GUI_PRIMITIVE, | ||
"net.rim.device.api.ui.Field"); | ||
videoControl.setDisplayFullScreen(true); | ||
videoControl.setVisible(true); | ||
} | ||
|
||
// Set the player to the STARTED state | ||
_player.start(); | ||
} catch (final Exception e) { | ||
UiApplication.getUiApplication().invokeLater(new Runnable() { | ||
public void run() { | ||
Dialog.alert("ERROR " + e.getClass() + ": " | ||
+ e.getMessage()); | ||
} | ||
}); | ||
} | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
com/rim/samples/device/augmentedrealitydemo/AugmentedRealityDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* AugmentedRealityDemo.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.augmentedrealitydemo; | ||
|
||
import net.rim.device.api.opengles.GLUtils; | ||
import net.rim.device.api.ui.UiApplication; | ||
import net.rim.device.api.ui.component.Dialog; | ||
|
||
/** | ||
* This application shows an example of overlaying a graphical object on a | ||
* surface backed field to create an augmented reality experience. The | ||
* application displays a spinning 3D cube object on top of the camera view | ||
* finder. The cube changes its axis of rotation when the orientation of the | ||
* device changes. | ||
*/ | ||
public final class AugmentedRealityDemo extends UiApplication { | ||
|
||
/** | ||
* Entry point for application | ||
* | ||
* @param args | ||
* Command line arguments (not used) | ||
*/ | ||
public static void main(final String[] args) { | ||
// Create a new instance of the application and make the currently | ||
// running thread the application's event dispatch thread. | ||
final AugmentedRealityDemo app = new AugmentedRealityDemo(); | ||
app.enterEventDispatcher(); | ||
} | ||
|
||
/** | ||
* Creates a new AugmentedRealityDemo object | ||
*/ | ||
public AugmentedRealityDemo() { | ||
// Check whether OpenGL is supported on the current BlackBerry | ||
// Smartphone | ||
if (GLUtils.isSupported()) { | ||
pushScreen(new ARDemoCameraScreen()); | ||
} else { | ||
UiApplication.getUiApplication().invokeLater(new Runnable() { | ||
public void run() { | ||
Dialog.alert("This device does not support OpenGL, exiting Augmented Reality Demo application..."); | ||
System.exit(0); | ||
} | ||
}); | ||
} | ||
} | ||
} |
Oops, something went wrong.