System requirements
Technical requirements
- Eclipse 3.5 classic
- 32-bit Windows® XP, Windows Vista™ or Windows 7 (Note: 64-bit versions require 32-bit Java and Eclipse)
- Monitor with a resolution of 1024 x 768 or higher
- PC with Intel® Pentium® 4 processor or compatible (2.5 GHz or higher, 2 GB RAM, 1.5 GB HD free)
- Java® SE Development Kit (JDK) 6, update 10 or later.
BlackBerry Java Plug-in for Eclipse Update Site
Using the BlackBerry® Java® Plug-in for Eclipse® update site, you can download and install Eclipse® update components directly into an Eclipse install.
Follow the installation instructions below to learn how to download the BlackBerry® Java® SDK v6.0
Installation instructions
If you’re using Java® 2 SDK, Standard Edition v6.0, obtain Update 16 of the Java 2 SDK v6.0 from the Sun Microsystems website before downloading the plug-in using the Eclipse Update Mechanism.- From the Help menu, select Install New Software to open the Install window.
- Click the Add button:
- In the Add Site dialog, type the URL http://www.blackberry.com/go/eclipseUpdate/3.5/java into the location text box and specify BlackBerry Java Plug-in Update Site in the name text box.
- Click the OK button, BlackBerry Update Site appears in the Available Software list.
- Select the BlackBerry Java Plug-in item and at least one BlackBerry Component Pack item you want to work on.
- Click the Next button.
- Click the Next button after reviewing the items to be installed (if the BlackBerry Java Plug-in for Eclipse was selected the first time, the BlackBerry Java SDK 5.0.0 is automatically selected if no other SDK was selected).
- Check the I accept the terms of the license agreement radio button after reviewing licenses.
- Click the Finish button to begin installation.
- Note: you'll need to enter your BlackBerry® Developer Zone login ID and password in an authentication dialog. Due to security policy, you may be authenticated multiple times. If you don’t have a BlackBerry Developer Zone login, register for access to the BlackBerry Developer Zone.
- After successfully downloading the files, you’ll be prompted to restart the Eclipse Platform. Choose to restart the platform.
Development Tools & Downloads
- Web development
- Themes and animated graphics
- Java® development
Simulators
- BlackBerry smartphone simulators
- Download the BlackBerry email and MDS services simulator package v4.1.4
Coding :
import java.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.system.AccelerometerSensor.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
/**
* This sample demonstrates the Accelerometer API. The DrawThread opens the
* accelerometer channel and periodically queries for the current data reading.
* The data is then used to apply corresponding force to a ball drawn on the
* screen.
*/
public final class AccelerometerDemo extends UiApplication
{
private AccelerometerDemoScreen _screen;
private DrawThread _thread;
private Bitmap _ball;
private int _ballWidth;
private int _ballHeight;
private int _x;
private int _y;
private float _xSpeed;
private float _ySpeed;
private Random _r;
private boolean _simulated;
private Channel _accChannel;
private short[] _xyz = new short[ 3 ];
private static final float G_NORM = 9.8066f / AccelerometerSensor.G_FORCE_VALUE;
private static final float TABLE_FRICTION = 0.98f;
private static final float BOUNCE_SLOWDOWN = 0.6f;
private static final int DEFAULT_ORIENTATION = Display.DIRECTION_NORTH;
private int _tick = 0;
/**
* Entry point for application.
* @param args Command line arguments (not used)
*/
public static void main( String[] args )
{
// Create a new instance of the application and make the currently
// running thread the application's event dispatch thread.
AccelerometerDemo app = new AccelerometerDemo();
app.enterEventDispatcher();
}
// Constructor
public AccelerometerDemo()
{
if( AccelerometerSensor.isSupported() )
{
// Initialize UI
_screen = new AccelerometerDemoScreen();
_screen.addMenuItem(_startMenuItem);
_screen.addMenuItem(_stopMenuItem);
pushScreen( _screen );
_ball = Bitmap.getBitmapResource( "img/ball.png" );
_r = new Random();
if( _ball != null ) {
_ballWidth = _ball.getWidth();
_ballHeight = _ball.getHeight();
}
// Prevent UI from rotating our screen.
Ui.getUiEngineInstance().setAcceptableDirections( DEFAULT_ORIENTATION );
}
else
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("This device does not support accelerometer.");
System.exit(0);
}
});
}
}
/**
* Calculates ball position.
* @param xAcc x axis acceleration
* @param yAcc y axis acceleration
*/
private void applyForce( int xAcc, int yAcc )
{
// Calculate new speed.
_xSpeed += xAcc * G_NORM;
_ySpeed += yAcc * G_NORM;
// Apply table friction.
_xSpeed *= TABLE_FRICTION;
_ySpeed *= TABLE_FRICTION;
// Move the ball.
_x += _xSpeed;
_y += _ySpeed;
if( _x < 0 )
{
_x = 0;
_xSpeed = -( _xSpeed * BOUNCE_SLOWDOWN );
}
else {
int screenWidth = _screen.getWidth();
if( _x > screenWidth - _ballWidth )
{
_x = screenWidth - _ballHeight;
_xSpeed = -( _xSpeed * BOUNCE_SLOWDOWN );
}
}
if( _y < 0 )
{
_y = 0;
_ySpeed = -( _ySpeed * BOUNCE_SLOWDOWN );
}
else {
int screenHeight = _screen.getHeight();
if( _y > screenHeight - _ballHeight )
{
_y = screenHeight - _ballHeight;
_ySpeed = -( _ySpeed * BOUNCE_SLOWDOWN );
}
}
}
/**
* A thread class to handle screen updates.
*/
private class DrawThread extends Thread
{
private boolean _running;
public void run()
{
_running = true;
// Start querying the accelerometer sensor.
openAccelerometerConnection();
while( _running )
{
_tick++;
// Get current acceleration.
readAcceleration();
// Apply force to the ball.
applyForce( -_xyz[ 0 ], _xyz[ 1 ] );
try
{
synchronized( this )
{
wait( 50 );
}
}
catch( InterruptedException e )
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("wait(long) threw InterruptedException");
}
});
}
if( !_running )
{
break;
}
_screen.invalidate();
}
// Stop querying the sensor to save battery charge.
closeAccelerometerConnection();
}
}
/**
* Opens the data channel.
*/
private void openAccelerometerConnection()
{
if( DeviceInfo.isSimulator() )
{
_simulated = true;
}
else
{
_accChannel = AccelerometerSensor.openRawDataChannel( AccelerometerDemo.this );
_simulated = false;
}
}
/**
* Gets the latest acceleromenter data.
*/
private void readAcceleration()
{
if( _simulated )
{
// Running in a simulator, simulate random.
if(_tick % 10 == 0)
{
_xyz[0] = (short) ( _r.nextInt( 400 ) - 200 );
_xyz[1] = (short) ( _r.nextInt( 400 ) - 200 );
}
}
else
{
// Real device, call the API for samples.
_accChannel.getLastAccelerationData( _xyz );
}
}
/**
* Closes the data channel.
*/
private void closeAccelerometerConnection()
{
if( _accChannel != null )
{
_accChannel.close();
_accChannel = null;
}
}
/**
* Menu item to start the ball moving.
*/
private MenuItem _startMenuItem = new MenuItem("Start" , 0, 0)
{
public void run()
{
if(_thread == null)
{
// Start drawing
_thread = new DrawThread();
_thread.start();
}
}
};
/**
* Menu item to stop the ball moving.
*/
private MenuItem _stopMenuItem = new MenuItem("Stop" , 0, 0)
{
public void run()
{
if( _thread!= null )
{
synchronized( _thread )
{
_thread._running = false;
_thread.notifyAll();
_thread = null;
}
}
}
};
/**
* A screen on which to display the ball.
*/
private class AccelerometerDemoScreen extends MainScreen
{
/**
* @see Screen#paint(Graphics)
*/
protected void paint( Graphics graphics )
{
if( _ball != null )
{
graphics.drawBitmap( _x, _y, _ballWidth, _ballHeight, _ball, 0, 0 );
}
}
/**
* @see Screen#onClose()
*/
public boolean onClose()
{
if( _thread != null )
{
synchronized( _thread )
{
_thread._running = false;
_thread.notifyAll();
}
Thread.yield();
}
return super.onClose();
}
}
}
Install the sample application
· On the taskbar, click Start > Programs > Research In Motion > BlackBerry JDE 4.7.0 > JDE.
· In the Add project to <workspace> dialog box, browse to the folder where you extracted the sample application.
Run the sample application
- In the workspace where you added the accelerometerdemo project, right-click accelerometerdemo.
- Click Build project.
- On the taskbar, click Start > Applications > Research in Motion > BlackBerry JDE 4.7.0 > Device Simulator.
- On the Home screen of the BlackBerry® Smartphone Simulator, click the Downloads folder.
- Click the accelerometerdemo icon.
- In the accelerometer sample application, press the Menu key.
No comments:
Post a Comment