Example #1
0
  public IDevice getDevice() {

    if (!virgin || cgScan.getSelectedIndex() == ADDR_TYPE_MANUAL) {
      device.setAddress(tfAddr.getString());
    }
    device.setSearch(cgSearch.getSelectedIndex());
    device.setPort(tfChan.getString());
    device.setName(tfName.getString());
    device.setAuthenticate(cgSecurity.isSelected(SEC_AUTHENTICATE_INDEX));
    device.setEncrypt(cgSecurity.isSelected(SEC_ENCRYPT_INDEX));

    return device;
  }
Example #2
0
  public BluetoothScreen(BluetoothDevice device) {

    super("Bluetooth");

    this.device = device;

    virgin = device.getAddress().length() == 0;

    String label, value;
    int constraints;

    // scan type //

    if (virgin) {
      label = "Address";
      cgScan = new ChoiceGroup(label, Choice.EXCLUSIVE, ADDR_CHOICES, null);
      cgScan.setSelectedIndex(ADDR_TYPE_SCAN, true);
      append(cgScan);
    } else {
      cgScan = null;
    }

    // address //

    if (virgin) {
      label = null;
      value = "001122AABBCC";
      constraints = ADDR_OFF;
    } else {
      label = "Address";
      value = device.getAddress();
      constraints = ADDR_ON;
    }
    tfAddr = new TextField(label, value, 256, constraints);
    append(tfAddr);

    if (virgin) {
      append("When scanning, ensure your computer's Bluetooth is in " + "visible mode.");
    }

    // search type //

    label = "Channel";
    cgSearch = new ChoiceGroup(label, Choice.EXCLUSIVE, CHAN_CHOICES, null);
    cgSearch.setSelectedIndex(device.getSearch(), true);
    if (!virgin) {
      append(cgSearch);
    }

    // channel //

    label = null;
    if (device.getSearch() == BluetoothDevice.SEARCH_MANUAL) {
      constraints = CHAN_ON;
    } else {
      constraints = CHAN_OFF;
    }
    tfChan = new TextField(label, device.getChan(), 256, constraints);
    if (!virgin) {
      append(tfChan);
    }

    // security //

    label = "Security";
    cgSecurity = new ChoiceGroup(label, Choice.MULTIPLE, SEC_CHOICES, null);
    cgSecurity.setSelectedIndex(SEC_AUTHENTICATE_INDEX, device.isAuthenticate());
    cgSecurity.setSelectedIndex(SEC_ENCRYPT_INDEX, device.isEncrypt());
    if (!virgin) {
      append(cgSecurity);
    }

    // name //

    label = "Name (optional):";
    tfName = new TextField(label, device.getName(), 256, TextField.ANY);
    if (!virgin) {
      append(tfName);
    }

    setItemStateListener(new SearchSelectionChangeListener());
  }