Android Open Source - GlassToPhoneBluetooth Device Select Dialog Fragment






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.zlglassworks.glassbluetoothtest;
/*from  w  ww.j a  va2s  .  com*/
import java.util.ArrayList;
import java.util.List;

import android.app.DialogFragment;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

public class DeviceSelectDialogFragment extends DialogFragment implements OnItemClickListener {

  private ListView mDeviceListView;
  private List<BluetoothDevice> mDevices;

  public interface BluetoothDevcieSelectListener {
    public void onDeviceSelected(BluetoothDevice device);

    public void noBluetoothDevices();
  }

  public DeviceSelectDialogFragment() {
    // empty constructor required
  }

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

    BluetoothAdapter defaultAdapter = BluetoothAdapter.getDefaultAdapter();

    if (defaultAdapter != null) {
      mDevices = new ArrayList<BluetoothDevice>(defaultAdapter.getBondedDevices());
    }

    if (mDevices.size() == 0) {
      BluetoothDevcieSelectListener activity = (BluetoothDevcieSelectListener) getActivity();
      activity.noBluetoothDevices();
      this.dismiss();
    }
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_dialog_device_list, container);
    mDeviceListView = (ListView) view.findViewById(R.id.device_list);

    List<String> deviceNames = new ArrayList<String>();
    for (BluetoothDevice device : mDevices) {
      deviceNames.add(device.getName());
    }

    ListAdapter adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,
        android.R.id.text1, deviceNames);
    mDeviceListView.setAdapter(adapter);
    mDeviceListView.setOnItemClickListener(this);

    getDialog().setTitle("Select Bluetooth Device");

    return view;
  }

  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    BluetoothDevcieSelectListener activity = (BluetoothDevcieSelectListener) getActivity();
    activity.onDeviceSelected(mDevices.get(position));
    this.dismiss();
  }
}




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