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
ryandevore
Posts: 46
Registered: ‎07-12-2008

Custom Menu Drawing

I'm able to specify a global font for my application by using the Font.setDefault static method.  This will set the font for static menu items, but when a menu item is highlighted, the font that is used is the current theme font, and the highlight color is from the current theme.

 

I would like to find a way to customize the menu's so that my application can have full control over their appearance.  Has anyone does this type of thing before? 

 

I've downloaded a couple apps off the internet (ATT GPS navigator is one)....and it seems to suffer the same thing I'm seeing.  It uses a specific font for everything, but the menu's are still tied to the theme.

 

Our app will run on many devices, but the current one I'm using is an ATT Curve 8310.  Our app is built against the 4.2.1 RIM libraries.

 

Thanks!

Please use plain text.
Developer
richard_puckett
Posts: 191
Registered: ‎04-03-2008

Re: Custom Menu Drawing

The way I did it (if I ever write an autobiography I'm calling it that) is by catching the menu key keydown event and then invoking my menu, eg:

 

protected boolean keyDown(int keycode, int time) { if (Keypad.key(keycode) == Keypad.KEY_MENU) { displayMenu(); return true; } return super.keyDown(keycode, time); }

 

Then, displayMenu creates an instance of my own MenuScreen class and pushes it onto the display stack, as in the following:

 

 

private void displayMenu() { menu = makeMenu(); MenuScreen menuScreen = new MenuScreen(menu); UiApplication.getUiApplication().pushScreen(menuScreen); }

 

makeMenu is where the menu is created and populated:

 

private Menu makeMenu() { menu = new Menu(); SubMenu newSubMenu = menu.addSubMenu("New"); newSubMenu.add("A New Thing", Config.toolbarShortcutAccelerator).setRunnable(new Runnable() { public void run() { addNewToolbarAction(); } });

 

 

menu.addSeparator();

 

menu.add("About", Config.appInfoAccelerator).setRunnable(new Runnable() {

public void run() {

showAppInfoDialog();

}

});

}

 

  And so, for something like this you'd need to create a MenuScreen class (an extension of Screen that's responsible for drawng the menu frame) and Menu which, in my impl, is a VerticalFieldManager which acts as the model and is responsible for drawing the menu items.

 

  Beyond that, I also have code which iterates down through the display stack and checks each Manager to see if it's an instance of IMenuContributor (my own interface).  If it is then its "makeContextMenu" (parameterized against my own Menu rather than the stock one) is called in order to allow for context menu items.

 

  It's not the most trivial (or well-architected) approach, but it works for me.  I would release this to the public but right now it's a bit messy and is part of a larger framework that I use for UI operations (for tooltips, autocomplete fields, etc).  Anyway, hope it gives you some ideas.

Please use plain text.
Developer
ryandevore
Posts: 46
Registered: ‎07-12-2008

Re: Custom Menu Drawing

[ Edited ]
Thanks for the advice!  I was hoping I wouldn't have to go to the trouble of implementing the whole menu myself, but I'm guessing from the lack of comments on the thread and your solution are indicators there is no easy way to just override the built in menu's.
Message Edited by ryandevore on 09-07-2008 03:46 PM
Please use plain text.
Developer
peter_strange
Posts: 19,526
Registered: ‎07-14-2008

Re: Custom Menu Drawing

The standard answer from Rim to this question is that the menu fonts are tied to the theme.  So Richard's idea, which is very impressive, or doing something very similar, does seem to be the only option.

Please use plain text.
Developer
gsk_56
Posts: 25
Registered: ‎09-08-2008

Re: Custom Menu Drawing

Hi Richard_Puckett,

 

Iam very new to this domain. I have to create a tooltip for images means when i focus on image(BitmapField) it should show tooltip.  In this thread you mentioned your having your own customized Tooltip component.  please send sample code for creating tooltip for BitmapField. Or else if you know any article please send it to me. 

 

Thanks in advance.

 

Below code iam using for creating BitmapField.

 

BitmapField bmf_temp = new BitmapField(bitmap_temp, BitmapField.FOCUSABLE) { private XYRect xyrect=new XYRect(); protected boolean navigationClick(int status, int time) { System.out.println("!!!!!!!!!!!!!!!!Inside NavigationClick :: URL !!!!!!!!!!!"+info.getDataUrl()); PrimaryResourceFetchThread thread = new PrimaryResourceFetchThread("http://"+info.getDataUrl(), null, null, null,application_temp); if(thread.isAlive()==false) { thread.start(); } return true; } public void paint( Graphics graphics ) { graphics.setColor(Color.GRAY); graphics.drawRect(0,0,getWidth(),getHeight()); super.paint(graphics); } };

 

Please use plain text.
New Contributor
turkanhmzgl
Posts: 2
Registered: ‎06-03-2010
My Carrier: student

Re: Custom Menu Drawing

Hi,

 

I have the same urgent problem to build a custom menu. I am very new to BB development environment, only one week.

 

Can you please share all your code with me? no metter how much messy it is.

 

Thank you very much.

Please use plain text.
Contributor
dontayeb
Posts: 23
Registered: ‎05-27-2011
My Carrier: Digicel

Re: Custom Menu Drawing

:Rockon: thank u this helped richard_puckett

Please use plain text.