Search in sources :

Example 96 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project BleSensorTag by StevenRudenko.

the class BleDevicesAdapter method getView.

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
    ViewHolder viewHolder;
    // General ListView optimization code.
    if (view == null) {
        view = inflater.inflate(R.layout.li_device, viewGroup, false);
        viewHolder = new ViewHolder(view);
        view.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) view.getTag();
    }
    BluetoothDevice device = leDevices.get(i);
    final String deviceName = device.getName();
    if (TextUtils.isEmpty(deviceName)) {
        viewHolder.name.setText(device.getAddress());
        viewHolder.address.setVisibility(View.GONE);
        viewHolder.address.setText(null);
    } else {
        viewHolder.name.setText(deviceName);
        viewHolder.address.setText(device.getAddress());
        viewHolder.address.setVisibility(View.VISIBLE);
    }
    final int rssi = rssiMap.get(device);
    if (rssi == RSSI_CONNECTED) {
        viewHolder.signal.setText(R.string.scan_li_signal_connected);
    } else {
        viewHolder.signal.setText(viewGroup.getResources().getString(R.string.scan_li_signal_template, Integer.toString(rssi)));
    }
    return view;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 97 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project BleSensorTag by StevenRudenko.

the class DeviceScanActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    final BluetoothDevice device = leDeviceListAdapter.getDevice(position);
    if (device == null) {
        return;
    }
    final Intent intent = new Intent(this, DeviceServicesActivity.class);
    intent.putExtra(DeviceServicesActivity.EXTRAS_DEVICE_NAME, device.getName());
    intent.putExtra(DeviceServicesActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress());
    startActivity(intent);
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) Intent(android.content.Intent)

Example 98 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project BleLiteLib4android by afunx.

the class BleConnectOperation method run.

@Override
public void run() {
    BluetoothDevice bluetoothDevice = BleUtils.getRemoteDevice(mBleAddr);
    //        bluetoothDevice.fetchUuidsWithSdp();
    BleConnector connector = getConnector();
    if (connector == null) {
        connector = new BleConnector.Builder().build(mAppContext, bluetoothDevice).setGattCallback(mBluetoothGattCallback).create();
        setConnector(connector);
    }
    connector.connect();
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice) BleConnector(com.afunx.ble.blelitelib.connector.BleConnector)

Example 99 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by crdroidandroid.

the class ScanFilter method matches.

/**
     * Check if the scan filter matches a {@code scanResult}. A scan result is considered as a match
     * if it matches all the field filters.
     */
public boolean matches(ScanResult scanResult) {
    if (scanResult == null) {
        return false;
    }
    BluetoothDevice device = scanResult.getDevice();
    // Device match.
    if (mDeviceAddress != null && (device == null || !mDeviceAddress.equals(device.getAddress()))) {
        return false;
    }
    ScanRecord scanRecord = scanResult.getScanRecord();
    // Scan record is null but there exist filters on it.
    if (scanRecord == null && (mDeviceName != null || mServiceUuid != null || mManufacturerData != null || mServiceData != null)) {
        return false;
    }
    // Local name match.
    if (mDeviceName != null && !mDeviceName.equals(scanRecord.getDeviceName())) {
        return false;
    }
    // UUID match.
    if (mServiceUuid != null && !matchesServiceUuids(mServiceUuid, mServiceUuidMask, scanRecord.getServiceUuids())) {
        return false;
    }
    // Service data match
    if (mServiceDataUuid != null) {
        if (!matchesPartialData(mServiceData, mServiceDataMask, scanRecord.getServiceData(mServiceDataUuid))) {
            return false;
        }
    }
    // Manufacturer data match.
    if (mManufacturerId >= 0) {
        if (!matchesPartialData(mManufacturerData, mManufacturerDataMask, scanRecord.getManufacturerSpecificData(mManufacturerId))) {
            return false;
        }
    }
    // All filters match.
    return true;
}
Also used : BluetoothDevice(android.bluetooth.BluetoothDevice)

Example 100 with BluetoothDevice

use of android.bluetooth.BluetoothDevice in project android_frameworks_base by crdroidandroid.

the class MidiService method addDeviceLocked.

// synchronize on mDevicesByInfo
private MidiDeviceInfo addDeviceLocked(int type, int numInputPorts, int numOutputPorts, String[] inputPortNames, String[] outputPortNames, Bundle properties, IMidiDeviceServer server, ServiceInfo serviceInfo, boolean isPrivate, int uid) {
    int id = mNextDeviceId++;
    MidiDeviceInfo deviceInfo = new MidiDeviceInfo(type, id, numInputPorts, numOutputPorts, inputPortNames, outputPortNames, properties, isPrivate);
    if (server != null) {
        try {
            server.setDeviceInfo(deviceInfo);
        } catch (RemoteException e) {
            Log.e(TAG, "RemoteException in setDeviceInfo()");
            return null;
        }
    }
    Device device = null;
    BluetoothDevice bluetoothDevice = null;
    if (type == MidiDeviceInfo.TYPE_BLUETOOTH) {
        bluetoothDevice = (BluetoothDevice) properties.getParcelable(MidiDeviceInfo.PROPERTY_BLUETOOTH_DEVICE);
        device = mBluetoothDevices.get(bluetoothDevice);
        if (device != null) {
            device.setDeviceInfo(deviceInfo);
        }
    }
    if (device == null) {
        device = new Device(server, deviceInfo, serviceInfo, uid);
    }
    mDevicesByInfo.put(deviceInfo, device);
    if (bluetoothDevice != null) {
        mBluetoothDevices.put(bluetoothDevice, device);
    }
    synchronized (mClients) {
        for (Client c : mClients.values()) {
            c.deviceAdded(device);
        }
    }
    return deviceInfo;
}
Also used : MidiDeviceInfo(android.media.midi.MidiDeviceInfo) BluetoothDevice(android.bluetooth.BluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) RemoteException(android.os.RemoteException)

Aggregations

BluetoothDevice (android.bluetooth.BluetoothDevice)100 Intent (android.content.Intent)13 BluetoothAdapter (android.bluetooth.BluetoothAdapter)12 CachedBluetoothDevice (com.android.settingslib.bluetooth.CachedBluetoothDevice)11 ParcelUuid (android.os.ParcelUuid)9 RemoteException (android.os.RemoteException)9 ScanFilter (android.bluetooth.le.ScanFilter)5 Parcel (android.os.Parcel)5 SmallTest (android.test.suitebuilder.annotation.SmallTest)5 IOException (java.io.IOException)5 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)5 IntentFilter (android.content.IntentFilter)4 MidiDeviceInfo (android.media.midi.MidiDeviceInfo)4 View (android.view.View)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 TextView (android.widget.TextView)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2