Focus skip to top image in VerticalFieldManager - blackberry

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.

Related

Bitmap field taking focus on whole screen

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.

how to disable endless scroll in BasicEditField

HI all i have implement Custom BasicEditField to set hint and to input long text .
please see my code
vfm_searchBox = new VerticalFieldManager()
{
//Main.Quicksearchinput is background image for inputtext
public void paint(Graphics g)
{
g.setColor(Color.WHITE);
g.drawBitmap(0,0,Main.Quicksearchinput.getWidth(),Main.Quicksearchinput.getHeight(),Main.Quicksearchinput,0,0);
super.paint(g);
}}
There is one HorizontalFieldManager to scroll text.
hfm_searchBox = new HorizontalFieldManager(Manager.HORIZONTAL_SCROLL) ;
There is one Basiceditfield to input text .
txtSearch = new BasicEditField(BasicEditField.NO_NEWLINE)
{
public void paint(Graphics g)
{
if(super.getText().length() == 0)
{
g.setColor(Color.GRAY);
g.setFont(g.getFont().derive(Font.PLAIN,18));
g.drawText("Enter Event title or subtitle", 0, 0);
super.paint(g);
}
else
{
g.setColor(Color.BLACK);
super.paint(g);
}
}};
The BasicEditField looks nice with Backgroundimage and hint but problem is that when i am nothing input in textfield it is working as endless scroll . i have set Horizontalfield width depend on BasiceditField but its width by default set to unlimited .
hfm_searchBox.add(txtSearch);
vfm_searchBox.add(hfm_searchBox);
how to prevent endless scroll ?
Thanks in Advance !!!
What is the HorizontalFieldManager's virtual width? This refers to the scrollable space whereas the width refers to the extent on the screen. You can try extending HorizontalFieldManager and overriding the sublayout method, calling setVirtualExtent in it.
As Tamar said, the Field's Virtual Width is the key concept to keep track of.
You can see my solution to a very similar question here. I provide a full code example that's probably not too far from what you're trying to do. The code I use goes a step further, and dynamically limits scrolling only to the end of where the text currently reaches. If you don't do this, and simply set one constant virtual width, then you can have the field actually scroll too far to the right. By dynamically calling setVirtualExtent(), you always get just enough scrolling, but not too much.

How to Increase the row height of the selected item of listfield

I am using a ListField for my app to show the data in a list. Now my requirement is that i want to increase the row height of the selected item of the list.
For this, i created a GridFieldManager and populated my list using this manager. I then override the onFocus() method of this manager. But, this method is never invoked. As a result i am unable to increase the height of the selected row item.
Please help.
ListField rows are all designed to be uniformly sized, so unfortunately you won't be able to directly change the size of one row. It's possible you can emulate it by setting it so that the row above and below draw a little bit of the focus color at the bottom and top respectively. Alternatively, you could have one field that just stays centered above whatever row is focused. Then redraw this "floating Field" with the information from the selected row.
I got it working. I faked the ListField implementation. I removed ListField and replaced it with VerticalFieldManager. I adjusted its size during onfocus() and onUnfocus() and used sublayout() to change the height of this manager. Its working exactly the way i want.
you can increase the row height/font text/...
as ultimately, all of the api's call canvas's paint methods
how to do:
//try playing with the font_type,font height
Font myFont = Font.getDefault().derive(Font.PLAIN, 14, Ui.UNITS_px);
private class ListCallback implements ListFieldCallback {
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
g.setFont(myFont);
String text = (String)listElements.elementAt(index);
g.drawText(text, 0, y, 0, w);
//you can increase the height of a particular row in the height parameter.
// if you want it to be specific, put an 'if conditon'
EX: if(index=1)
{
w+=10;
}
}
}

Can't align fields horizontally on custom pop up screen in Blackberry

What I want to achieve is to have a custom popup screen with specified width and height.
On that screen I add two buttons which stay in one row and align center horizontally.
public class CustomPopupScreen extends PopupScreen {
ButtonField minimizeBf;
ButtonField cancelBf;
HorizontalFieldManager hfm;
public CustomPopupScreen() {
super(new VerticalFieldManager());
minimizeBf = new ButtonField("Minimize", FIELD_HCENTER|Field.USE_ALL_WIDTH);
cancelBf = new ButtonField("Cancel", FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm = new HorizontalFieldManager(FIELD_HCENTER|Field.USE_ALL_WIDTH);
hfm.add(minimizeBf);
hfm.add(cancelBf);
add(hfm);
//add(minimizeBf);
//add(cancelBf);
}
protected void sublayout(int width, int height) {
// TODO Auto-generated method stub
int xPos = 0;
int yPos = 0;
int sideMargin = 30;
int screenWidth = width - (2 * sideMargin);
int screenHeight = 100;
layoutDelegate(screenWidth, screenHeight);
//setPositionDelegate(0, 0);
super.sublayout(screenWidth, screenHeight);
setExtent(screenWidth, screenHeight);
xPos = (width - screenWidth) / 2;
yPos = (height - screenHeight) / 2;
setPosition(xPos, yPos);
// layout(screenWidth, screenHeight);
}
}
If I add those buttons to the screen, then it will align center horizontally, but the buttons appear on different row, while I want it to appear in the same row.
Can somebody tell me where have I code wrong ?
Try removing the USE_ALL_WIDTH flag from your HorizontalFieldManager allocation. That should do the trick.
Try putting a couple of vertical field managers, each taking half the available width, inside the horizontal manager. then add one button to each of the vertical managers.
I was just wondering the purpose of having a custom size. There is often a correct way to do something without having to modify the layout manually. If you share your end goal, we may be able to help better. Since it almost appears that you want to simply make two buttons be side to side. To add width and height you can add spacers (add(new SeparatorField())) to the field managers and specify their width/height as well as where in the manager you want them. This would allow all the fields to use their default layout patterns.
just do one
hfm = new HorizontalFieldManager(USE_ALL_WIDTH);
i think it might help you just give it a try.

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