Traversing in Subclass of CustomItem
Hi
I am writing an J2ME application using CLDC 1.1 and MIDP 2.0. I have created a CustomItem. I have set the prefered and min content bounds of the CustomItem to the Form width and height in which it is embedded.
I have overriden the traverse(), to handle UP, DOWN, LEFT, RIGHT events, using Canvas.UP, Canvas.Down, Canvas.RIGHT, and Canvas.LEFT.
I have tested the code using the following emulator platforms:
1. J2ME WTK 2.2
2. Nokia Prototype SDK 4.0
3. Sony Ericsson SDK 2.2.3
4. Series 40 SDK 3rd Edition
In the first three platform the traversal code is working as expected, but in theSeries 40 SDK 3rd Edition the traverse event is not getting fired when the joystick is pressed in thedown direction after a first couple of times.
But the traversal code works fine with sony ericsson k750 device emulator which also have a joystick
Can any one suggest what i am missing here. I am enclosing the travesal code
publicstaticfinalint MONTH_SCROLLER = 1;
publicstaticfinalint CALENDAR = 2;
privateint location = MONTH_SCROLLER;
privateboolean m_oInsideComponent =false;
....
....
protectedboolean traverse(int dir,int viewportWidth,int viewportHeight,
int[] visRect_inout){
int month = m_oCalendar.get(Calendar.MONTH);
switch (dir){
case Canvas.LEFT:
if(location == MONTH_SCROLLER){
if(month == Calendar.JANUARY){
m_oCalendar.set(Calendar.YEAR, (m_oCalendar.get(Calendar.YEAR) - 1));
m_oCalendar.set(Calendar.MONTH, Calendar.DECEMBER);
}else{
m_oCalendar.set(Calendar.MONTH, (m_oCalendar.get(Calendar.MONTH) - 1));
}
setMonth(m_oCalendar);
}elseif(location == CALENDAR){
updateSelectedDateCell(m_nCurrentSelectedCellDate - 1, LEFT_RIGHT_SELECTION);
}
invalidate();
if (!m_oInsideComponent){
m_oInsideComponent =true;
}
break;
case Canvas.RIGHT:
if(location == MONTH_SCROLLER){
if(month == Calendar.DECEMBER){
m_oCalendar.set(Calendar.YEAR, (m_oCalendar.get(Calendar.YEAR) + 1));
m_oCalendar.set(Calendar.MONTH, Calendar.JANUARY);
}else{
m_oCalendar.set(Calendar.MONTH, (m_oCalendar.get(Calendar.MONTH) + 1));
}
setMonth(m_oCalendar);
}elseif(location == CALENDAR){
updateSelectedDateCell(m_nCurrentSelectedCellDate + 1, LEFT_RIGHT_SELECTION);
}
invalidate();
if(!m_oInsideComponent){
m_oInsideComponent =true;
}
break;
case Canvas.UP:
if(!m_oInsideComponent){
m_oInsideComponent =true;
returntrue;
}else{
if(location == CALENDAR){
if(m_nCurrentSelectedCellDate <= 7){
location = MONTH_SCROLLER;
}else{
updateSelectedDateCell(m_nCurrentSelectedCellDate - 7, UP_DOWN_SELECTION);
}
invalidate();
returntrue;
}elseif(location == MONTH_SCROLLER){
m_oInsideComponent =true;
returnfalse;
}else{
returnfalse;
}
}
//break;
case Canvas.DOWN:
if(!m_oInsideComponent){
m_oInsideComponent =true;
returntrue;
}else{
if(location == MONTH_SCROLLER){
location = CALENDAR;
invalidate();
returntrue;
}elseif(location == CALENDAR){
updateSelectedDateCell(m_nCurrentSelectedCellDate + 7, UP_DOWN_SELECTION);
m_oInsideComponent =true;
invalidate();
returnfalse;
}else{
returnfalse;
}
}
//break;
}
returntrue;
}

