Android Open Source - GlassToPhoneBluetooth Device Select Activity






From Project

Back to project page GlassToPhoneBluetooth.

License

The source code is released under:

MIT License

If you think the Android project GlassToPhoneBluetooth listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.space150.android.glass.camerazoom;
/* w  ww  . j a v  a 2s. c om*/
import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class DeviceSelectActivity extends Activity {

  public static final String BLUETOOT_DEVICE = "bluetoot_device";

  private List<BluetoothDevice> mDevices;

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

    List<String> deviceNames = new ArrayList<String>();
    BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();

    if (defaultAdapter != null) {
      mDevices = new ArrayList<BluetoothDevice>(defaultAdapter.getBondedDevices());
      for (BluetoothDevice device : mDevices) {
        deviceNames.add(device.getName());
      }
    }

    if (deviceNames.size() == 0) {
      Toast.makeText(this, "Unable to locate and Bluetooth Devices", Toast.LENGTH_SHORT).show();
      finish();
    } else {
      openOptionsMenu();
    }
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    int position = 0;
    for (BluetoothDevice device : mDevices) {
      menu.add(0, position, position, device.getName());
      position++;
    }
    return true;
  }

  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    Intent intent = new Intent();
    intent.putExtra(BLUETOOT_DEVICE, mDevices.get(item.getItemId()));
    setResult(Activity.RESULT_OK, intent);
    finish();
    return true;
  }

  public void onOptionsMenuClosed(Menu menu) {
    super.onOptionsMenuClosed(menu);
    setResult(Activity.RESULT_OK, null);
    finish();
  }
}




Java Source Code List

com.space150.android.glass.camerazoom.DeviceSelectActivity.java
com.space150.android.glass.camerazoom.MainActivity.java
com.zlglassworks.glassbluetoothtest.DeviceSelectDialogFragment.java
com.zlglassworks.glassbluetoothtest.MainActivity.java
ktlab.lib.connection.CommandReceiveThread.java
ktlab.lib.connection.CommandReceiveThread.java
ktlab.lib.connection.CommandSendThread.java
ktlab.lib.connection.CommandSendThread.java
ktlab.lib.connection.ConnectionCallback.java
ktlab.lib.connection.ConnectionCallback.java
ktlab.lib.connection.ConnectionCommand.java
ktlab.lib.connection.ConnectionCommand.java
ktlab.lib.connection.ConnectionThread.java
ktlab.lib.connection.ConnectionThread.java
ktlab.lib.connection.Connection.java
ktlab.lib.connection.Connection.java
ktlab.lib.connection.bluetooth.BluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.BluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.BluetoothConnection.java
ktlab.lib.connection.bluetooth.BluetoothConnection.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnection.java
ktlab.lib.connection.bluetooth.ClientBluetoothConnection.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnectionThread.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnection.java
ktlab.lib.connection.bluetooth.ServerBluetoothConnection.java