How to move drop down left in blackberry + java - blackberry

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.

Related

Set the text in the center of the screen in Button Field in Blackberry?

I am an an Android Developer, developing an Blackberry application.
I have created a button of full width of screen. Getting problem in shifting the text to the center of the button area.
Used below code :
ButtonField _contactButton = new ButtonField(Constants.contactButtonTitle,Field.FIELD_HCENTER|Field.USE_ALL_WIDTH |
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
protected void layout(int width, int height) {
super.layout(width, height);
HARD_CODED_HEIGHT = this.getHeight()/2 + 6;
this.setExtent(contactButtonWidth, HARD_CODED_HEIGHT);
}
public int getPreferredWidth() {
return contactButtonWidth;
}
};
Now using the below code :
ButtonField _contactButton = new ButtonField(Constants.contactButtonTitle,Field.FIELD_VCENTER|Field.USE_ALL_WIDTH |
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
public int getPreferredWidth() {
return (Display.getWidth()-60);
}
};
Still getting the issue .. text of my button align to right corner. Please suggest
ButtonField appears to be a little 'broken'. But it also appears to be consistently broken in all the OS Levels that I have tested (OS 5.0 to OS 7.1), so I think we can achieve what you want by working round the broken bits and be confident the workaround will work in all levels you want.
As has been noted, ButtonField ignores USE_ALL_WIDTH, but does respect preferredWidth. So if you want to set the width of your ButtonField, then just override getPreferredWidth(). You should not do anything with width in layout.
Now you are using the styles for ButtonField already. Given that we have discarded USE_ALL_WIDTH as a useful style, I note that you also use FIELD_HCENTER. You should be aware that this is actually a directive to the Manager that is positioning this Field - telling the Manager to position the Field in the centre of the width the Manager has available. This style does not relate to how the contents of the ButtonField are drawn.
For that, you can look to use DrawStyle. By default, ButtonField uses DrawStyle.RIGHT. And it respects DrawStyle.Left - the text will be drawn on the left. It does not however, respect DrawStyle.HCENTER. So to get centred text, we need to paint the text ourselves.
There is one more complication. ButtonField passes a Context area into its paint() method, not the full Field canvas - presumably it does not pass in the edges because these are painted by a border. So to centre the text appropriately, we have to use the clipping region that has been passed in.
Here is the final, hopefully working, ButtonField. I appreciate you will have to spend some time creating a class for this, I'm sorry, I've been lazy and done in it 'in-line'. Please publish your CenteredTextButtonField class if you create one....
final String buttonText = "Test";
ButtonField _contactButton = new ButtonField(" ",
Field.ACTION_INVOKE | Field.FOCUSABLE | ButtonField.CONSUME_CLICK){
public int getPreferredWidth() {
return contactButtonWidth;
}
protected void paint(Graphics graphics) {
super.paint(graphics);
XYRect clippingRect = graphics.getClippingRect();
int centreY = (clippingRect.height - graphics.getFont().getHeight()) / 2;
graphics.drawText(buttonText, 0, centreY, DrawStyle.HCENTER, clippingRect.width);
}
};
USE_ALL_WIDTH is our instruction to the field. Surprisingly, ButtonField ignores such instructions. Even more surprisingly, it honors its own getPreferredWidth (as illogical as it sounds).
So drop that USE_ALL_WIDTH and define your ButtonField like this:
ButtonField testBtn = new ButtonField("Button") {
public int getPreferredWidth() {
return Display.getWidth();
}
};

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 remove white color around Labelfield in Blackberry

I am developing a blackberry app and I am new to Blackberry. I am using Label Field in every screens, but there is a color surrounding the LabelField other than the background I have given for the screen like the image I have given here..
This is a header in my App,which comes in every screens. Here you can see a white color around the "state editions". It does not look good. I want the orange background color at the place of white color. Thanks in advance...
You are using the following code.. (from your comment)
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
graphics.clear();
graphics.setColor(Color.BLACK);
graphics.setBackgroundColor(Color.ORANGE); graphics.fillRect(0, 0,0, 0);
super.paint(graphics);
}
};
Try to modify this like the following:
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER) {
public void paint(Graphics graphics) {
super.paint(graphics);
}
};
That means, you don't have to extend default LabelField.
Just use,
lF1= new LabelField("state editions",LabelField.FIELD_LEFT |FIELD_VCENTER);
And check the Graphics , graphics.clear() etc in the API.

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)

not display cursor in custom BasicEditField bb

please check it
BasicEditField demo = ew BasicEditField("", number, 15,
BasicEditField.FILTER_NUMERIC
| BasicEditField.FIELD_LEFT) {
public int getPreferredWidth() {
int Width = Graphics.getScreenWidth() - 180;
return Width;
}
public int getPreferredHeight() {
return 30;
}
public void paint(Graphics g) {
g.setColor(Color.LINEN);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
g.setColor(Color.BLUE);
g.drawText(getText(), 0, 0);
super.paint(g);
}
protected void layout(int arg0, int arg1) {
super.layout(getPreferredWidth(), getPreferredHeight());
super.setExtent(getPreferredWidth(), getPreferredHeight());
}
};
this is my code help me out?
Kalpana, I checked your code. Yes, It is not showing cursor. I suggest you to use EditField instead of BasicEditField. You can override these methods for Editfield also. I tried it and it is showing cursor.
I think I may have solved this by adding another field to the manager before this custom BasicEditField. Add a field that doesn't do anything. Something like this:
BitmapField bugFix = new BitmapField(Bitmap.getBitmapResource("empty_image.png"));
myFieldManager.add(bugFix);
myFieldManager.add(demo);
However, what I found is that the size of the dummy field (BitmapField in this case) matters. If your "empty_image.png" image is only 2px high, only the top 2px of the cursor will display. So, if you can deal with the extra padding, add a field that has at least 20px or so and the entire cursor should display. I should also add that this bug does not seem to show up on any subsequent custom BasicEditFields that you add to the manager... only the first one. Hmmm...

Resources