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
New Developer
Posts: 6
Registered: ‎09-13-2008
My Device: Not Specified

Adding menu item to file explorer

can someone please tell me how to add menu item to file explorer item.....i have used ApplicationMenuItemRepository class to add menu item in SMS , addressbooks, task and memo which is working fine but it is not working with file explorer..............one difference which i have noted is tht we have to pass ApplicationDescriptor to add menu item in file explorer........

 

can anyone post the code to do tht ?

 

 

Thanks

Developer
Posts: 29
Registered: ‎09-12-2008
My Device: Curve 8330

Re: Adding menu item to file explorer

In the FileExplorerDemo that comes with the JDE, this is where it would be added:

 

    public void makeMenu(Menu menu, int instance) {
        // only display the menu if no actions are performed
        if (instance == Menu.INSTANCE_DEFAULT) {
            menu.add(_selectItem);
           
            if (DeviceInfo.hasCamera()) {
                menu.add(_cameraItem);
            }
           
            menu.add(_deleteItem);
           
            if ( _parentRoot != null ) {
                menu.add( _backItem );
            }
        }

        super.makeMenu(menu, instance);
    }
   
Notice that it calls super.makeMenu to include the normal menu items as well as the cusstom items.  So to add an item you would add a line like "menu.add(_customItem);" to the above code.  It would reference the following code:

 

    private MenuItem _customItem = new MenuItem(_uiApp.getString(FileExplorerDemoResource.MENU_ITEM_CUSTOM), 500, 500) {
        public void run() {
            // Put your custom code here or a call to a function to do it
        }
    };

This code is executed when the menu item is selected.  Don't forget to update the recource file with the MENU_ITEM_CUSTOM text to be shown on the menu.

 

Is this what you were asking, or do I not understand the question?

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Adding menu item to file explorer

The ApplicationDescriptor.currentApplicationDescriptor returns the ApplicationDescriptor for the application from where you call it.  You can use this to obtain your application's ApplicationDescriptor.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 6
Registered: ‎09-13-2008
My Device: Not Specified

Re: Adding menu item to file explorer

FileExplorerDemo application that comes with the JDE, add menu item to the FileExplorerDemo application itself (not in-build application ) but i want to add menu item to the blackberry media application (only when image is opened )......but i guess there is no such field avaliable in ApplicationMenuItemRepositor class to add menu item in media images ....so i have chosen another option to add it in file explorer item......

 

i guess i m able to make u understand my question now  ?

 

 Following is the example code to add menu item in SMS application :

 

 

public class MyMainApp

{

public static void main(String[] args) { ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance(); ApplicationMenuItem smsmi = new EditSMSMenuItem(); amir.addMenuItem( ApplicationMenuItemRepository.MENUITEM_SMS_VIEW, smsmi); } MyMainApp() { } //Class to edit SMS menu item private static class EditSMSMenuItem extends ApplicationMenuItem { //private long ID = 0xe97d170d452eb143L; 0x6af0b5eb44dc5164L public EditSMSMenuItem () { super( 0 ); } public Object run (Object o) { if (o instanceof TextMessage) { // TODO: Load the application to modify the details! Dialog.alert( "Object is a SMS" ); } else { throw new IllegalStateException( "Expected a SMS object" ); } return null; } public String toString () { return "Print"; } }

 Which is working fine .....Now in the same way i want to add "Print" menu item in file explorer item.

 

 

New Developer
Posts: 6
Registered: ‎09-13-2008
My Device: Not Specified

Re: Adding menu item to file explorer

ApplicationDescriptor.currentApplicationDescriptor returns the ApplicationDescriptor for the application .....but it donot invoke run method then where i have to put the functionality behind that menu item.
BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Adding menu item to file explorer

You can use the ApplicationMenuItemRepository.MENUITEM_FILE_EXPLORER constant to add a menu item to the file explorer view.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 6
Registered: ‎09-13-2008
My Device: Not Specified

Re: Adding menu item to file explorer

I have used tht......

 

 Following is the code .......

import net.rim.blackberry.api.menuitem.ApplicationMenuItem; import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository; //import net.rim.device.api.system.Application; import net.rim.device.api.system.ApplicationDescriptor; import net.rim.device.api.ui.component.*; public final class MenuTest //extends Application { public static void main(String[] args) { long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_FILE_EXPLORER_ITEM; ApplicationMenuItem imagemenu = new DemoMenuItem(); ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance(); ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor(); amir.addMenuItem(locationToAddMenuItem , imagemenu ,app); } private static class DemoMenuItem extends ApplicationMenuItem { DemoMenuItem() { super(0); } public String toString() { return "Print"; } public Object run(Object context) { if (context instanceof String) Dialog.alert("Hello ...run."); //System.out.println("run is running"); return context; } } }

 

this code show up the Print menu item.........but the problem is when i click on the Print option.....rather then invoking the run() method....the control moves back to the main block and again Print option get added in menu....why run() method is not invoking ??....is there any alternate way to do tht?     

Thanks 4 ur response

 

Regards,

Preety

 

BlackBerry Development Advisor
Posts: 15,752
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Adding menu item to file explorer

I have been able to reproduce this behaviour and notified our development team of the issue.

 

You could work around the duplication by storing a value in the RuntimeStore when your ApplicationMenuItem is created and checking if it exists within you constructor.  The limitation is that your application does not receive a string with the selected file.

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
New Developer
Posts: 7
Registered: ‎08-12-2008
My Device: Not Specified

Re: Adding menu item to file explorer

Hi Mark,

 

I'm facing the very same issue, did you get any answer/workaround from the dev team on how to get the selected file name anyway?

 

Cheers

Highlighted
New Developer
Posts: 50
Registered: ‎03-18-2009
My Device: 8530
My Carrier: Movilnet

Re: Adding menu item to file explorer

Hi, I Solved your problem with the code below:

 

 

package Menutest; import net.rim.blackberry.api.menuitem.ApplicationMenuItem; import net.rim.blackberry.api.menuitem.ApplicationMenuItemRepository; //import net.rim.device.api.system.Application; import net.rim.device.api.system.ApplicationDescriptor; import net.rim.device.api.ui.component.*; import net.rim.device.api.system.*; import net.rim.device.api.ui.component.Dialog.*; public final class Menutest extends Application { private static long ID = 0x7cab1e23b72a0033L; public static void main(String[] args) { Menutest app = new Menutest(); app.enterEventDispatcher(); } Menutest() { System.out.println("Registering MenuTest"); long locationToAddMenuItem = ApplicationMenuItemRepository.MENUITEM_FILE_EXPLORER; ApplicationMenuItemRepository amir = ApplicationMenuItemRepository.getInstance(); ApplicationMenuItem imagemenu = new DemoMenuItem(); ApplicationDescriptor app = ApplicationDescriptor.currentApplicationDescriptor(); amir.addMenuItem(locationToAddMenuItem , imagemenu, app); } private static class DemoMenuItem extends ApplicationMenuItem { DemoMenuItem() { super(20); } public String toString() { return "Print"; } public Object run(Object context) { if (context instanceof String) { Dialog.alert("Hello ...run."); //System.out.println("run is running"); } return context; } } }

 

 

 

 

 

// Code for getting Thanks
if( iWasHelpful && solvedYourProblem ) {
Thanks++;
solution = true;
}