Faster MenuOption

2 views
Skip to first unread message

rafa

unread,
Jun 4, 2009, 12:56:27 PM6/4/09
to J4ME
Hi,
I see no activity for a few months. I just hope the project is still
active. Do you plan any release soon?
Anyway, I have an app, with long menues: about 60 MenuOption, some
of the options' text spreads over 2-3 lines. That made the app slow,
when moving through the menu. Well... I changed a bit the MenuOption
class.
I'm caching the getPreferredSize() result, so I don't call it again
if the text (label) is the same. This is the modified code on
MenuOption.java.

private int[] cachedPreferredTextSize=null; // this variable is new
protected int[] getPreferredTextSize (Theme theme, int viewportWidth,
int viewportHeight)
{
if (null == text.getLabel() || !text.getLabel().equals(getLabel()))
{
text.setLabel( getLabel() );
cachedPreferredTextSize= text.getPreferredSize( theme,
viewportWidth, viewportHeight );
}
return cachedPreferredTextSize;
}

Note that there is a potential error: I'm not checking "theme",
"viewportWidth" and "viewportHeight" being the same as in last call.
In my app that is ok (AFAIK), but you might need to store the values
of those parameters in previous call and compare to make it fool
proof.

Hope it is usefull for someone (and is added to next release)
Regards,
Rafa

michael...@googlemail.com

unread,
Jun 5, 2009, 10:03:18 AM6/5/09
to J4ME
Yeah, I had a similar problem. How much of a performance benefit did
you get from your solution?

rafa

unread,
Jun 5, 2009, 10:20:57 PM6/5/09
to J4ME
In my Nokia 5200 the difference is really big. Probably in other
phones, the difference will be less obvious.
Rafa



On Jun 5, 11:03 am, "michael.ebb...@googlemail.com"

michael...@googlemail.com

unread,
Jul 9, 2009, 5:06:29 AM7/9/09
to J4ME
Yeah, that sounds about right. The biggest issues I've had have been
with older/low end Nokia's - they've got a good level of
functionality, but low-spec processing power.

That's not to slate Nokia's, I would have had the issue with other
manufacturer's handsets if the earlier models had better Java support.
Reply all
Reply to author
Forward
0 new messages