How to make bitmapfield focusable and clickable - blackberry

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)

Related

how to improve autosuggest/complete in blackberry + java

I am facing lot of issues while implement the auto suggest :I will tell you my issues .
1) Focus is always comes on auto suggest /complete field.First there is button .But focus is also on autosuggest field as shown in figure
2) When I write m on auto suggest field monday is display when I click the track pad it display monday on autosuggest field But Monday of pop up is not hide.
3) what is this encircle .How to change is gray color (or remove this color).some times it display on whole field and some time on half field
4) I just want a auto suggest with fix width not whole width .Like this on a screen with black background and autosuggest (edit field have white background no gray when focus comes on auto suggest)
Example
Label Auto suggest
Days Auto-complete of days
public final class MyScreen extends MainScreen implements JsonObserver
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
// Set the displayed title of the screen
setTitle("Drop-down List Demo");
VerticalFieldManager vfm=new VerticalFieldManager(){
protected void sublayout(int maxWidth, int maxHeight) {
// TODO Auto-generated method stub
super.sublayout(maxWidth, maxHeight);
setExtent(maxWidth, maxHeight/2);
}
protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
graphics.setColor(Color.BLACK);
graphics.fillRect(0, 0, Display.getWidth(), Display.getHeight()/2);
super.paint(graphics);
}
};
vfm.add(new ButtonField("add"));
BasicFilteredList filterList = new BasicFilteredList();
String[] days = {"Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday"};
filterList.addDataSet(1,days,"days",BasicFilteredList.COMPARISON_IGNORE_CASE);
AutoCompleteField autoCompleteField = new AutoCompleteField(filterList);
vfm.add(autoCompleteField);
vfm.add(new ButtonField("addpppp"));
add(vfm);
}
}

How to move drop down left in blackberry + java

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.

Blackberry Remove Highlighted Blue Focus

I have a custom ImageButton in which I have placed a png and the hover Image which is transparent from some parts. So when It gets focused it also takes it self with a blue focus. I want to remove that focus blue color but at the same time I want my hoverImage to work!
This is my ImageButton Class: http://codepad.org/mjtIUKLR
A solution that works for me is to add this functionality to the paint method and track whether focus has been gained:
boolean hasFocus = false;
public void onFocus(int direction) {
invalidate();
hasFocus = true;
}
public void onUnfocus() {
hasFocus = false;
invalidate();
super.onUnfocus();
}
And then use this in your paint method:
public void paint(Graphics graphics) {
if (hasFocus){
graphics.drawShadedFilledPath(xPositions, yPositions, null,
HIGHLIGHTED_GRADIENT, null);
}else{
graphics.drawShadedFilledPath(xPositions, yPositions, null,
GRADIENT, null);
}
super.paint(graphics);
}
In my example above, I am using a custom gradient for highlighting that overrides the default blue colour. In your case you will obviously want to change your image or something.

How to change row color background in a ListField after navigation Click?

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.

Blackberry -- Listfield with transparent rows

I have a screen with a background image being rendered like so:
bg = new VerticalFieldManager(
VerticalFieldManager.USE_ALL_WIDTH |
VerticalFieldManager.USE_ALL_HEIGHT |
VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR |
VerticalFieldManager.NO_VERTICAL_SCROLLBAR |
VerticalFieldManager.NO_HORIZONTAL_SCROLL |
VerticalFieldManager.NO_VERTICAL_SCROLL) {
//Override the paint method to draw the background image.
public void paint(Graphics graphics) {
//Draw the background image and then call paint.
graphics.drawBitmap(Graphics.getScreenWidth()/2 - bgBitmap.getWidth()/2,
Graphics.getScreenHeight()/2 - bgBitmap.getHeight()/2,
bgBitmap.getWidth(), bgBitmap.getHeight(), bgBitmap, 0, 0);
super.paint(graphics);
}
};
add(bg);
Then I'm adding any fields for the screen to this manager. I have a ListField that I'd like to see the background through. When the screen is first rendered, all is well. I can see the image. As soon as I scroll down, select something and unselect it, the background disappears (turns white).
Do I need to do something special when drawing my list rows in order to make them truly transparent after the selection color is gone?
NOTE: I've found that this happens no matter what field is drawn on top of the background. It displays correctly until the selection color is drawn for a given focusable field and then you select something else. All the area that was filled with the selection color turns to the default white after unselecting it.
use invalidate() function within onfocus() and onunfocus() method.
For example if you use LabelField then use:
LabelField l=new LabelField("Hello",FOCUSABLE)
{
protected void onFocus(int direction)
{
invalidate();
super.onFocus(direction);
}
protected void onUnfocus()
{
invalidate();
super.onUnfocus();
}
};
I ended up overriding moveFocus() in my custom ListField.
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
return super.moveFocus(amount, status, time);
}
Vivek's method works well for single fields outside of a ListField row though.

Resources