Exemplo n.º 1
0
  private void setMineralLists(Sector sector) {
    // Populate the list with the initial data
    // Remove the ones we don't want
    mineralList.clear();
    mineralList.addAll(Static.mineralList);

    // Grab the ore list for later
    ArrayAdapter<String> oreListAdapter =
        new ArrayAdapter<String>(
            this, android.R.layout.simple_list_item_1, new ArrayList<String>());
    ((ListView) findViewById(R.id.oreList)).setAdapter(oreListAdapter);

    // Add and remove the needed things from the lists
    for (Mineral mineral : sector.getMinerals()) {
      mineralList.remove(mineral.getMineral());

      oreListAdapter.add(mineral.getMineral());
    }

    // Check to see if the mineral list is empty. If so add the emtpy mineral
    if (mineralList.size() == 0) mineralList.add(emptyMineralString);

    mineralAdapter.notifyDataSetChanged();
    oreListAdapter.notifyDataSetChanged();
  }
        @Override
        public void onReceive(Context context, Intent intent) {
          String action = intent.getAction();

          // When discovery finds a device
          if (BluetoothDevice.ACTION_FOUND.equals(action)) {
            // Get the BluetoothDevice object from the Intent
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
            // If it's already paired, skip it, because it's been listed already
            if (device.getBondState() != BluetoothDevice.BOND_BONDED) {
              mNewDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
            }
            // When discovery is finished, change the Activity title
          } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED.equals(action)) {
            setProgressBarIndeterminateVisibility(false);
            setTitle(R.string.select_device);
            if (mNewDevicesArrayAdapter.getCount() == 0) {
              String noDevices = getResources().getText(R.string.none_found).toString();
              mNewDevicesArrayAdapter.add(noDevices);
            }
          }
        }
Exemplo n.º 3
0
  @Override
  public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
    Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent);

    if ((actionId == EditorInfo.IME_ACTION_DONE)
        || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
      Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER");
      String input = textView.getText().toString().trim();

      if (input.length() > 0) {
        String result = "";

        try {
          result += calculator.calculate(input);
        } catch (Exception e) {
          result = "no result (" + e.getMessage() + ")";
        }

        if (listAdapter.getCount() > 0) {
          listAdapter.add("");
        }

        listAdapter.add(input + " =");
        if (input.indexOf("@") > -1) {
          listAdapter.add(calculator.getEquation() + " =");
        }
        listAdapter.add(result);
        listAdapter.notifyDataSetChanged();

        inputView.endBatchEdit();
        inputView.setText("");
        hideKeyboard();
      }
    }

    return false;
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Setup the window
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.device_list);

    // Set result CANCELED in case the user backs out
    setResult(Activity.RESULT_CANCELED);

    // Initialize the button to perform device discovery
    Button scanButton = (Button) findViewById(R.id.button_scan);
    scanButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            doDiscovery();
            v.setVisibility(View.GONE);
          }
        });

    // Initialize array adapters. One for already paired devices and
    // one for newly discovered devices
    mPairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

    // Find and set up the ListView for paired devices
    ListView pairedListView = (ListView) findViewById(R.id.paired_devices);
    pairedListView.setAdapter(mPairedDevicesArrayAdapter);
    pairedListView.setOnItemClickListener(mDeviceClickListener);

    // Find and set up the ListView for newly discovered devices
    ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
    newDevicesListView.setOnItemClickListener(mDeviceClickListener);

    // Register for broadcasts when a device is discovered
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, filter);

    // Register for broadcasts when discovery has finished
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    // Get the local Bluetooth adapter
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    // Get a set of currently paired devices
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

    // If there are paired devices, add each one to the ArrayAdapter
    if (pairedDevices.size() > 0) {
      findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
      for (BluetoothDevice device : pairedDevices) {
        mPairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
      }
    } else {
      String noDevices = getResources().getText(R.string.none_paired).toString();
      mPairedDevicesArrayAdapter.add(noDevices);
    }
  }