use of com.afunx.ble.blelitelib.adapter.BleDeviceAdapter in project BleLiteLib4android by afunx.
the class ScanActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scan);
mHandler = new Handler();
mListView = (ListView) findViewById(R.id.lv_devices);
mBleDeviceAdapter = new BleDeviceAdapter(this);
mListView.setAdapter(mBleDeviceAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
BleDevice bleDevice = (BleDevice) mBleDeviceAdapter.getItem(position);
// ServiceListActivity.startActivity(ScanActivity.this, bleDevice.getBluetoothDevice());
TestActivity.startActivity(ScanActivity.this, bleDevice.getBluetoothDevice());
}
});
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
doRefresh();
}
});
mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
private long timestamp = 0;
private final long interval = 200;
@Override
public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
BleDevice bleDevice = new BleDevice();
bleDevice.setBluetoothDevice(device);
bleDevice.setRssi(rssi);
bleDevice.setScanRecord(scanRecord);
if (mBleDeviceAdapter.addOrUpdateDevice(bleDevice)) {
timestamp = System.currentTimeMillis();
mBleDeviceAdapter.notifyDataSetChanged();
} else {
if (System.currentTimeMillis() - timestamp > interval) {
timestamp = System.currentTimeMillis();
mBleDeviceAdapter.notifyDataSetChanged();
}
}
}
};
BleUtils.enableBluetooth();
BleProxy.getInstance().init(getApplicationContext());
requestBleAuthority();
}
Aggregations