How to use Telugu font in blackberry application - blackberry

As I'm novice in Blackberry/Java development, I don't know how to use "telugu" font in my Blackberry application. Please give an example.
see the difference between three simulators
9300-OS6 not displaying
9790-os7 displays only in this device .
9900-os7 even OS7 it is not displaying.

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.component.*;
import java.util.*;
public class FontLoadingDemo extends UiApplication
{
public static void main(String[] args)
{
FontLoadingDemo app = new FontLoadingDemo();
app.enterEventDispatcher();
}
public FontLoadingDemo()
{
pushScreen(new FontLoadingDemoScreen());
}
}
class FontLoadingDemoScreen extends MainScreen
{
public FontLoadingDemoScreen()
{
setTitle("Font Loading Demo");
LabelField helloWorld = new LabelField("Hello World");
if (FontManager.getInstance().load("Myfont.ttf", "MyFont", FontManager.APPLICATION_FONT) == FontManager.SUCCESS)
{
try
{
FontFamily typeface = FontFamily.forName("MyFont");
Font myFont = typeface.getFont(Font.PLAIN, 50);
helloWorld.setFont(myFont);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
}
add(helloWorld);
}
}
Source: http://docs.blackberry.com/en/developers/deliverables/11958/Load_and_use_a_custom_font_899948_11.jsp

Related

Blackberry Browserfield example app not launching

I'm attempting to run a very simple Blackberry/Java application which implements the BrowserField class. When I launch it in the simulator it just hangs. When I launch it on my device nothing happens.
JRE: 7.0
Simulator: 4.0.0.141
package mypackage;
import net.rim.device.api.browser.field2.BrowserField;
import net.rim.device.api.browser.field2.BrowserFieldConfig;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
public class BrowserJazz extends UiApplication
{
public static void main(String[] args)
{
BrowserJazz app = new BrowserJazz();
app.enterEventDispatcher();
}
public void BrowserJazz()
{
pushScreen(new BrowserFieldDemoScreen());
}
}
class BrowserFieldDemoScreen extends MainScreen
{
public BrowserFieldDemoScreen()
{
BrowserFieldConfig myBrowserFieldConfig = new BrowserFieldConfig();
myBrowserFieldConfig.setProperty(BrowserFieldConfig.NAVIGATION_MODE,
BrowserFieldConfig.NAVIGATION_MODE_POINTER);
BrowserField browserField = new BrowserField(myBrowserFieldConfig);
/*BrowserFieldListener listener = new BrowserFieldListener() {
public void documentLoaded(BrowserField browserField) throws Exception
{
// the document has loaded, do something ...
Dialog.inform("PAGE LOADED!");
}
};*/
add(browserField);
//browserField.addListener( listener );
browserField.requestContent("http://www.google.com");
//browserField.addListener( listener );
}
}
Any ideas?
You are using "NAVIGATION_MODE_POINTER" which only support OS 5 and above as you can read from browserfield doc http://www.blackberry.com/developers/docs/5.0.0api/net/rim/device/api/browser/field2/BrowserFieldConfig.html#NAVIGATION_MODE_POINTER
and as you said you using an old simulator "Simulator: 4.0.0.141"

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);
}
}
}

Is it possible to strikethrough text in a LabelField?

I've been able to style a LabelField with bold, underlined and italic text, but I have yet to find a way to specify strikethrough text. I haven't been able to find any documentation that it's supported or any other examples where it's implemented. Is it possible to display text with a strikethrough effect in BlackBerry OS 4.6 or 4.7?
I think BB way is not to style components, but extend them - so the solution could be:
package mypackage;
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.*;
public class MyApp extends UiApplication {
public static void main(String[] args) {
MyApp myApp = new MyApp();
myApp.enterEventDispatcher();
}
public MyApp () {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
public MyScreen() {
LabelField myLabel = new LabelField("Strike me") {
protected void paint(Graphics g) {
super.paint(g);
int w = getFont().getAdvance(getText());
g.drawLine(0, getHeight()/2, w, getHeight()/2);
}
};
add(myLabel);
}
}
UPDATE: You could also use
Font f = g.getFont();
Font s = f.derive(Font.STRIKE_THROUGH);
g.setFont(s);

JVM exception in simple program

I am writing a small demo program to display a message box in to run in blackberry. As soon as I click the OK button on the dialog, it throws me a JVM Error 104, uncaught:runtimeexception. Any help please? Here is the code :
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class My_First_App extends UiApplication
{
public static void main(String[] args)
{
My_First_App theApp = new My_First_App();
theApp.enterEventDispatcher();
}
public My_First_App()
{
pushScreen(new My_First_AppScreen());
}
}
final class My_First_AppScreen extends MainScreen
{
public My_First_AppScreen()
{
super();
HorizontalFieldManager _fieldmanager;
_fieldmanager = new HorizontalFieldManager();
/* declare one label to how the application title */
LabelField applicationtitle = new LabelField("Demo",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
ButtonField _pairMe = new ButtonField("PairMe");
FieldChangeListener listenerPairMe = new FieldChangeListener() {
public void fieldChanged(Field field, int context){
Dialog.alert("You clicked the button!");
}
};
/*set the title*/
add(_fieldmanager);
setTitle(applicationtitle);
_fieldmanager.add(_pairMe);
_pairMe.setChangeListener(listenerPairMe);
}
public boolean onClose()
{
Dialog.alert("Goodbye!");
System.exit(0);
return true;
}
}
create a new workspace. It's related to Eclipse, not to your code

Blackberry how to display message in app if device got no internet connection?

I've just started with programming for the Blackberry device. I'm using version 5 of the API.
I'm building a very simple application which is just a browserfield. So far it's all working great. I can display my browserfield with the content I need.
The problem I'm having now is if the device doesn't have an active internet connection I get the ugly "Error requesting content for" message.
I would need to someone display my own message if the device doesn't have an active connection.
Something like "You need to have an active internet connection to use this application" with an Exit button which closes the app.
I've tried to find this for hours but no luck.
Hopefully it's something relatively easy so I can get help here.
Here's my code so far:
package com.mycompany.webview;
import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.container.*;
public class webview extends UiApplication
{
public static void main(String[] args)
{
webview app = new webview();
app.enterEventDispatcher();
}
public webview()
{
pushScreen(new webviewScreen());
}
}
class webviewScreen extends MainScreen
{
public webviewScreen()
{
BrowserField myBrowserField = new BrowserField();
add(myBrowserField);
myBrowserField.requestContent("http://www.google.com");
}
}
Would really appreciate some help please.
Thanks
I got it working.
If anyone else is wondering how it's done, this is how I did it:
package com.mycompany.webview;
import net.rim.device.api.browser.field2.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.CoverageInfo;
public class webview extends UiApplication
{
public static void main(String[] args)
{
webview app = new webview();
app.enterEventDispatcher();
}
public webview()
{
pushScreen(new webviewScreen());
}
}
class webviewScreen extends MainScreen
{
public webviewScreen()
{
if (CoverageInfo.isOutOfCoverage())
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
Dialog.alert("You need an active internet connection to use this application");
System.exit(0);
}
});
}
else
{
BrowserField myBrowserField = new BrowserField();
add(myBrowserField);
myBrowserField.requestContent("http://www.google.com");
}
}
}

Resources