blackberry remove default color - blackberry

How do I remove default BLUE focus color in Blackberry? I have one bitmap field and it is focusable. When I click on that image, transparent portion of that image focus with BLUE color and I want to remove that.

This is a method by which you can remove the default color of focus. If you want to set your own color then you need to give body.
protected void drawFocus(Graphics paramGraphics,boolean paramBoolean)
{
//...
}

You can Try the follwing code
Bitmap b = Bitmap.getBitmapResource("test.png"){
protected void onFocus(int direction)
{
backgroundColour = highlightColour;
invalidate();
}
protected void onUnfocus()
{
backgroundColour = Color.GRAY;
invalidate();
}
protected void paint(Graphics graphics)
{
graphics.setColor(backgroundColour);
}
}

Related

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 make bitmapfield focusable and clickable

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)

ToolbarManager not focusable

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);

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