/**
   * We have to provide this method due to "do not do network operation in command listener method"
   * restriction, which is caused by crooked midp design.
   *
   * <p>This method is called by BTImageClient after it is done with bluetooth initialization and
   * next screen is ready to appear.
   */
  void completeInitialization(boolean isBTReady) {
    // bluetooth was initialized successfully.
    if (isBTReady) {
      StringItem si = new StringItem("Ready for images search!", null);
      si.setLayout(StringItem.LAYOUT_CENTER | StringItem.LAYOUT_VCENTER);
      mainScreen.append(si);
      Display.getDisplay(parent).setCurrent(mainScreen);

      return;
    }

    // something wrong
    Alert al = new Alert("Error", "Can't initialize bluetooth", null, AlertType.ERROR);
    al.setTimeout(DemoMIDlet.ALERT_TIMEOUT);
    Display.getDisplay(parent).setCurrent(al, parent.getDisplayable());
  }
  /**
   * Process the command events.
   *
   * @param c - the issued command.
   * @param d - the screen object the command was issued for.
   */
  public void commandAction(Command c, Displayable d) {
    // back to demo main screen
    if (c == SCR_MAIN_BACK_CMD) {
      destroy();
      parent.show();

      return;
    }

    // starts images (device/services) search
    if (c == SCR_MAIN_SEARCH_CMD) {
      Form f = new Form("Searching...");
      f.addCommand(SCR_SEARCH_CANCEL_CMD);
      f.setCommandListener(this);
      f.append(new Gauge("Searching images...", false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING));
      Display.getDisplay(parent).setCurrent(f);
      bt_client.requestSearch();

      return;
    }

    // cancels device/services search
    if (c == SCR_SEARCH_CANCEL_CMD) {
      bt_client.cancelSearch();
      Display.getDisplay(parent).setCurrent(mainScreen);

      return;
    }

    // back to client main screen
    if (c == SCR_IMAGES_BACK_CMD) {
      bt_client.requestLoad(null);
      Display.getDisplay(parent).setCurrent(mainScreen);

      return;
    }

    // starts image download
    if (c == SCR_IMAGES_LOAD_CMD) {
      Form f = new Form("Loading...");
      f.addCommand(SCR_LOAD_CANCEL_CMD);
      f.setCommandListener(this);
      f.append(new Gauge("Loading image...", false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING));
      Display.getDisplay(parent).setCurrent(f);

      List l = (List) d;
      bt_client.requestLoad(l.getString(l.getSelectedIndex()));

      return;
    }

    // cancels image load
    if (c == SCR_LOAD_CANCEL_CMD) {
      bt_client.cancelLoad();
      Display.getDisplay(parent).setCurrent(listScreen);

      return;
    }

    // back to client main screen
    if (c == SCR_SHOW_BACK_CMD) {
      Display.getDisplay(parent).setCurrent(listScreen);

      return;
    }
  }