Question

I want to have a listener when a message is opened from the application messages folder. For this I make use of ApplicationMenuItem, but after registering it, the message could not be opened anymore.

ApplicationMessageFolderRegistry messagefolderRegistry = ApplicationMessageFolderRegistry.getInstance();
        messaageMenuItemListener = new CVSMessaageMenuItemListener();
        CVSApplicationMenuItem menuItem = new CVSApplicationMenuItem();
        menuItem.registerMenuItemListener(messaageMenuItemListener);        
        messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});
        messagefolderRegistry.registerMessageIcon(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, alarmsIcon);

and the menuItem:

public class CVSApplicationMenuItem extends ApplicationMenuItem {

    private CVSVector listeners;

    CVSApplicationMenuItem(){
        super(20);
    }

    public Object run(Object context) {
        if(!(context instanceof CVSApplicationMessage))
            return context;

        CVSApplicationMessage applicationMessage = (CVSApplicationMessage)context;
        if(listeners == null)
            return context;

        for (int i = 0; i < listeners.size(); i++) {
            ((ICVSApplicationMessageMenuItemListener)listeners.itemAt(i)).messageReaded(applicationMessage);
        }
        return context;
    }

    public void registerMenuItemListener(ICVSApplicationMessageMenuItemListener l){
        if(listeners == null)
            listeners = new CVSVector();

        if(l != null)
            listeners.addItem(l);
    }

    public String toString() {
        return null;
    }

}

I can see the message in the messages list (opened from home notification icon), but cannot open it. If I do the following it works, but then I have no callback when the message it's opened:

//messagefolderRegistry.registerMessageMenuItems(CVSApplicationMessage.TYPE_ALARMS, ApplicationMessage.Status.UNOPENED, new ApplicationMenuItem[]{menuItem});
Was it helpful?

Solution

As I understand you don't see system "Message preview" screen any more. I have same problem. Seems when you register menu item it completely overrides open action. I checked Message List Demo and found that they open custom preview message screen inside ApplicationMenuItem's run() method. As I didn't found any way to open system "Message preview" screen with my message I'm going to implement custom screen also.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top