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
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

Its overridden but then also "fieldIndex" is not coming "-1"
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

[ Edited ]

Thanks Bikas.

 

Actually the problem was I have overridden getFieldAtLocation(x, y) but I m using 2 HFM's. So I wrote touchEvent() for btoth in there Inner class & getFieldAtLocation(x, y) was in outer class so not getting expected output.By adding it in respective Inner class got expected result.

 

But after adding HFM for BitmapFields when I add HFM for ButtonFields. The 1st HFM is working properly but in 2nd HFM the ButtonFieldss r not getting displayed also. I m looking into it. But i think after displaying it will work properly.

 

But not getting why ButtonFields in 2nd HFM are not getting displayed.

Message Edited by shreyasb on 09-03-2009 09:53 AM
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

This may be caused beacuse the 2nd Hfm does not fit within the screen.

Try with adding vertical scoll to your main screen.

 

super(Manager.VERTICAL_SCROLL);

 

Regards

Bikas

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

I have added this. The HFM is coming there & ButtonFields click events occur only they are not visible.

 

 

okButton = new ButtonField("Ok", ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY | ButtonField.FOCUSABLE | ButtonField.VISUAL_STATE_ACTIVE);
deleteButton = new ButtonField("Del", ButtonField.CONSUME_CLICK | ButtonField.NEVER_DIRTY | ButtonField.FOCUSABLE | ButtonField.VISUAL_STATE_ACTIVE);
Background grayBackground = BackgroundFactory.createSolidBackground(Color.LIGHTGREY);

 

hfm_DiscardArea = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH | HorizontalFieldManager.VERTICAL_SCROLL){ protected void sublayout(int maxWidth, int maxHeight) { super.sublayout(maxWidth, maxHeight); setExtent(Display.getWidth(), 62); setPositionChild(okButton, 2, (hfm_DiscardArea.getHeight() / 2) - (okButton.getHeight() / 2)); setPositionChild(deleteButton, hfm_DiscardArea.getWidth() - deleteButton.getWidth(), (hfm_DiscardArea.getHeight() / 2) - (deleteButton.getHeight() / 2)); } public void paint(Graphics g) { super.paint(g); g.setColor(Color.BLACK); g.drawLine(0,0,Display.getWidth(),0); g.drawLine(0,hfm_DiscardArea.getHeight()-1,Display.getWidth(),hfm_DiscardArea.getHeight()-1); } protected boolean touchEvent(TouchEvent event) { // Retrieve the new x and y touch positions. int x = event.getX(1); int y = event.getY(1); System.out.println("X: "+x); System.out.println("Y: "+y); int eventCode = event.getEvent(); if(eventCode == TouchEvent.CLICK) { //See if there is a field at this screen position int fieldIndex = getFieldAtLocation(x, y); if(fieldIndex == -1) return true; // kill the event else if ((fieldIndex >= 0) && (fieldIndex < getFieldCount())) { //Set the focus to the field at this position Field field = getField(fieldIndex); field.setFocus(); if(field == okButton) { System.out.println(".......... Clicked OK .............."); } else if(field == deleteButton) { System.out.println(".......... Clicked DEL .............."); } } return false; } //Event wasn't for us, handle in default manner return super.touchEvent(event); } public int getFieldAtLocation(int x, int y) { XYRect rect = new XYRect(); int index = getFieldCount() - 1; while (index >= 0) { getField(index).getExtent(rect); if (rect.contains(x, y)) break; --index; } return index; } };

 

hfm_DiscardArea.setBackground(grayBackground);
hfm_DiscardArea.add(doneButton);
hfm_DiscardArea.add(deleteButton);  

 

vfm_Main.add(hfm_BitmapField);
vfm_Main.add(hfm_DiscardArea);
vfm_Main.add(hfm);
add(vfm_Main);

 

I had taken 1 "vfm_Main". In that 2 HFM's & 1 VFM is there. VFM for BitmapFields is coming properly with 2 BitmapFields. Below that is HFM for 2 ButtonFields. Its coming but only 2 Buttons are not visible.

 

& Do u know how to CONSUME_CLICK for BitmapFields like for ButtonFields.CONSUME_CLICK ?

 

 

 

Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

I had created BitmapField as ...

 

 

public class MyCanvas extends MainScreen { BitmapField start = new BitmapField(startBitmap, BitmapFieid.FOCUSABLE); ButtonField okButton = new ButtonField("Ok", ButtonField.CONSUME_CLICK | ButtonField.FOCUSABLE); hfm.add(start); hfm.add(okButton); }

 

 But there is no property for BitmapField as

 

 

BitmapField.CONSUME_CLICK

 

to avoid the default menu that comes when clicked on it.

ButtonField has "CONSUME_CLICK" property so we can set for it as 

 

 

ButtonField okButton = new ButtonField("Ok", ButtonField.CONSUME_CLICK | ButtonField.FOCUSABLE);

 

 The TouchEvents are coming properly by overriding touchevent().

 

 Only I want to set "CONSUME_CLICK" property for BitmapField to avoid the default menu that comes when clicked on it.. How to do it ?

 

 

 

 

Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

[ Edited ]

To avoid the default menu that comes when clicked on the BitmapField:

override navigationClick() for BitmapField and don't return super.navigationCLick() rather just return true which indicates you consumed the click event.

 

Something like:

 

BitmapField start = new BitmapField(startBitmap, BitmapFieid.FOCUSABLE)
{
protected boolean navigationClick(int status, int time )
{
//handle click event
return true;
}
}

 

Regards

Bikas

Message Edited by bikas on 09-05-2009 04:56 PM
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

[ Edited ]
Hey Thanks Bikas.. It worked..
Message Edited by shreyasb on 09-05-2009 07:39 AM
Please use plain text.
Developer
shreyasb
Posts: 152
Registered: ‎07-17-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

[ Edited ]

Only that 2 ButtonFields are not visible in HFM.

 

Pls refer my code above my 2 posts. (Messsge 15)

Message Edited by shreyasb on 09-05-2009 07:45 AM
Please use plain text.
Developer
bikas
Posts: 984
Registered: ‎02-10-2009
My Device: Not Specified

Re: How to handle ButtonField & BitmapField Click (Touch) events in Blackberry Storm?

I think the problem is in the sublayout(..) method of the hfm_DiscardArea.

 

Try with comment out HorizontalFieldManager.VERTICAL_SCTROLL

 

And also have a look at the following KB article. You will get the clear idea how to organize a layout.

 

How to - Create a custom layout manager for a screen

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800505/800508/... 

 

Regards

Bikas

Please use plain text.