I have the following labelfield that I want to be clickable and also catch/handle its focus/unfocus events.
titleField = new LabelField(title,FOCUSABLE|USE_ALL_WIDTH){
public void paint(Graphics graphics)
{
graphics.setColor(Color.BLUE);
graphics.drawText(_title, 30,0);
super.paint(graphics);
}
protected boolean navigationClick(int status,int time)
{
if(panel != null) panel.takeAction();
return true;
}
protected void onFocus(int dir)
{
super.onFocus(dir);
panel.setSelectedIndex(_index);
}
protected void onUnfocus()
{
if(!_collapse){
_prevIndex = _index;
panel.setPreviousSelectedIndex(_prevIndex);
}
}
};
So far, the code works as expected on my os5 simulators, but on os6/7 simulators, the labelfields just appear blank (I even tried removing the super.paint(graphics); call but still got the same results). Any ideas what's happening? Thanks
I would suggest you remove drawText and call setText for label every time when you change _title field.
I see also that you don't call super.onUnfocus() it cause repaint issue.
i figured it out... actually in my layout (horizontal) i have a checkboxfield then a labelfield.. for some strange reason the checkboxfield is taking up all the horizontal space on os6/7 simulators even though i did not specify USE_ALL_WIDTH. By overriding layout and specifying the dimensions for the checkboxfield, the layout's behaving properly now. Thanks for the tips :)
Related
I am using ObjectChoiceField example. it is showing drop down at the end of right side, but i need to show some margin on the left side .
how we can achieve this ?
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm=new VerticalFieldManager(){
protected void paint(Graphics graphics) {
graphics.setBackgroundColor(Color.BLACK);
graphics.clear();
super.paint(graphics);
}
};
vfm.add(new ObjectChoiceField("Day of the week",choices,iSetTo){
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
});
I am using this example:
![enter image description here][1]
You can do this with many fields by setting their margin. Field#setMargin() has been available since BBOS 6.0 officially, but was undocumented and usable in 5.0 (at least), too. So, at this point, I consider it perfectly acceptable to use in 5.0+ apps.
For example:
public ChoiceMarginScreen() {
super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
String choices[] = {"Monday","Tuesday","Wednesday","Thursday","Friday", "Saturday", "Sunday"};
int iSetTo = 0;
VerticalFieldManager vfm = new VerticalFieldManager();
vfm.setBackground(BackgroundFactory.createSolidBackground(Color.BLACK));
ObjectChoiceField days = new ObjectChoiceField("Day of the week", choices, iSetTo) {
protected void paint(Graphics graphics) {
graphics.setColor(Color.WHITE);
super.paint(graphics);
}
};
// set margin XYEdges(top, right, bottom, left):
days.setMargin(new XYEdges(0, 150, 0, 0));
vfm.add(days);
add(vfm);
}
Note that you also don't need to override the VerticalFieldManager#paint() method just to set a solid background color. You can use setBackground() for that. For setting the white font color on your object choice field, though, overriding paint() is a fine solution.
Also: I just went off your screen shot, and assumed you wanted the choice field moved to the left, but with no other field to the right of it. If you want the choice field to the left to make room for another field on its right, then you probably want to put both those fields in a HorizontalFieldManager, representing a row, and then add that HorizontalFieldManager to your VerticalFieldManager. But, that's not what you showed, so I offer my answer above.
Developing on the blackberry (OS 7.0) and I have an extended Vertical Field manager created as such:
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.USE_ALL_HEIGHT | Manager.VERTICAL_SCROLL){};
However, when I scroll the view, the virtual scroll view size appears way too big.
i.e, I can scroll quite alot further down than is needed and I cant work out why?
Any body any quick ideas? I do have a background image in there that is created as such:
public void paint(Graphics graphics)
{
Bitmap backgroundBitmap = Bitmap.getBitmapResource("bg.png");
Bitmap newBackground = new Bitmap(Display.getWidth(), Display.getHeight());
backgroundBitmap.scaleInto(newBackground, Bitmap.FILTER_LANCZOS, Bitmap.SCALE_TO_FILL);
graphics.clear();
graphics.drawBitmap(0, 0, Display.getWidth(),
Display.getHeight(), newBackground, 0, 0);
super.paint(graphics);
}
Please and thanks,
Burrows
You can redefine the method to define the height of the manager
protected void setExtent(int width, int height) {
super.setExtent(width, myHeight);
}
To not repeat the background image is necessary to redefine the following method, returning false
protected boolean isScrollCopyable() {
return false;
}
Another comment is that it is a bad practice to obtain an image from the paint method. What you are doing is every time you call the paint method is going to get this image.
It's best to get the image once and then use it.
public MyScreen() {
super(NO_VERTICAL_SCROLL);
I managed to fix the issue in my extension of MainScreen using 'NO_VERTICAL_SCROLL' style parameter
Combined with Rupak's suggestion of setting the Background in the constructor of my Vertical Field Manager rather than overriding paint (
https://gist.github.com/3248319)
everything seems Good now - thanks all for your help.
Burrows
No need to USE_ALL_HEIGHT in your constructor.
// instead use this
_myVFM = new MyViewManager(Manager.USE_ALL_WIDTH | Manager.VERTICAL_SCROLL){};
I am doing a blackberry, in my application I have to make a bitmapfield clickable and focusable .This is my samplecode.
bf=new BitmapField(logo,BitmapField.FOCUSABLE){
protected boolean navigationClick(int status, int time) {
Dialog.inform("haaaaaaaaaaaai");
return true;
};
protected void layout(int width, int height) {
// TODO Auto-generated method stub
super.layout(width, height);
setExtent(120, 110);
}
};
And I added this field to a verticalfieldmanager. Now the problem is if I click any where in the screen the action is happening and it is not showing any sign of focus.Please help me friends.
BitmapField caontains Bitmap, so blue focusable rectangle covered by bitmap. If you want to show the BitmapField focusable then you need to:
use low opacity image.
OR
use image with 2 or more pixel transparent padding around the image.
for the second issue use can add NullField before the BitmapField because by default first field have focus in screen. And in your case only one field available on screen.
Check at Advanced UI. And look for BitmapButton. :)
For making the bitmap field focusable and clickable yue just use this code:-
Bitmap myBitmap = Bitmap.getBitmapResource("image.png");
BitmapField icImg = new BitmapField(myBitmap, BitmapField.FOCUSABLE)
{
protected boolean navigationClick(int status, int time)
{
UiApplication.getUiApplication().pushScreen( new SCREENCLASS());
return true;
}
};
add(icImg)
I have an application where I have a toolbarmanager on the bottom of the screen to control which screen is shown. The toolbar works great for touch but it is not focusable. I tried creating it with focusable style but no luck.
So far I tried:
tbm=new ToolbarManager(Manager.FOCUSABLE);
Additional details:
Now when I try to add FOCUSABLE to the ToolbarButtonField the whole toolbar disappears. Not sure why that is happening.
Any ideas?
You can't set a focus to a manager, you'll have to set the focus for the fields inside it. Now for the ToolbarManager, you can use the ToolbarButtonField and set him to focus, so the manager will get focused.
You can solve it by using the following.
ToolbarManager mana = new ToolbarManager();
ToolbarButtonField test = new ToolbarButtonField(){
public boolean isFocusable() {
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
};
test.setText(new StringProvider("AAAA"));
mana.add(test);
add(mana);
I'm beginner in BB dev. I create a CustomListField and when I click on a row, the background color of this row must change and a new screen must be displayed (it's done!).
Could any one please help me to get this done?
thx
Below is the code:
protected boolean navigationClick(int status, int time)
{Field field = this.getLeafFieldWithFocus();
if(field instanceof ListField)
{
// listValues is String[] where you store your list elements.
// listField is the ListField instance you are using
UiApplication.getUiApplication().pushScreen(new ReadMsgScreen());
int index= getIndex();
if(index== this.getSelectedIndex())
{
**// I think the code to change the row's background color must be set here!**
}
return true;
}
return super.navigationClick(status, time);
}
use this it will definately work...
int tmpcolor = graphics.getColor();
graphics.setColor(Color.CYAN);
graphics.fillRect(0, y, width, getRowHeight());
graphics.setColor(tmpcolor);
thanks...
onerride the paint() method in blackberry as showed the code below..
_specialNumbers = new LabelField(Constants.SPECIAL_NUMBERS,LabelField.USE_ALL_WIDTH) {
protected void paintBackground(Graphics arg0) {
int color = arg0.getBackgroundColor();
arg0.setBackgroundColor(Color.LIGHTGREY);
arg0.clear();
arg0.setBackgroundColor(color);
}
};
In the drawListRow() method of the ListFieldCallback for your CustomListField draw that selected line differently and call a Transition to display the other Screen slowly.