Bitmap field taking focus on whole screen - blackberry

I have added 2 BitmapFields(left and right arrow) on one HorizontalFieldManager, but when I click anywhere on HFM, BitmapFields taking focus and shows that it is selected.
I want not to show focus anywhere until it doesn't click on BitmapFields.
Following is the code for it:
bmfBottomRight = new BitmapField(bmpBottomRightFocused, FOCUSABLE) {
protected boolean navigationClick(int status, int time) {
int fieldIndex = getCurrentFieldIndex();
if (fieldIndex < (surveyList.size() - 1))
updateIncrField(fieldIndex);
return super.navigationClick(status, time);
}
};
bmfBottomLeft.setPadding(5, 0, 5, ((Display.getWidth() - bmfBottomRight.getPreferredWidth()) >> 1) - bmfBottomRight.getPreferredWidth());
I am setting Padding for it..

Have added null fields new NullField(Field.NON_FOCUSABLE). And added two different null fields at left and right of bitmap field. SO I am able to getting the focus on bitmapfield, when only tapping on it.

Related

Focus skip to top image in VerticalFieldManager

I have two VerticalFieldManager which are in HorizontalFieldManager to make two columns with images inside. Those images are able to focus (Blackberry add border to image when focus) with border, but there is one problem, when I scroll from right to left and opposite focus skip to the top image in VerticalFieldManager how to avoid it and skip to the nearest left/right image? Part responsible for adding images:
for(int i=0;i<15;++i){
if(i%2==0){
v1.add(tab[i]);
}else{
v2.add(tab[i]);
}
}
The reason for this is because your managers can only enter focus from 2 directions. For a HorizontalFieldManager its left and right, while VerticalFieldManager is top and bottom. When you scroll in your horizontal manager to the left, you are moving in a -1 direction. This is then passed to your vertical manager, where -1 means that it gets focus from the bottom. Likewise when you move to the right, it is in the +1 direction and focuses from the top.
The best bet for you would be to listen for navigation movement (on the horizontal manager), and then focus the correct field programmatically.
HorizontalFieldManager horManager = new HorizontalFieldManager(NO_HORIZONTAL_SCROLL | NO_VERTICAL_SCROLL | USE_ALL_WIDTH | USE_ALL_HEIGHT)
{
protected boolean navigationMovement(int dx, int dy, int status, int time)
{
if(dx > 0 && leftManager.isFocus()) // Moved right from the left manager
{
int index = leftManager.getFieldWithFocusIndex();
rightManager.getField(index).setFocus();
return true;
}
else if(dx < 0 && rightManager.isFocus())// Moved left from the right manager
{
int index = rightManager.getFieldWithFocusIndex();
leftManager.getField(index).setFocus();
return true;
}
return super.navigationMovement(dx, dy, status, time);
}
};
This assumes that both vertical managers contain the same number of fields and only two columns. But with a little bit of work, you can make this method handle a dynamic number of vertical managers, and fields.

BlackBerry Touch not going through Fields

I have a manager that is handling the Touch click.
In order to have the Manager Focusable I have a Field that is acting as a Background and is focusable, This field change color when it is focused.
The problem is, I have multiple fields on this manager (which are not focusable), like LabelField, BitmapField, etc...
If the user click on one of non-focusable Field, it won't take into account the click on the Cell.
But if the user clicks between 2 non-focusable fields (and then click on the Background Field), the click is took into account and works fine...
I would need some kind of click through set to true, how would I do that ?
P.S. : I do not want to put all Field focusable, because when using the trackball it would go through every Field, I just want the Whole Manager to be selected, not elements inside.
The Manager will actually get the click events - normally it will just pass them on. But you can process them if you want. The following code demonstrates the easiest way I find to make sure I process everything as I want. Try it on a touch screen and non touchscreen phone.
VerticalFieldManager testVFM = new VerticalFieldManager(Manager.USE_ALL_WIDTH) {
protected boolean touchEvent(TouchEvent message) {
int x = message.getX( 1 );
int y = message.getY( 1 );
if( x < 0 || y < 0 || x >= getExtent().width || y >= getExtent().height ) {
// Outside the field
return false;
}
if ( message.getEvent() == TouchEvent.UNCLICK ) {
Status.show("Manager Clicked");
return true;
}
return super.touchEvent(message);
}
};
LabelField testlab = new LabelField("test", LabelField.FIELD_HCENTER);
testVFM.add(testlab);
LabelField testlab2 = new LabelField("test2", LabelField.FIELD_HCENTER);
testVFM.add(testlab2);
testVFM.add(new NullField() {
protected boolean navigationClick(int status, int time){
Status.show("NullField Clicked");
return true;
}
}); // So Manager can get focus

Automatically change focus among Editfields in Blackberry

I have five EditField objects in my BlackBerry app, each one will accept only one numeric character.
I want to change the focus from the first EditField to the second EditField when a character is entered. Note the focus from one to another EditField must go automatically and not by pressing Enter key or some other key.
You want to set a FieldChangeListener on the EditField to monitor when the contents of the field changes. Once the user has entered a single character you can move to the next field by calling Field.setFocus().
Lets assume your EditFields are added to screen one by one.
You could use next code:
editField<i>.setFieldChangeListener(this);
...
public void fieldChanged(Field field, int status) {
if (field instanceof EditField) {
EditField editField = (EditField)field;
if (field.getText().length() > 0) {//don't move focus in case of deleted text
Manager manager = field.getManager();
Field nextField = manager.getField(manager.getFieldIndex(editField) + 1);
if (nextField instanceof EditField) {
nextField.setFocus();
}
}
}
}

Container is taking event of Button in blackberry

I have a grid container wchich consist two button.and i add this container in the form.
When i click on the button it is working fine but when i click outside the buttons then the event fired by those button which have the focus at that time.
GridFieldManager startStopButtonContainer = new GridFieldManager(2,Field.FIELD_HCENTER);
startStopButtonContainer.add(slideRestart);
startStopButtonContainer.add(slideStop);
add(startStopButtonContainer);
now i click on the slideRestart it works fine but when i click outside the button then also it is taking event.
Please help me out...:)
Add nullfield at starting & ending at each row of the gridfieldManager.And set style Field.Non_FOCASABLE to that nullfields.And set the default focus at buttonfield.
Note: nullfields must cover the remaining part of gridfieldManager.
you can use
LabelField field = new LabelField(" ",Field.NON_FOCUSABLE)
{
protected void layout(int width, int height)
{
// TODO Auto-generated method stub
super.layout(width, height);
setExtent((Display.getWidth()-(buttonField.getPreferredWidth()+buttonField.getPreferredWidth())/2, height);
}
};
as nullfield.

BlackBerry: define direction of Scroll or Focus change

Does BlackBerry provide any functionality to track focus or scroll change direction?
On our UI we have a horizontal tab bar, and under that a list.
If the user has navigated far down the list and decides to click another tab, it is difficult to get the focus back on the Tab control. The user must scroll up to the first list item and then the focus will move to the tab.
Since the list has no left-right component, can I catch horizontal scroll events to change the currently focused tab?
Similarly, I would like to catch vertical scroll events to go back to the list.
For navigation control you can override
protected boolean navigationMovement(int dx, int dy,
int status, int time) {
// TODO Auto-generated method stub
return super.navigationMovement(dx, dy, status, time);
}
here dx for horizontal navigation
and dy for vertical navigation.
if you want to listen focus change you can implement this method
public void focusChangeNotify(int arg0) {
// TODO Auto-generated method stub
super.focusChangeNotify(arg0);
}

Resources