08-30-2012 01:03 PM
Hi all;
This is my first post and I'm a bit of newb when it comes to app development --- but not to coding in general.
I have inherited a project from someone who no longer works in my company. It is in an unfinished state and I am having some trouble debugging a nagging issue.
The elements on the screen are set up using an Absoloute Field Manager to display things at specific X,Y coordinates, several of these elements are outside the visable range of the device. Using the JDE simulator I can see it looks fine on the 9900, but not on the 9700 which has a lower screen resoloution.
I would expect that when I reached the bottom of the page on the 9700 it would scroll down, but alas I can't get past the bottom, which is to say I can't see the bottom portion of the application where several important buttons and UI controls are.
The buttons exist and are clickable (one of them is a reset and I can move to it and the reset functionallity is working).
As far as I can see nothing was overridden in the AbsoluteFieldManager (just a standard AbsoluteFieldManager manager = new AbsoluteFieldManager() declaration and then various adds). Below is the display method.
Any and all help would be greatly appreciated.
public class display extends MainScreen {
//Loop counters
int i=0;
int k=0;
//Semester GPA
double gpa;
//Layout Manager
AbsoluteFieldManager manager = new AbsoluteFieldManager()
//Set the color of the screen
Background bg = BackgroundFactory.createSolidBackground(Color.LIGH TSTEELBLUE);
//Screen placement constants all numbers are in pixels (px) format
final static int topbase=40; //Space from top of screen to start of fields
final static int bottombase=360; //How far down from top to start results fields
final static int bottomheight=360;
final static int course_offset=5; //How far from the left of screen do we start the text field
final static int credit_offset=355; //How far from the left of screen do we start the credit drop down
final static int grade_offset=200; //How far from the left of screen do we start the grades drop down
final static int result_offset=275; //How far from the left of screen do we start the results text fields
final static int fieldsize=8; //How many text fields and drop down boxs there are for each categoty
final static int resultsize=3; //How many text fields used for the results area
String gradearr[] = {" ", "A", "&A", "A-", "&A-", "B+", "&B+", "B", "&B", "B-", "&B-", "C+", "&C+",
"C", "&C", "D","F", "#F", "#FI","FIN","WU","#WU","INC","AUD","P","W","@A","@ A-","*A","*A-",
"@B+","@B","@B-","*B+","*B","*B-","@C+","@C","*C+" ,"*C","@D","@P"}; //All possible grades
String credarr[] = {"0", "1", "2", "3", "4", "5", "6", "7", "8"}; //All possible grades
//Object variables for the fields on screen
CustomDrop grades[] = new CustomDrop[fieldsize]; //An array of drop down boxs
CustomDrop credit[] = new CustomDrop[fieldsize]; // An array of drop down boxs
CustomText course[] = new CustomText[fieldsize]; // An array of text fields
CustomText result[] = new CustomText[resultsize]; // An array of text fields
//Labels & Prewritten text
LabelField courses = new LabelField("COURSE",Field.FOCUSABLE);
LabelField credits = new LabelField("CREDITS",Field.FOCUSABLE);
LabelField grade = new LabelField("GRADE",Field.FOCUSABLE);
LabelField qualitypts = new LabelField("QUALITY POINTS",Field.FOCUSABLE);
LabelField attmptcred = new LabelField("ATTEMPTED CREDITS", Field.FOCUSABLE);
LabelField avg = new LabelField("FINAL GPA",Field.FOCUSABLE);
//Buttons for actions and calculation
ButtonField submit=new ButtonField("Calculate",Field.FOCUSABLE); //Calculate the GPA
ButtonField reset=new ButtonField("Reset",Field.FOCUSABLE);// Clear the Screen
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field e, int context)
{
if(e==reset) //We pushed reset
{
for(i=0; i<fieldsize; i++) //reset all values
{
course[i].setText("");
grades[i].setSelectedIndex(0);
credit[i].setSelectedIndex(0);
}
for(i=0; i<resultsize; i++)
result[i].setText("");
} //end reset pushed
else //we pushed calculate
{
//Default values
int attmpcred=0; //Attempted credits
double qualitypoints=0.0; //quality points
//Add all of the credits into the count
for(i=0; i<fieldsize; i++)
attmpcred=attmpcred + Integer.parseInt(credit[i].getChoice(credit[i].get SelectedIndex()).toString());
for(i=0; i<fieldsize; i++)
{
//-1.0 is used here as a bypass. If we see a -1.0, we remove the credits associated with it
//From the total attempted credits because they do not count towards it
//We also do add any quality points
if(getval(grades[i])==-1.0)
attmpcred = attmpcred - Integer.parseInt(credit[i].getChoice(credit[i].get SelectedIndex()).toString());
else//If not a -1.0, add the quality points to the whole
qualitypoints=qualitypoints + getval(grades[i]) * Integer.parseInt(credit[i].getChoice(credit[i].get SelectedIndex()).toString());;
}
gpa = qualitypoints/attmpcred; //Definition of GPA is qualitypoints/attmpcred
gpa = roundDouble(gpa,3); //round to 3 places
qualitypoints= roundDouble(qualitypoints,1); //round to 1 place
for(i=0; i<resultsize; i++) //set the results of each field to display the correct information
{
if(i==0)
result[i].setText(Integer.toString(attmpcred));
if(i==1)
result[i].setText(Double.toString(qualitypoints));
if(i==2)
result[i].setText(Double.toString(gpa));
}
}
} //end calculate pushed
};
//This function returns a numerical value which is associated with each grade.
//Values which are -1.0, are returned as an indicator that they are not to be added into our final calculation
private double getval (CustomDrop c)
{
if(c.getChoice(c.getSelectedIndex())=="A" || c.getChoice(c.getSelectedIndex())=="&A")
return 4.0;
else if(c.getChoice(c.getSelectedIndex())=="A-" || c.getChoice(c.getSelectedIndex())=="&A-")
return 3.7;
else if(c.getChoice(c.getSelectedIndex())=="B+" || c.getChoice(c.getSelectedIndex())=="&B+")
return 3.3;
else if(c.getChoice(c.getSelectedIndex())=="B" || c.getChoice(c.getSelectedIndex())=="&B")
return 3.0;
else if(c.getChoice(c.getSelectedIndex())=="B-" || c.getChoice(c.getSelectedIndex())=="&B-")
return 2.7;
else if(c.getChoice(c.getSelectedIndex())=="C+" || c.getChoice(c.getSelectedIndex())=="&C+")
return 2.3;
else if(c.getChoice(c.getSelectedIndex())=="C" || c.getChoice(c.getSelectedIndex())=="&C")
return 2.0;
else if(c.getChoice(c.getSelectedIndex())=="D")
return 1.0;
else if(c.getChoice(c.getSelectedIndex())=="F" || c.getChoice(c.getSelectedIndex())=="FIN" || c.getChoice(c.getSelectedIndex())=="WU")
return 0.0;
else if(c.getChoice(c.getSelectedIndex()).toString().st artsWith("#")) //Variables starting with a "#" all have same value (0.0)
return 0.0;
//Special cases
else if(c.getChoice(c.getSelectedIndex())=="INC" || c.getChoice(c.getSelectedIndex())=="AUD" || c.getChoice(c.getSelectedIndex())=="P" || c.getChoice(c.getSelectedIndex())=="W")
return -1.0;
//Variables starting with a "@" or a "*" all have the same value (-1.0)
else if(c.getChoice(c.getSelectedIndex()).toString().st artsWith("@") || c.getChoice(c.getSelectedIndex()).toString().start sWith("*"))
return -1.0;
else
return 0.0; //if we didn't select anything
}
//This function rounds the value d, to the amount of places after the decimal specified.
//I.E. roundDouble(1.2356,2) will return (1.24)
public static final double roundDouble(double d, int places) {
return MathUtilities.round(d * MathUtilities.pow(10, (double) places)) / MathUtilities.pow(10,(double) places);
}
//Default Constructor for Display
display()
{
super(MainScreen.VERTICAL_SCROLL);
manager.setBackground(bg); // Set BG Color
setTitle("GPA CALC");
for(i=0; i<fieldsize; i++)
{
grades[i] = new CustomDrop(); //Initialize each variable
grades[i].setChoices(gradearr); //Add all possible choices to this drop down menu
//Assign on screen position
manager.add(grades[i],grade_offset,((topbase)*(i+1 )));
}
for(i=0; i<credit.length; i++)
{
credit[i] = new CustomDrop(); //Initialize each variable
//Assign on screen position
manager.add(credit[i],credit_offset,((topbase)*(i+ 1)));
//Add all possible choices to this drop down menu
for(k=0; k<=fieldsize; k++)
credit[i].setChoices(credarr);
}
for(i=0; i<course.length; i++)
{
course[i] = new CustomText(); //Initialize each variable
//Assign on screen position
course[i].setMaxSize(8); // 8 characters
manager.add(course[i],course_offset,((topbase)*(i+ 1)));
}
for(i=0; i<result.length; i++)
{
result[i] = new CustomText(); //Initialize each variable
//Assign on screen position
if(i==0)
manager.add(result[i],result_offset, bottomheight);
else
manager.add(result[i],result_offset, (bottomheight+(i*40)));
result[i].setEditable(false); //Disable user input for result fields
}
//Setting the labels position on screen
manager.add(courses,course_offset, 0);
manager.add(grade,grade_offset+5, 0); //Offset 5 for field edge
manager.add(credits,credit_offset+5, 0); //Offset 5 for field edge
manager.add(attmptcred,0, bottomheight);
manager.add(qualitypts,0,bottomheight+40);
manager.add(avg,0,bottomheight+80);
//Setting the buttons position on screen
manager.add(submit,425, bottombase);
manager.add(reset,425, bottombase+50);
//Enable submit button, place on screen and add action listner
submit.setEnabled(true);
submit.setChangeListener(listener);
// Enable reset button, place on screen and add action listner
reset.setEnabled(true);
reset.setChangeListener(listener);
add(manager); // Add Manager Layout to the Screen
} //end init
}
08-30-2012 01:17 PM - edited 08-30-2012 01:18 PM
I'm not sure how AbsoluteManager and vertical scroll work together, but in your example the scrolling is done in the MainScreen, not the manager. Try doing it the other way around - create the screen with NO_VERTICAL_SCROLL (change the first line in screen's constructor) and the AbsoluteManager with VERTICAL_SCROLL. AbsoluteManager was added quite recently and is a strange beast overall, so I won't be surprised if such tinkering actually works. ![]()
Edit: Oh, and welcome to the forums!
08-30-2012 02:35 PM
It appears the AbsoluteFieldManager constructor is dissimilar from the others. It doesn't have a format for style_bits akin to VERTICAL_SCROLL.
In fact that default constructor takes no paramters....how would I set the Scroll type? Would I need to overwrite the sublayout in some way?
08-30-2012 03:57 PM
Oops... That's true, it is a different beast. You'll have to go with the screen's vertical scroll.
Some ideas on how to proceed:
You might want to play with nextFocus override to make sure that the proper fields receive focus. As the first step, override it to call super.nextFocus and save the return value, then return that value. Then you can put a break point on the return statement and see that the focus changes properly (or maybe it doesn't). You can also call getFocusRect there and make sure that the returned focus rectangle is correct (it will still report the previously focused field, I believe, which is something you can also check - see getFieldWithFocus and similar methods).
Once you get the hang of what is going on there, try to implement your own control over focus movements and see if it changes things.
Good luck - you'll need it!
08-30-2012 04:03 PM
After I posed the initial question, I was searching through the forums for similar issues, and found this thread: http://supportforums.blackberry.com/t5/Java-Develo
I wound up overwrting the sublayout of the fieldmanager so it now looks like:
AbsoluteFieldManager manager = new AbsoluteFieldManager()
{
protected void sublayout(int width, int height)
{
super.sublayout(width, height); // necessary to layout all the fields
int totalWidth = 0;
int totalHeight = 0;
XYRect fieldExtent = new XYRect();
for (int i = 0; i < getFieldCount(); ++i)
{
getField(i).getExtent(fieldExtent);
totalWidth = Math.max(totalWidth, fieldExtent.X2());
totalHeight = Math.max(totalHeight, fieldExtent.Y2());
}
setExtent(Math.min(width, totalWidth), Math.min(height, totalHeight));
setVirtualExtent(totalWidth, totalHeight);
}Which goto me 95% of the way there. After I ran with those changes, the sreen scrolled down but not across. I then altered the original display constructor to invoke (HORIZONTAL_SCROLL) and that seemed to do the trick. The screen now scrolls to the southern edge of the bottom box and the right most edge, but not off to infinity like I had seen in other examples (MAX >> 1 being the common answer)
So directly / indirectly you were a big help ![]()
Thanks!