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;
}
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);
}
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();
}
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;
}
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;
}
Aggregations