Blackberry MenuItem Deprecated - blackberry

I am trying to use the MenuItem class of BlackBerry JDE 6.0 and I am encountering an error "The constructor MenuItem String(String, int, int) is deprecated". I am implementing it using a subclass under the MainScreen class. below is the sample deprecated code:
public class UiFunMainScreen extends MainScreen{
class LoginMenuItem extends MenuItem {
public LoginMenuItem() {
super("Login", 20, 10);
}
public void run() {
login();
}
}
class ClearMenuItem extends MenuItem {
public ClearMenuItem() {
super("Clear", 10, 20);
}
public void run() {
clearTextFields();
}
}
}

Use following version of code to create a MenuItem:
class MyUiScreen extends MainScreen
{
public MyUiScreen()
{
MenuItem myItem = new MenuItem(
new StringProvider("My Menu Item"),
0x230000,
0
);
// rest of codes...
from the RIM BlackBerry API 6.0 Documentation
Creating menu items by subclassing and implementing Runnable
If subclassing the extending class must implement the Runnable interface, which in turn supports abstract dispatching of menu actions on activation.
...
// setup the menu items
MenuItem item = new MyMenuItem();
menu.addItem(item);
...
class MyMenuItem extends MenuItem {
MyMenuItem() {
super(MyResourceBundle.getBundle(), MyResource.MY_MENU_ITEM, 0x230000, 0);
}
public void run() {
// do something
}
}
Explore the API.

Related

How to explicitly access the Connector from Widget Side into Vaadin 7?

I create a Widget with his Server Side Class and the Client Side (Connector Class, ServerRPC Class, State Class and Widget Class).
Connector :
#Connect(Custom.class)
public class CustomConnector extends ButtonConnector {
...
public void myFunc() {
// DO Something
}
}
Widget :
public class CustomWidget extends VButton {
...
private CustomConnector conn = new CustomConnector();
public CustomWidget () {
conn.myFunc();
}
...
}
Now from the Widget Class i want to explicitly call/access the Connector Object, which are not a Singleton, so that i can access a function too. How can i solve it?
In my opinion you should not access connector directly from GWT widget. It is against Vaadin 7 architecture where GWT widgets are objects independent from vaadin at all.
However if we are talking about dirty migration from Vaadin 6 to 7 solution could be:
ComponentConnector connector = ConnectorMap.get(client).getConnector(CustomWidget.this); // client is taken from updateFromUIDL method (Vaadin6)
Better solution will be to add "state" listener to the widget
public interface CustomWidgetStateListener {
public void stateChanged();
}
public class CustomWidget extends VButton {
...
CustomWidgetStateListener listener;
public void addStateListener(CustomWidgetStateListener listener) {
this.listener = listener;
}
public void notifyStateChanged() { // You can call notifyStateChanged() whenever you want to notify connector
listener.stateChanged();
}
...
}
public class CustomConnector extends ButtonConnector {
public CustomConnector() {
getWidget().addStateListener(new CustomWidgetStateListener() {
public void stateChanged() {
myFunc();
}
});
}
...
public void myFunc() {
// DO Something
}
}

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

BlackBerry OS 6 Native Menu

Hi I am trying to create a global class for my Native Menu, but can seem to get it to load in my Screen Class, I want this to show up where ever I would like to show up.
Not sure if I am doing it right
Here is my MenuItems Class
public final class MenuItems extends MainScreen {
public void getMenuItems(){
MenuItem myItem = new MenuItem(new StringProvider("My Cards"), 0x230000, 0);
myItem.setCommandContext(new Object(){
public String toString(){
return "My Cards";
}
});
myItem.setCommand(new Command(new CommandHandler(){
public void execute(ReadOnlyCommandMetadata metadata, Object context){
// Do Something
}
}));
addMenuItem(myItem);
}
}
The Screen Class I want to add it to is this, not sure if how I would call it here, I tried creating a new instance and just fetching the get method, but no luck, but if I dump the code from the above class in to this class, it will work fine, but I don't want that.
public final class MobiScreen extends MainScreen {
ToolBar toolbar = new ToolBar();
Banner banner = new Banner("Welcome");
MenuItems myMenu = new MenuItems();
public MobiScreen()
{
setTitle(toolbar.getToolBar());
setBanner(banner.getBanner());
myMenu.getMenuItems();
}
}
Why not have MobiScreen extend your MenuItems class?
public class MobiScreen extends MenuItems { ... }

How disable widget?

I use GWT Editors framework for data binding.
I have next code:
AAAView.java
public interface AAAView extends Editor<AAA> {
public interface Presenter {
}
public interface Driver extends SimpleBeanEditorDriver<AAA, AAAViewImpl> {
}
void setPresenter(Presenter presenter);
Driver initializeDriver();
Widget asWidget();
}
AAAViewImpl.java
public class AAAViewImpl extends Composite implements AAAView {
interface AAAViewImplUiBinder extends UiBinder<Widget, AAAViewImpl> {
}
private static AAAViewImplUiBinder ourUiBinder = GWT.create(AAAViewImplUiBinder.class);
private Presenter presenter;
#UiField
ValueBoxEditorDecorator<String> firstName;
public AAAViewImpl() {
Widget rootElement = ourUiBinder.createAndBindUi(this);
initWidget(rootElement);
}
#Override
public void setPresenter(Presenter presenter) {
this.presenter = presenter;
}
#Override
public Driver initializeDriver() {
Driver driver = GWT.create(Driver.class);
driver.initialize(this);
return driver;
}
AAAViewImpl.ui.xml
<e:ValueBoxEditorDecorator ui:field="firstName">
<e:valuebox>
<g:TextBox maxLength="16" width="100%"/>
</e:valuebox>
</e:ValueBoxEditorDecorator>
How can I disable/enable firstName textbox in runtime?
Or how get access to the inner textbox of ValueBoxEditorDecorator object?
Anyone knows how to solve this problem? Thanks in advance.
Instead of setting the ui:field attribute on the ValueBoxEditorDecorator, set it on the inner TextBox. Then you can disable the TextBox by using:
firstName.setEnabled(false);

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