Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Storm Orientation with 4.2.1

[ Edited ]

I'll see if I can pull up something for you later but the basis (using Eclipse by the way) of it is:

 

Create a reference to the project in Eclipse. In 1.1.2, the cod files are copied into the deliverables folder for you (I used to have to do this manually).

 

Call UpdateJad utility to combine the library jad file with the main project jad.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Developer
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified

Re: Storm Orientation with 4.2.1

Jerome,

You will have to forgive me, this is my first BB/Java app. Coming from a C# world I understand libraries and adding references, I am just not sure how to do it with Eclipse/J2me

 

I have the same setup you do. Eclipse/plugin 1.1

 

Do I need to create a library or simply another BB project that outputs a cod file? I googled Java and J2ME library and not a whole lot comes up. I was thinking this would be the equivalent of a .dll file.

 

It would be great if you could post an example

 

Thanks

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Storm Orientation with 4.2.1

[ Edited ]

Not a problem. You need to create a new BlackBerry project.

 

When asked for a JRE, use the 4.7 or 5.0 JRE for this new project.

 

In your new project, create a new class that will hold your method or methods to perform the orientation lock. This project does not need a main or anything.

 

Right-click on the project > Properties > Project References

 

Check off your main project as a project reference.

 

You can now reference your class from the library project in this project but not directly. This is where Class.forName comes in.

 

 

// Load 4.7 library
try {
   Object lockClass = (Class.forName("package.path.to.your.lockclass")).newInstance();} catch (Exception e) {
   System.out.println("Library is not available");
}

 

 

In the code above, when the new class is initialized, it locks the current screen to landscape by calling the lock method in it's constructor.

 

It's not the exact code I used but it should get you going. The code that I used uses a base LIbraryInterface in a separate project with flags for different initializaiton parameters (which I thought was a bit complicated but works).

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Highlighted
Developer
Developer
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified

Re: Storm Orientation with 4.2.1

Hi Jerome,

So I am still struggling with this...

 

I made a new project in my workspace called Orientation (4.7.0) and added my main project as a reference.

 

There is one class in project Orientation (packaged in lock_orientation) called LockOrientation with only the constructor with the following code.

 

 

    public LockOrientation() { int directions = net.rim.device.api.system.Display.DIRECTION_NORTH; net.rim.device.api.ui.Ui.getUiEngineInstance().setAcceptableDirections(directions); }

 

 

In my main project I added the code

 

         // Load 4.7 library try { Object lockClass = (Class.forName("lock_orientation.LockOrientation")).newInstance();} catch (Exception e) { System.out.println(e.toString()); }

 

 I think this is where I am having problems... referencing the library correctly.. Am I needing to copy something somehwere? Is my package path wrong? I am not sure how to reference the package in my library project.

 

Thanks..

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: Storm Orientation with 4.2.1

You are going about it right. Now you actually have to load both CODs to your device or sim for testing. Once the COD is on the device it'll call the orientation lock as long as it can load it.

 

Try searching the forums for dynamic class load for some more examples. You are very close.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Developer
Developer
Posts: 46
Registered: ‎06-16-2009
My Device: Not Specified

Re: Storm Orientation with 4.2.1

Jerome,

Thank You, I finally got it...

 

The problem was I needed to add a reference to the library project from the main project as well as vice versa as you had suggested...