Screen Height get reduced after click on Check Box [closed] - blackberry

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hello Everyone,
I am working on a Screen , the height of Screen reduced after click on CheckBox (when change listener call).
Here is the code :-
public class IA_SearchScreen extends MainScreen implements FieldChangeListener
{
private CheckboxField ch1;
private CheckboxField ch2;
private CheckboxField ch3;
private CheckboxField r1;
private CheckboxField r2;
private CheckboxField r3;
private boolean togle_r1 = true;
private boolean togle_r2;
private boolean togle_r3;
private AutoTextEditField iaDescriptionEditField;
private AutoTextEditField streetEditField;
private AutoTextEditField postCodeEditField ;
private AutoTextEditField radiusEditField ;
private Bitmap filterButton_F = Bitmap.getBitmapResource("filter_ focus.png");
private Bitmap filterButton_N = Bitmap.getBitmapResource("filter_Unfocuss.png");
private int temp_mgr_Height = 0;
private StatusManager status_Manager;
private ImageButton map_Button;
private ImageButton favorite_Button;
private ImageButton search_Button;
private Calendar calendar;
private LabelField _startDateLabelField;
private LabelField _startTimeLabelField;
private LabelField _endDateLabelField;
private LabelField _endTimeLabelField;
private String[] street_Array;
private String[] postCode_Array;
private String SearchString = Global.EMPTY;
private String DisruptionsType = Global.EMPTY;
private String Lat = Global.EMPTY;
private String Long = Global.EMPTY;
private String Radius = Global.EMPTY;
private String Severity = Global.EMPTY;
private String StartDate = Global.EMPTY;
private String EndDate = Global.EMPTY;
private String PostCode = Global.EMPTY;
private String StreetName = Global.EMPTY;
private String AllDates = Global.EMPTY;
private VerticalFieldManager _workSpace ;
public IA_SearchScreen()
{
super(Screen.USE_ALL_HEIGHT);
_workSpace = (VerticalFieldManager)getMainManager();
/**
* Initialize Screen Components
* */
iaDescriptionEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
iaDescriptionEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source0 = new SizedHFM(Global.Display_Width -30);
_source0.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source0.add(iaDescriptionEditField);
HorizontalFieldManager hfm_0 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -55, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Search by Incident or Accident Description", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_0.add(_source0);
hfm_0.add(new LabelField());
/**
* StreetEditField Manager START
* */
streetEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
streetEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source = new SizedHFM(Global.Display_Width - 65);
_source.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source.add(streetEditField);
ImageButton btn_go_streetEditField = new ImageButton(filterButton_N , filterButton_F)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go_streetEditField.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
street_Invoke();
}
});
HorizontalFieldManager hfm_1 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -filterButton_N.getWidth()-10, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Plain_16);
graphics.drawText("Street", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_1.add(_source);
hfm_1.add(btn_go_streetEditField);
/**
* StreetEditField Manager END
* */
/**
* PostCodeEditField Manager START
* */
postCodeEditField = new AutoTextEditField("" , "", 500, EditField.NO_NEWLINE | EditField.NON_SPELLCHECKABLE)
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
postCodeEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source1 = new SizedHFM(Global.Display_Width -65);
_source1.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source1.add(postCodeEditField);
ImageButton btn_go_postCodeEditField = new ImageButton(filterButton_N , filterButton_F)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go_postCodeEditField.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
postCode_Invoke();
}
});
HorizontalFieldManager hfm_2 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width - filterButton_N.getWidth()-10, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Plain_16);
graphics.drawText("Post code", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_2.add(_source1);
hfm_2.add(btn_go_postCodeEditField);
/**
* PostCodeEditField Manager END
* */
radiusEditField = new AutoTextEditField("" , "", 5, EditField.NO_NEWLINE |AutoTextEditField.FILTER_INTEGER )
{
protected void layout(int width, int height)
{
super.layout(width, height);
setExtent((Global.Display_Width - 40), getHeight());
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
radiusEditField.setFont(Global.arialFont_Plain_16);
SizedHFM _source3 = new SizedHFM(Global.Display_Width -30);
_source3.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3, 3, 3, 3), 0x867E42, Border.STYLE_FILLED), true);
_source3.add(radiusEditField);
HorizontalFieldManager hfm_3 = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(maxWidth, maxHeight);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 10, 25);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -55, 25);
setExtent(maxWidth,temp_mgr_Height + 35);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Radius (in Meters)", 15, 5);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
hfm_3.add(_source3);
hfm_3.add(new LabelField());
/**
* Start Date & Time
* */
_startDateLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
return true;
}
};
_startTimeLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
// TODO Auto-generated method stub
return true;
}
};
HorizontalFieldManager startDateNTimeManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 20, 30);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -120, 30);
setExtent(maxWidth,/*temp_mgr_Height + 25*/ 70);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("Start Date & Time", 10, 5);
graphics.drawRect(9, 25, 141, 30);
graphics.drawRect((Global.Display_Width - 151), 25, 141, 30);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
startDateNTimeManager.add(_startDateLabelField);
startDateNTimeManager.add(_startTimeLabelField);
/**
* End Date & Time
* */
_endDateLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
return true;
}
};
_endTimeLabelField = new LabelField("")
{
protected void layout(int width, int height) {
super.layout(150, 25);
super.setExtent(150, 25);
}
public boolean isFocusable() {
// TODO Auto-generated method stub
return true;
}
};
_startDateLabelField.setFont(Global.arialFont_Plain_18);
_startTimeLabelField.setFont(Global.arialFont_Plain_18);
_endDateLabelField.setFont(Global.arialFont_Plain_18);
_endTimeLabelField.setFont(Global.arialFont_Plain_18);
HorizontalFieldManager endDateNTimeManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
Field f = getField(0);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
setPositionChild(f, 20, 30);
temp_mgr_Height = getPreferredHeightOfChild(f) +20;
f = getField(1);
layoutChild(f, getPreferredWidthOfChild(f) ,getPreferredHeightOfChild(f));
//setPositionChild(f, Global.Display_Width -70, 25);
setPositionChild(f, Global.Display_Width -120, 30);
setExtent(Global.Display_Width,/*temp_mgr_Height + 25*/ 70);
};
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.setFont(Global.arialFont_Bold_16);
graphics.drawText("End Date & Time", 10, 5);
graphics.drawRect(9, 25, 141, 30);
graphics.drawRect((Global.Display_Width - 151), 25, 141, 30);
graphics.drawRect(5, 1, getWidth()-10, getHeight()-2);
super.paint(graphics);
}
};
endDateNTimeManager.add(_endDateLabelField);
endDateNTimeManager.add(_endTimeLabelField);
/**
* Add Components to Screen
* */
LabelField searchByLocation = new LabelField("Search by Location")
{
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
super.paint(graphics);
}
};
searchByLocation.setFont(Global.arialFont_Bold_18);
insertSearchModeManager();
_workSpace.add(hfm_0);
searchByLocation.setMargin(5, 5, 5, 10);
_workSpace.add(searchByLocation);
_workSpace.add(hfm_1);
_workSpace.add(hfm_2);
_workSpace.add(hfm_3);
LabelField selectStartDateHeader = new LabelField("Select start date & end dates to check incidents in the future");
selectStartDateHeader.setFont(Global.arialFont_Bold_16);
selectStartDateHeader.setMargin(5, 5, 5, 10);
_workSpace.add(selectStartDateHeader);
insertDateSelectionManager();
startDateNTimeManager.setMargin(10, 0, 10, 0);
_workSpace.add(startDateNTimeManager);
_workSpace.add(endDateNTimeManager);
ButtonField btn_go = new ButtonField("Go" ,FIELD_HCENTER)
{
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
};
btn_go.setMargin(10, 0, 0, 10);
_workSpace.add(btn_go);
// add(_workSpace);
btn_go.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
invokeAISearch();
}
});
/**
* Status Manager
* */
insertStatusManager();
/**
* Very First time r1 = All days should be selected
* */
/*r1.setSelected(true);
invokeDays_Calculatio();*/
}
protected void invokeAISearch()
{ }
private String getAllDates()
{
String dateString = Global.EMPTY;
return dateString;
}
private String getStartDateTime()
{
String startDateString = Global.EMPTY;
return startDateString;
}
private String getEndDateTime() {
String endDateString = Global.EMPTY;
return endDateString;
}
private String getSeverity() {
String sevString = Global.EMPTY;
return sevString;
}
private void show_AI(final Vector v_temp)
{
}
private void insertSearchModeManager() {
ch1 = new CheckboxField("Severe", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch2 = new CheckboxField("Moderate", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch3 = new CheckboxField("Slight", true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
super.setExtent(getPreferredWidth(), height);
}
};
ch1.setFont(Global.arialFont_Plain_16);
ch2.setFont(Global.arialFont_Plain_16);
ch3.setFont(Global.arialFont_Plain_16);
HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(maxWidth, maxHeight);
setExtent(360, 50);
}
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.drawRect(5, 0, getWidth()-10, getHeight());
super.paint(graphics);
}
};
ch1.setMargin(0, 0, 0, 10);
ch2.setMargin(0, 0, 0, 20);
ch3.setMargin(0, 0, 0, 20);
dateSelectionManager.add(ch1);
dateSelectionManager.add(ch2);
dateSelectionManager.add(ch3);
LabelField selectStartDateHeader = new LabelField("Search by Severity");
selectStartDateHeader.setFont(Global.arialFont_Bold_16);
selectStartDateHeader.setMargin(5, 5, 5, 10);
_workSpace.add(selectStartDateHeader);
_workSpace.add(dateSelectionManager);
}
private void insertDateSelectionManager()
{
r1 = new CheckboxField( "All Dates" , true)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
r2 = new CheckboxField("Tomorrow",false)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
r3 = new CheckboxField("Next 7 days",false)
{
protected void layout(int width, int height) {
super.layout(getPreferredWidth(), height);
}
};
HorizontalFieldManager dateSelectionManager = new HorizontalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Global.Display_Width, 50);
setExtent(Global.Display_Width, 50);
}
protected void paint(Graphics graphics)
{
graphics.setColor(Color.BLACK);
graphics.drawRect(5, 0, getWidth()-10, getHeight());
super.paint(graphics);
}
};
r1.setFont(Global.arialFont_Plain_16);
r2.setFont(Global.arialFont_Plain_16);
r3.setFont(Global.arialFont_Plain_16);
r1.setMargin(0, 0, 0, 20);
r2.setMargin(0, 0, 0, 20);
r3.setMargin(0, 0, 0, 20);
dateSelectionManager.add(r1);
dateSelectionManager.add(r2);
dateSelectionManager.add(r3);
add(dateSelectionManager);
r1.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r1);
}
}
});
r2.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r2);
}
}
});
r3.setChangeListener(new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
if ( nonProgrammaticChange(context) )
{
invokeDays_Calculation(r3);
}
}
});
}
private boolean nonProgrammaticChange (int context) {
return (context & FieldChangeListener.PROGRAMMATIC) != FieldChangeListener.PROGRAMMATIC;
}
protected void invokeDays_Calculation(CheckboxField selectedField)
{
r1.setChecked(false);
r2.setChecked(false);
r3.setChecked(false);
if(selectedField.equals(r1))
{
togle_r1 = !togle_r1;
if(togle_r1)
{
r1.setChecked(true);
togle_r2 = false;
togle_r3 = false;
_startDateLabelField.setText("");
_startTimeLabelField.setText("");
_endDateLabelField.setText("");
_endTimeLabelField.setText("");
}
else
{
if(!togle_r1 && !togle_r2 && !togle_r3)
{
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
}
if(selectedField.equals(r2))
{
togle_r2 = !togle_r2;
if(togle_r2)
{
r2.setChecked(true);
togle_r1 = false;
togle_r3 = false;
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
++tDayStr;
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
if(selectedField.equals(r3))
{
togle_r3 = !togle_r3;
if(togle_r3)
{
r3.setChecked(true);
togle_r1 = false;
togle_r2 = false;
Calendar todaysDate = Calendar.getInstance();
int tDayStr = todaysDate.get(Calendar.DATE);
int tMonStr = todaysDate.get(Calendar.MONTH);
int tYearStr = todaysDate.get(Calendar.YEAR);
/**
* In Calendar class Month start form 0 thats why I incremented one time
* */
++tMonStr;
/*System.out.println("t Date "+tDayStr);
System.out.println("t Month "+tMonStr);
System.out.println("t Year "+tYearStr);*/
String startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_startDateLabelField.setText(startDateStr);
_startTimeLabelField.setText("00:00");
tDayStr += 7;
startDateStr = tDayStr+"/"+tMonStr+"/"+tYearStr;
_endDateLabelField.setText(startDateStr);
_endTimeLabelField.setText("23:59");
}
}
}
public void fieldChanged(Field field, int context) {
// TODO Auto-generated method stub
}
protected void street_Invoke()
{
}
protected void postCode_Invoke() {
}
void showStreetPopUp(final String[] street_Array)
{
}
public void showCarParkingStreetPopUp(final String[] postCode_Array)
{
}
public void updateStreetField(String strVal)
{
}
public void updatePostField(String strVal) {
}
public boolean onClose()
{
setDirty(false);
return super.onClose();
}
protected void sublayout(int width, int height)
{
super.sublayout(Global.Display_Width, Global.Display_Height + 100);
super.setExtent(Global.Display_Width, Global.Display_Height + 100);
}
protected void paint(Graphics graphics)
{
// TODO Auto-generated method stub
super.paint(graphics);
}
}
Note : the code is working fine in 5.0 OS but in 6.0 & 7.0 it creates problem.
Please let me know why I am getting the issue .

The problem is that you have made the app specific for a particular device on OS 5.0 which was obviously non-touch. Now on Touch devices, the sizes of buttons and checkboxes are much larger whereas you are trying to constrain them to smaller sizes. So the checkboxes will normally take whatever setextent you have done, but when focussed, they will try to make space for themselves which would disturb your screen layout. Remove the artificial constraining in the checkboxes and your immediate problem may get solved.
However, There are a LOT of issues in this code that may give rise to problems later.
Use of Screen.USE_ALL_HEIGHT will not make the take up the entire display.
You are unnecessarily overriding each and every field to somehow constrain their height. And you are doing it wrong. For example, in iaDescriptionEditField you have given full width for layout but then constrained its size. This will result in a the field not getting painted at the ends.
You have hardcoded widths and heights - including the fonts in pixels, this will make your app look very bad on high pixel density devices like the bold 3.
You are overriding a HorizontalFieldManager and then completely recreating the sublayout method. Better to simply extend the Manager class since you do not seem to using any facility of HorizontalFieldManager.
Remember that not all fields will give the correct getPreferredWidth/Height and you should only use these methods to make estimations during layout.
I would suggest that you rethink and rewrite your entire code after taking into account the different devices you would need to target. Use point based fonts and measurements instead of pixel based measurements.
All the best.

Related

How can i select a drop down which i added over a list field?

Hi Friend's in my BlackBerry Application i use a list Field, and over this list Field i add a drop down. Now my problem is how do i select the drop down which i added over the list Field.Now i only select list field and not the drop down but my requirement is first i should select the drop down and then list field. I have included my code here please check it.
public class TaskListField extends ListField implements ListFieldCallback, KeypadListener {
private Vector rows;
private Bitmap p1;
private Bitmap p2;
public LoginPage objLoginPage;
public String[] data={"Call","Visit"};
public String strIndex = null;
public int tempIndex = 0;
public int intvalue;
public int id;
public int value;
public boolean hasFocus = false;
public static String[] arrOutletName = { "Dosa Store", "Benfish Bhawan",
"Nalban Park", "Korunamoyee", "206 Bus Stop", "aaaaaaaa",
"bbbbbbbb", "ccccccccc", "dddddddd", "eeeeeee" };
public ObjectChoiceField ocf;
public TaskListField() {
super(0, ListField.MULTI_SELECT);
setRowHeight(80);
setEmptyString("Hooray, no tasks here!", DrawStyle.HCENTER);
setCallback(this);
p1 = Bitmap.getBitmapResource("name.png");
p2 = Bitmap.getBitmapResource("name.png");
rows = new Vector();
for (int x = 0; x < XmlHander.vectSrno.size(); x++) {
TableRowManager row = new TableRowManager();
strIndex = String.valueOf(x);
String strVectno = XmlHander.vectSrno.elementAt(x).toString();
String strSLADate = XmlHander.vectSldate.elementAt(x).toString();
if (x % 2 == 0) {
row.add(new BitmapField(null));
}
else {
row.add(new BitmapField(null));
}
LabelField task = new LabelField(" ");
if (x % 15 == 0) {
task.setFont(Font.getDefault().derive(Font.BOLD | Font.UNDERLINED));
} else {
task.setFont(Font.getDefault().derive(Font.BOLD));
}
row.add(task);
row.add(new LabelField(strVectno, DrawStyle.ELLIPSIS) {
protected void paint(Graphics graphics) {
graphics.setColor(0x00878787);
// graphics.setColor(Color.PINK);
super.paint(graphics);
}
});
row.add(ocf=new ObjectChoiceField("",data){
protected void paint(Graphics graphics){
graphics.setColor(0x00878787);
super.paint(graphics);
}
});
ocf.setChangeListener(new FieldChangeListener(){
public void fieldChanged(Field field, int context) {
if(context != PROGRAMMATIC)
Dialog.alert(data[ocf.getSelectedIndex()]);
}
});
rows.addElement(row);
}
setSize(rows.size());
}
public void drawListRow(ListField listField, Graphics g, int index, int y, int width) {
TaskListField list = (TaskListField) listField;
TableRowManager rowManager = (TableRowManager) list.rows.elementAt(index);
rowManager.drawRow(g, 0, y, width, list.getRowHeight());
}
private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x00CACACA);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 32, 32);
setPositionChild(field, 0, 0);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 34, 3);
field = getField(2);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, 34, fontHeight + 6);
field = getField(3);
layoutChild(field, 150, fontHeight + 1);
setPositionChild(field, preferredWidth - 152, fontHeight + 6);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return 0;
}
public int indexOfList(ListField listField, String prefix, int start) {
return 0;
}
protected boolean navigationClick(int status, int time) {
final int index;
index = this.getFieldWithFocusIndex() - 1;
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(new Details(id));
}
});
return false;
}
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
id = this.getSelectedIndex();
invalidate();
return super.moveFocus(amount, status, time);
}
public void onFocus(int direction) {
hasFocus = true;
super.onFocus(direction);
System.out.println("direction==" + direction);
invalidate();
}
public void onUnfocus() {
updateLayout();
super.onUnfocus();
invalidate();
}
private int getFieldWithFocusIndex() {
return 0;
}
}

how to create three edit fileds in horizontal field manager in blackberry

How to create three editfields like this
HorizontalFieldManager hfm_city=new HorizontalFieldManager();
VerticalFieldManager vfm_city = new VerticalFieldManager();
vfm_city.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_city.setMargin(0, 200, 0, 0);
final EditField city = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "City";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_city.add(city);
VerticalFieldManager vfm_state = new VerticalFieldManager();
vfm_state.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_state.setMargin(0, 0, 0, 0);
final EditField state = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "State";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_state.add(state);
VerticalFieldManager vfm_zip = new VerticalFieldManager();
vfm_zip.setBorder(
BorderFactory.createBitmapBorder(
new XYEdges(12,12,12,12), borderBitmap
)
);
vfm_zip.setMargin(0, 0, 0, 0);
final EditField zip = new EditField("", "", 30, BasicEditField.FILTER_DEFAULT){
String emptyString = "Zip";
protected void paintBackground(Graphics g) {
g.setBackgroundColor(0xFFFFFF);
g.clear();
}
protected void paint(Graphics g) {
int oldColor = g.getColor();
try {
g.setColor(0x000000);
test = super.getText();
if ( test == null || test.length() < 1 ) {
//g.setColor(Config.hint_colour);
g.drawText(emptyString, 0, 0);
}
super.paint(g);
} finally {
g.setColor(oldColor);
}
}
};
vfm_zip.add(zip);
hfm_city.add(vfm_city);
hfm_city.add(vfm_state);
hfm_city.add(vfm_zip);
You are going in the right way. but you have to give specific width & height to yourVerticalFieldManager otherwise it will take full width by default.
VerticalFieldManager vfm_city = new VerticalFieldManager() {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getwidth()/3,30);
setExtent(Display.getwidth()/3,30);
}
};
Do this in your State & city vfm and add in your hfm and try.
Check my answer
{
Border bdr = BorderFactory.createRoundedBorder(new XYEdges(4, 4, 4, 4),Border.STYLE_SOLID);
VerticalFieldManager vert=new VerticalFieldManager()
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
HorizontalFieldManager hr=new HorizontalFieldManager(USE_ALL_HEIGHT)
{
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),50);
setExtent(Display.getWidth(),50);
}
};
hr.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
EditField e1=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(100,30);
setExtent(100,30);
}
};
EditField e2=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
EditField e3=new EditField(Field.FOCUSABLE|Field.FIELD_VCENTER){
protected void layout(int width, int height) {
super.layout(60,30);
setExtent(60,30);
}
};
e1.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e2.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e3.setBackground(BackgroundFactory.createSolidBackground(Color.WHITE));
e1.setPadding(0, 0, 0, 10);
e2.setPadding(0, 0, 0, 20);
e3.setPadding(0, 0, 0, 10);
e1.setBorder(bdr);
e2.setBorder(bdr);
e3.setBorder(bdr);
hr.add(e1);
hr.add(e2);
hr.add(e3);
vert.add(hr);
add(vert);
}

center object in GridFieldManager on blackberry

I want to center the objects in the GridFieldManager. This can be seen from the selected image in the blue zone like in the first picture. How can I center these objects (text+picture)???
This is my code
VerticalFieldManager manager = (VerticalFieldManager) getMainManager();
gfm = new GridFieldManager(rows, columns, GridFieldManager.FIXED_SIZE);
manager.add(gfm);
int columnWidth = (Display.getWidth() / columns)
- gfm.getColumnPadding();
for ( i = 0; i < columns; i++) {
gfm.setColumnProperty(i, GridFieldManager.FIXED_SIZE, columnWidth);
}
BitmapField[] images = new BitmapField[6];
EncodedImage Icon = null;
for (i = 0; i < 6; i++) {
Icon = EncodedImage
.getEncodedImageResource("img/HOME.png");
images[i] = new BitmapField(Icon.getBitmap(), Field.FIELD_HCENTER
| Field.FIELD_VCENTER | Field.FOCUSABLE) {
protected void layout(int width, int height) {
setExtent(getPreferredWidth()+20, getPreferredHeight() + 15);
}
protected void paint(Graphics graphics) {
super.paint(graphics);
graphics.drawText("text", 0,
getBitmapHeight(), 2, getBitmapWidth() + 20);
}
};
gfm.setPadding(10, 0, 0, 0);
gfm.setRowPadding(20);
images[i].setPadding(20, 10, 5, 10);
gfm.add(images[i]);
}
}
Try this sample code:
public class PictureScreen extends MainScreen implements FieldChangeListener
{
static EditField editField;
private Bitmap lockBit;
private BitmapField bitmapField[];
private int size=0, i=0;;
public PictureScreen()
{
lockBit=Bitmap.getBitmapResource("HOME.png");
size=10;
createGUI();
}
private void createGUI()
{
bitmapField=new BitmapField[size];
HorizontalFieldManager hr=null;
for(i=0;i<size;i=i+3)
{
hr=new HorizontalFieldManager(Field.FIELD_HCENTER);
for(int j=i;j<i+3;j++) //Here I am taking 3 images per line(Horizontal Manager);
{
if(j<size)
{
final String _label="Text: "+(j+1);
bitmapField[j]=new BitmapField(null,Field.FOCUSABLE)
{
protected void layout(int width, int height)
{
setExtent( 100,100);
}
protected void paint(Graphics g)
{
g.drawBitmap(50-24, 0,lockBit.getWidth(), lockBit.getHeight(), lockBit, 0, 0); //Here 24= image width is 48pixel so,48/2 and 50=setExtent( 100,100); width=100/2;
g.setFont(Font.getDefault().derive(Font.BOLD|Font.ITALIC, 18));
g.drawText(_label, 50-24, 50);
super.paint(g);
}
};
bitmapField[j].setChangeListener(this);
bitmapField[j].setPadding(10, 10, 10, 10);
hr.add(bitmapField[j]);
}
}
add(hr);
}
}
public void fieldChanged(Field field, int context)
{
for(int i=0;i<size;i++)
{
if(field==bitmapField[i])
{
Status.show("Buy the Full Version", 500);
}
}
}
}
Then I got like this:
Try this and see the comments in the class;
I thinks your image is not in center and its Transparent area is not align properly . If you want to do this in easy way than it have to use PictureBackgroundButtonField Custom class. In this class you can handle focus and unfocus using tow different images . Below is the class .
package com.picturebackgroundbuttonfield;
import net.rim.device.api.ui.*;
import net.rim.device.api.system.*;
public class PictureBackgroundButtonField extends Field
{
private String _label;
private int _labelHeight;
private int _labelWidth;
private Font _font;
private Bitmap _onPicture, _offPicture;
private Bitmap _currentPicture;
public PictureBackgroundButtonField(Bitmap onFocus, Bitmap offFocus, String text, long style)
{
super(style);
_onPicture = onFocus;
_offPicture = offFocus;
_font = getFont();
_label = text;
_labelHeight = _onPicture.getHeight();
_labelWidth = _onPicture.getWidth();
_currentPicture = _offPicture;
}
/**
* #return The text on the button
*/
String getText()
{
return _label;
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#getPreferredHeight()
*/
public int getPreferredHeight()
{
return _labelHeight;
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#getPreferredWidth()
*/
public int getPreferredWidth()
{
return _labelWidth;
}
/**
* Field implementation. Changes the picture when focus is gained.
* #see net.rim.device.api.ui.Field#onFocus(int)
*/
protected void onFocus(int direction)
{
_currentPicture = _onPicture;
// setFont(getFont().derive(Font.BOLD));
invalidate();
}
/**
* Field implementation. Changes picture back when focus is lost.
* #see net.rim.device.api.ui.Field#onUnfocus()
*/
protected void onUnfocus()
{
_currentPicture = _offPicture;
// setFont(getFont().derive(Font.PLAIN));
invalidate();
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#drawFocus(Graphics, boolean)
*/
protected void drawFocus(Graphics graphics, boolean on)
{
// Do nothing
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#layout(int, int)
*/
protected void layout(int width, int height)
{
setExtent(Math.min( width, getPreferredWidth()),
Math.min( height, getPreferredHeight()));
}
/**
* Field implementation.
* #see net.rim.device.api.ui.Field#paint(Graphics)
*/
/**
* Overridden so that the Event Dispatch thread can catch this event
* instead of having it be caught here..
* #see net.rim.device.api.ui.Field#navigationClick(int, int)
*/
protected boolean navigationClick(int status, int time)
{
fieldChangeNotify(1);
return true;
}
/*protected void paint(Graphics graphics) {
// TODO Auto-generated method stub
}*/
protected void paint(Graphics graphics)
{
graphics.drawBitmap(0, 0, getWidth(), getHeight(), _currentPicture, 0, 0);
graphics.setBackgroundColor(Color.BLACK);
graphics.drawText(_label, 2, 0,
(int)( getStyle() & DrawStyle.ELLIPSIS | DrawStyle.HALIGN_MASK ),
getWidth() - 6 );
}
}

BlackBerry - How to add clickEvent (setChangeListener) to ListField in BlackBerry?

I'm using ListField in Blackberry and unable to apply the row.setChangeListener.
Can anybody please help me?
Here is my code,
Friendship objFriendship = new Friendship();
friends = objFriendship.FetchFriends(AATTGlobals.CURRENT_USER.getUserID());
rows = new Vector();
for (int x = 0; x < friends.length; x++) {
String UserName = friends[x].getUserName();
ProfilePicture = MISC.FetchUserProfilePicture(friends[x].getProfilePicturePath());
String Location = friends[x].getLocation();
TableRowManager row = new TableRowManager();
row.add(new BitmapField(ProfilePicture));
LabelField task = new LabelField(UserName,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
};
task.setFont(Font.getDefault().derive(Font.BOLD));
row.add(task);
row.add(new LabelField(Location,DrawStyle.ELLIPSIS)
{
protected void paint(Graphics graphics) {
graphics.setColor(0x0099CCFF);
super.paint(graphics);
}
}
);
row.setChangeListener( new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
Dialog.alert("Row Clicked #");
}
});
No any error message but setChangeListener doesn't fire, here is TableRowManager
Private class TableRowManager extends Manager {
public TableRowManager() {
super(0);
}
public void drawRow(Graphics g, int x, int y, int width, int height) {
layout(width, height);
setPosition(x, y);
g.pushRegion(getExtent());
subpaint(g);
g.setColor(0x0099CCFF);
g.drawLine(0, 0, getPreferredWidth(), 0);
g.popContext();
}
protected void sublayout(int width, int height) {
int fontHeight = Font.getDefault().getHeight();
int preferredWidth = getPreferredWidth();
Field field = getField(0);
layoutChild(field, 44, 44);
setPositionChild(field, 10, getRowHeight() / 4);
field = getField(1);
layoutChild(field, preferredWidth - 16, fontHeight + 1);
setPositionChild(field, 70, getRowHeight() / 5);
field = getField(2);
layoutChild(field, field.getPreferredWidth(), fontHeight + 1);
setPositionChild(field, 70, (getRowHeight() / 2) + 5);
setExtent(preferredWidth, getPreferredHeight());
}
public int getPreferredWidth() {
return Graphics.getScreenWidth();
}
public int getPreferredHeight() {
return getRowHeight();
}
}
in tableRowManager add this
//for non touch
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
//for touch
protected boolean touchEvent(TouchEvent message) {
if (TouchEvent.CLICK == message.getEvent()) {
FieldChangeListener listener = getChangeListener();
if (null != listener)
listener.fieldChanged(this, 1);
}
return super.touchEvent(message);
}
try this let me know is it working or not.
I noticed, fieldChangeLister/FieldChanged isnt getting called with ListField UI [as it works for button and labels.]So I think FieldChanged is not supported with Listfield
In navigationClick/TouchEvent (), write the action you are writing in FieldChange method.

how to use image for text field - j2me blackberry

I am using an image for text field.
When I focus on it to write something the first letter of the text that I write gets half cut.
How to avoid that?
My code is:
textbox = new EditField(EditField.NO_NEWLINE)
{
protected void layout(int width, int height)
{
super.layout(1000, 38);
super.setExtent((Display.getWidth()),30);
}
}
manager = new VerticalFieldManager(HORIZONTAL_SCROLL)
{
protected void paint(Graphics g)
{
int x = this.getHorizontalScroll();
g.drawBitmap( x, 0,textbox.getWidth(),textboxc.getHeight(),textbox, 0, 0 );
super.paint(g);
}
protected void sublayout(int maxWidth, int maxHeight)
{
Field field = testbox;
layoutChild(field, Display.getWidth(), Display.getHeight());
setPositionChild(field, 148, 8);
super.sublayout(maxWidth, maxHeight);
}
}
manager.add(textbox);
textbox= new EditField(" ","",500,EditField.NO_NEWLINE | Field.FOCUSABLE)
{
protected void paint(Graphics g)
{
g.setColor(Color.MAROON);
super.paint(g);
}
protected boolean keyChar(char key, int status, int time)
{
return super.keyChar(key, status, time);
}
};
manager = new VerticalFieldManager(HORIZONTAL_SCROLL )
{
protected void paint(Graphics g)
{
int x = this.getHorizontalScroll();
if(textbox.getText().equals(""))
{
g.drawBitmap( x, 0, textbox_img.getWidth(), textbox_img.getHeight(), textbox_img, 0, 0 );
}
super.paint(g);
}
}
manager.add(textbox);

Resources