/** Create a new GPSDemoAdvanced object */
  public GPSDemoAdvanced() {
    final MainScreen screen = new MainScreen();

    // Initialize UI components
    screen.setTitle("GPS Advanced Demo");
    final LabelField apiChoiceMessage =
        new LabelField("Please select an API to test:", Field.USE_ALL_WIDTH | Field.FIELD_HCENTER);
    _coreTestButton =
        new ButtonField("Core GPS API Test", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
    _extendedTestButton =
        new ButtonField(
            "Extended GPS API Test", ButtonField.NEVER_DIRTY | ButtonField.CONSUME_CLICK);
    _coreTestButton.setChangeListener(this);
    _extendedTestButton.setChangeListener(this);

    screen.add(apiChoiceMessage);
    screen.add(_coreTestButton);
    screen.add(_extendedTestButton);
    pushScreen(screen);
  }
 /**
  * Processes a new HttpConnection object to instantiate a new browser Field (aka WebView) object,
  * and then resets the screen to the newly-created Field.
  *
  * @param connection
  * @param e
  */
 public void processConnection(HttpConnection connection, Event e) {
   // Cancel previous request.
   if (_currentConnection != null) {
     try {
       _currentConnection.close();
     } catch (IOException e1) {
     }
   }
   // Clear out pending responses.
   synchronized (pendingResponses) {
     pendingResponses.removeAllElements();
   }
   // Cancel any XHRs happening.
   commandManager.stopXHR();
   _currentConnection = connection;
   BrowserContent browserContent = null;
   Field field = null;
   try {
     browserContent = _renderingSession.getBrowserContent(connection, this, e);
     if (browserContent != null) {
       field = browserContent.getDisplayableContent();
       if (field != null) {
         synchronized (Application.getEventLock()) {
           _mainScreen.deleteAll();
           _mainScreen.add(field);
         }
       }
       browserContent.finishLoading();
     }
   } catch (RenderingException re) {
   } finally {
     browserContent = null;
     field = null;
     // Manually call the garbage collector to clean up all of leftover objects and free up the
     // nulled object handles.
     System.gc();
   }
 }
  public TaskScreen(Task task) {
    super(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);

    internalManager =
        new VerticalFieldManager(Manager.NO_VERTICAL_SCROLL | Manager.NO_VERTICAL_SCROLLBAR);
    super.add(internalManager);
    internalManager.add(new TitleField(TaskUtils.getPath(task)));

    manager = new VerticalFieldManager(Manager.VERTICAL_SCROLL | Manager.VERTICAL_SCROLLBAR);
    internalManager.add(manager);

    this.task = task;

    Font bold = getFont().derive(Font.BOLD);

    HeaderLabel name = new HeaderLabel(task.getName());
    name.setFont(bold);
    RichTextField description =
        new RichTextField(task.getDescription()) {
          public void paint(Graphics graphics) {
            graphics.setColor(0x00777777);
            super.paint(graphics);
          }
        };

    add(name);

    if (task.getPriority() != Task.NORMAL_PRIORITY) {
      BitmapInput priority =
          new BitmapInput(
              "Priority",
              task.getPriority() == Task.LOW_PRIORITY ? "low_priority.png" : "high_priority");
      priority.setEditable(false);
      priority.setSelected(task.getPriority());
      add(priority);
    }

    String statusRes = "";
    switch (task.getStatus()) {
      case Task.NOT_STARTED:
        statusRes = ("not_started.png");
        break;
      case Task.IN_PROGRESS:
        statusRes = ("progress.png");
        break;
      case Task.WAITING:
        statusRes = ("waiting.png");
        break;
      case Task.DEFERRED:
        statusRes = ("deferred.png");
        break;
      case Task.COMPLETED:
        statusRes = ("completed.png");
        break;
    }
    status = new BitmapInput("Status", statusRes);
    status.setEditable(false);
    status.setSelected(task.getStatus());
    add(status);

    percent_complete =
        new BitmapInput(
            "Percent Complete", task.getPercentComplete() + "% Complete", "percent_complete.png");
    percent_complete.setEditable(false);
    add(percent_complete);

    BitmapInput tags = new BitmapInput("Tags", "tags.png");
    tags.setTextQuiet(TaskUtils.getTags(task));
    tags.setEditable(false);
    add(tags);

    if (task.getDescription().length() > 0) add(description);

    Font header = getFont().derive(Font.BOLD, getFont().getHeight() - 4);
    HeaderLabel l_dr = new HeaderLabel("Due Date");
    l_dr.setFont(header);
    BitmapInput dueDate = new BitmapInput("Due Date", "soon.png");
    if (task.getDateDue() > 0) {
      dueDate.setTextQuiet(
          "Due date: "
              + new SimpleDateFormat(DateFormat.DATETIME_DEFAULT).formatLocal(task.getDateDue()));
      System.out.println("REMINDER: " + task.getDateDue());
    } else dueDate.setTextQuiet("No due date set.");
    dueDate.setEditable(false);
    BitmapInput reminder = new BitmapInput("Reminder", "reminder.png");
    if (task.getReminder() > 0) {
      reminder.setTextQuiet(
          "Reminder: "
              + new SimpleDateFormat(DateFormat.DATETIME_DEFAULT)
                  .formatLocal(task.getDateDue() - (task.getReminder() * 1000)));
      System.out.println("REMINDER: " + task.getReminder());
    } else reminder.setTextQuiet("No reminder set.");
    reminder.setEditable(false);
    add(l_dr);
    add(dueDate);
    add(reminder);
    if (task.getDateDue() > 0) {
      BitmapInput viewInCalendar = new BitmapInput("View in Calendar", "today.png");
      viewInCalendar.setTask(task);
      add(viewInCalendar);
    }

    HeaderLabel l_notes = new HeaderLabel("Notes");
    l_notes.setFont(header);
    notes = new NoteManager(task);
    add(l_notes);
    add(notes);
  }