Tidying Up the Login Success Screen
Now that we've got a few components, let's revisit LoginSuccessScreen. With some simple modifications to the constructor to use our CustomLabelField and GridFieldManager, we can make the screen look a little better.
public LoginSuccessScreen(String username, String domain) { try {
FontFamily alphaSansFamily = FontFamily.forName("BBAlpha Serif"); Font appFont = alphaSansFamily.getFont(Font.PLAIN, 9, Ui.UNITS_pt); setFont(appFont);
} catch (ClassNotFoundException e) { }
add(new CustomLabelField("Logged In!", Color.WHITE, 0x999966, Field.USE_ALL_WIDTH));
add(new SeparatorField());
GridFieldManager gridFieldManager = new GridFieldManager(2, 0); gridFieldManager.add
(new CustomLabelField("Username:", Color.BLACK, Color.WHITE, Field.FIELD_RIGHT));
gridFieldManager.add
(new CustomLabelField(username, Color.BLACK, Color.LIGHTGREY, Field.USE_ALL_WIDTH));
gridFieldManager.add
(new CustomLabelField("Domain:", Color.BLACK, Color.WHITE, Field.FIELD_RIGHT));
gridFieldManager.add
(new CustomLabelField(domain, Color.BLACK, Color.LIGHTGREY, Field.USE_ALL_WIDTH));
add(gridFieldManager);
Here, we've moved the username and domain labels and values into a grid, similar to our main screen. Notice that we've given the right column labels the Field.USE_ALL_WIDTH value, which, in combination with the sublayout method of the grid field manager, will make them use the entire screen width except for the space taken by the first column. Go back and see if you can figure out why, and try to figure out what would happen if we applied Field.USE_ALL_WIDTH to the labels for the first column.
The screen with the constructor provided in this section will look something like Figure 5-23.
Username :hannah
Domain: Work
Username :hannah
Domain: Work
- Figure 5-23. The redone login success screen
Now, you should be familiar with how to make fields and managers. That leaves one more piece of the visual BlackBerry user interface to cover before we're finished this chapter—screens.
Post a comment