_app = app;
// Initialize UI components
setTitle("MMS Demo");
_addressField =
new EditField("Destination:", "", MAX_PHONE_NUMBER_LENGTH,
BasicEditField.FILTER_PHONE);
add(_addressField);
add(new SeparatorField());
_subjectField = new EditField("Subject:", "");
add(_subjectField);
_messageField = new EditField("Message:", "");
add(_messageField);
add(new SeparatorField());
final LabelField attachmentText = new LabelField("Attachments");
add(attachmentText);
// Create table components
_view = new TableView(_app.getMessageParts());
final TableController controller =
new TableController(_app.getMessageParts(), _view);
controller.setFocusPolicy(TableController.ROW_FOCUS);
_view.setController(controller);
// Set the highlight style for the view
_view.setDataTemplateFocus(BackgroundFactory
.createLinearGradientBackground(Color.LIGHTBLUE,
Color.LIGHTBLUE, Color.BLUE, Color.BLUE));
// Create a data template that will format the model data as an array of
// LabelFields
final DataTemplate dataTemplate = new DataTemplate(_view, 1, 1) {
public Field[] getDataFields(final int modelRowIndex) {
final MessagePart message =
(MessagePart) _app.getMessageParts().getRow(
modelRowIndex);
final Field[] fields =
{ new LabelField(message.getContentLocation(),
Field.NON_FOCUSABLE | DrawStyle.ELLIPSIS) };
return fields;
}
};
// Define the regions of the data template and column/row size
dataTemplate.createRegion(new XYRect(0, 0, 1, 1));
dataTemplate.setColumnProperties(0, new TemplateColumnProperties(
Display.getWidth()));
dataTemplate.setRowProperties(0, new TemplateRowProperties(24));
_view.setDataTemplate(dataTemplate);
dataTemplate.useFixedHeight(true);
// Add the file to the screen
add(_view);
_status = new EditField();
add(_status);
// Menu item to attach a picture to the MMS
final MenuItem attachPicture =
new MenuItem(new StringProvider("Attach Picture"), 0x230010, 0);