Blackberry: limit app to portrait mode - blackberry

I've tried this piece of code in my UiApplication class, but I get an illegalstatexception.
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
I dont want my app to change its orientation. I want it to stay in portrait mode.
EDIT:
How it is used:
public class HelloWorld extends UiApplication {
public static void main(String[] args){
Ui.getUiEngineInstance().setAcceptableDirections(Display.DIRECTION_PORTRAIT);
HelloWorld theapp = new HelloWorld();
theapp.enterEventDispatcher();
}
public HelloWorld(){
pushScreen(new FeaturedScreen());
}
}

DemoClass()
{
int direction = Display.DIRECTION_PORTRAIT;
Ui.getUiEngineInstance().setAcceptableDirections(direction);
pushScreen(new AppScreen(this));
}
public static void main(String[] args) {
DemoClass app1 = new DemoClass();
app1.enterEventDispatcher();
}

public class HelloWorld extends UiApplication {
public static void main(String[] args){
UiEngineInstance ui = Ui.getUiEngineInstance();//I have added this new line in your code
ui.setAcceptableDirections(Display.DIRECTION_NORTH);
HelloWorld theapp = new HelloWorld();
theapp.enterEventDispatcher();
}
public HelloWorld(){
pushScreen(new FeaturedScreen());
}
}

Related

Blackberry global popup

I'm trying to popup a global dialog from a background thread that I started from an alternate entry point.
public static void main(String[] args) {
MyApp theApp = new MyApp();
if (args != null && args.length > 0 && args[0].equals("test")) {
new Thread(new Runnable() {
public void run() {
try {
synchronized (UiApplication.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "Test", Dialog.OK,
Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_MODAL);
}
} catch (Exception e) {
System.out.println(e.toString());
}
}
}).start();
} else {
theApp.enterEventDispatcher();
}
}
I tried so many variations to make it work but it's still not showing up. I tried
synchronizing Application.getEventLock(), I also tried
UiApplication.getUiApplication().invokeLater,
UiApplication.getUiApplication().invokeAndWait. I even tried synchronizing the eventlock first before calling the invokeLater (which I think is redundant, but I still tried...). I'm not sure what I'm doing wrong.
okk i am giving you a sample demo ....
First of all edit the BlackBerry_App_Descriptor.xml click on Application Tab
In ApplicationArgument write alternate and check Auto Run on start up
Click on Alternate Entry Points click on add and write in the title BackgroundApp
Make a class which will extend Application class rather than UiApplication class like this way
import net.rim.device.api.system.Alert;
import net.rim.device.api.system.Application;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.Screen;
import net.rim.device.api.ui.Ui;
import net.rim.device.api.ui.UiEngine;
import net.rim.device.api.ui.component.Dialog;
public class BackGroundApp extends Application {
// this class is used for the background processing .....
public void startBackgroundThread()
{
new Thread(){
public void run() {
while (true) {
try {
Thread.sleep(60000);
} catch (InterruptedException e) {
e.printStackTrace();
}
synchronized (getEventLock()) {
//with this UiEngine pushGlobal dialogs
//whenever with the app in background
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "You have updates!",
Dialog.OK, Bitmap
.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}
}
}
}.start();
}
}
Make a class which will extend UiApplication class like this way
public class GuiTest extends UiApplication {
static Timer t;
public static void main(String[] args) {
if(args.length>0&&"alternate".equals(args[0])){
BackGroundApp app = new BackGroundApp();
app.startBackgroundThread();
app.enterEventDispatcher();
}
else{
GuiTest test = new GuiTest();
test.enterEventDispatcher();
}
}
public GuiTest(){
Myscreen screeMyscreen = new Myscreen();
pushScreen(screeMyscreen);
}
}
Now make a class MyScreen and add all your Ui in it .... and push the screen
public class Myscreen extends MainScreen {
public Myscreen(){
CreateGui();
}
public void CreateGui(){
// Your Ui goes here .......
}
}
run the sample you will see after one minute a dialog will appear on your screen no matter if you are in the application or out side of it. Thanks may be this might be help full.

put the application blackberry multilang (different languages)

I want to make my application Blackberry in different languages. That mean I use english as default language and then when the user select other language, all the items and all the application will be with the other language. I use this code and I put the file Local.rrc and .rrh in the same package. I obtain nothing in my screen just white screen. Can any one help me ?
package mypackage;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.i18n.*;
public class Local extends UiApplication {
public static void main(String[] args) {
Local theApp = new Local();
theApp.enterEventDispatcher();
}
public Local() {
pushScreen(new LocalScreen());
}
}
final class LocalScreen extends MainScreen implements LocalDemoResource {
private static ResourceBundle res =
ResourceBundle.getBundle(BUNDLE_ID, BUNDLE_NAME);
LabelField title;
RichTextField rtf;
public LocalScreen() {
super();
title = new LabelField(res.getString(FIELD_TITLE),LabelField.ELLIPSIS| LabelField.USE_ALL_WIDTH);
setTitle(title);
rtf = new RichTextField(res.getString(MESSAGE));
add(rtf); }
public void HelloWorldScreen()
{
LabelField title = new LabelField("HelloWorld Sample",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new RichTextField("Hello World!"));
}
public boolean onClose() {
Dialog.alert(res.getString(GOODBYE));
System.exit(0);
return true;
}
protected void makeMenu(Menu menu, int instance) {
menu.add(_english);
menu.add(_french);
menu.add(_spanish);
menu.add(_close);
}
private MenuItem _close = new MenuItem(res.getString(CLOSE), 110, 10) {
public void run() {
onClose();
}
};
private MenuItem _english = new MenuItem(res.getString(ENGLISH), 110, 10)
{
public void run() {
Locale.setDefault (Locale.get(Locale.LOCALE_en, null));
refresh();
}
};
private MenuItem _french = new MenuItem(res.getString(FRENCH), 110, 10) {
public void run() {
Locale.setDefault (Locale.get(Locale.LOCALE_fr, null));
refresh();
}
};
private MenuItem _spanish = new MenuItem(res.getString(SPANISH), 110, 10)
{
public void run() {
Locale.setDefault (Locale.get(Locale.LOCALE_es, null));
refresh();
}
};
private void refresh() {
title.setText(res.getString(FIELD_TITLE));
deleteAll();
rtf = new RichTextField(res.getString(MESSAGE));
add(rtf);
_english.setText(res.getString(ENGLISH));
_french.setText(res.getString(FRENCH));
_spanish.setText(res.getString(SPANISH));
_close.setText(res.getString(CLOSE));
}
}
There is an example import--->import blackberry samples---->LocalizationDemo explain how to use multilang in application blackberry

Blackberry: display Alert/Status/Dialog early and exit

Let's say I have a typical Blackberry app:
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
and already at the beginning I notice, that a mandatory condition is missing (wrong Display dimensions; missing SD card; some IT policy; etc.)
Is there a way to display a short and quick message to the user (in the form of Alert/Status/Dialog/whatever) and exit straight away - without/before instantiating a complex Screen/registering Acceleration listeners/installing complex CleanupRunnable?
I've tried Status.show(), Dialog.alert() - they do not work (RuntimeException "pushModalScreen called by a non-event thread"):
public class MyScreen extends MainScreen {
public MyScreen() {
if (Display.getWidth() < 400) {
Status.show("Goodbye");
return;
}
}
}
Instead of direct invocation use invokeLater. Sample is below:
Application.getApplication().invokeLater(new Runnable() {
public void run() {
Dialog.inform("Your message here...");
}
});
Instead of Dialog.inform you may use Status.show()
Actually the following is better, than what's suggested by Rafael - because it doesn't have the ugly white screen underneath. Here is my complete example MyApp.java:
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.image.*;
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp app = new MyApp();
app.enterEventDispatcher();
}
public MyApp() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen implements DialogClosedListener {
Dialog myDialog = new Dialog(Dialog.OK, "Goodbye!", 0, Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION), Dialog.GLOBAL_STATUS);
public MyScreen() {
// XXX just some condition, like wrong dimensions or IT policy
if (Display.getWidth() > 40) {
myDialog.setDialogClosedListener(this);
Application.getApplication().requestBackground();
Application.getApplication().invokeLater(new Runnable() {
public void run() {
myDialog.show();
}
});
return;
}
// XXX heavy stuff to be skipped
}
public void dialogClosed(Dialog dialog, int choice) {
if (dialog == myDialog) {
System.out.println("XXX exiting XXX");
System.exit(1);
}
}
}

How to configure your blackberry app works ok (works on simulator but not on smartphone)?

I wrote an app which has 2 screens. The first screen is triggered by the main class. The second screen is opened by clicking a button in the first screen.
public class MyApp extends UiApplication{
public static void main(String[] args){
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp(){
// Push a screen onto the UI stack for rendering.
pushScreen(new MyScreen());
}
}
public class MyScreen extends MainScreen implements FieldChangeListener
{
BasicEditField mEdit = null;
ButtonField mButton = null;
public MyScreen()
{
super();
mEdit = new BasicEditField("input: ", "some text");
add(mEdit);
mButton = new ButtonField("Go second screen");
mButton.setChangeListener(this);
add(mButton);
}
public void fieldChanged(Field field, int context)
{
if(mButton == field)
{
MyScreen2 scr = new MyScreen2();
scr.setTextValue(mEdit.getText());
UiApplication.getUiApplication().pushScreen(scr);
UiApplication.getUiApplication().popScreen(this);
}
}
}
public final class MyScreen2 extends MainScreen
{
String mTextValue = null;
LabelField mLabel = null;
public void setTextValue(String textValue)
{
mTextValue = textValue;
mLabel.setText(mTextValue);
}
public MyScreen2()
{
super();
mLabel = new LabelField();
add(mLabel);
}
}
It works on the 9700 simulator, but doesn't work on the smartphone. I wonder what is wrong? I wonder if the smartphone blocks loading app from my computer?
I tried signing .cod but nothing changes.
Any idea?
you need signing key to run your application on real device ... It cost near about 20 dollars
go here
you can find all the details from here
I think it might help you
cheers

Ui Applicatiopn class use in other class

(public class GPSDemo extends UiApplication) its a class name
i want to use this class in this code. i am make a object of this class but throw the exception
here is the place where we use it
popRunnable = new Runnable()
{
public void run()
{
/*StartUpScreen mainScreen = new StartUpScreen();
pushScreen(mainScreen); */
GPSDemo mainScreen =new GPSDemo();
// mainScreen.enterEventDispatcher();
//pushScreen(mainScreen);
}
};
who we use it
UiApplication and MainScreen are different things
public class Main extends UiApplication{
Main() {
pushScreen(new GPSDemo());
}
public static void main(String args[]) {
Main app = new Main();
app.enterEventDispatcher();
}
class GPSDemo extends MainScreen {
GPSDemo() {
this.setTitle("GPSDemo");
}
}

Resources