@Override protected void onPause() { super.onPause(); scanLeDevice(false); mLeDeviceListAdapter.clear(); mLeDeviceListAdapter.notifyDataSetChanged(); }
protected void onListItemClick(int position) { iBeaconClass.iBeacon device = mLeDeviceListAdapter.getDevice(position); if (device == null) return; if (!device.name.equals("pBeacon_n")) { Toast.makeText(MainActivity.this, "The iBeacon is not connectable", Toast.LENGTH_LONG).show(); return; } Intent intent = new Intent(this, DeviceControlActivity.class); Bundle bundle = new Bundle(); intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.bluetoothAddress); intent.putExtras(bundle); if (mScanning) { // ask scan service to stop scanning Intent intent1 = new Intent(BluetoothLeScanService.SCAN_COMMAND_ACTION); intent1.putExtra( BluetoothLeScanService.SCAN_COMMAND_ACTION, BluetoothLeScanService.SCAN_COMMAND_STOP); LocalBroadcastManager.getInstance(MainActivity.this).sendBroadcast(intent1); mScanning = false; } startActivity(intent); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position); if (device == null) return; final Intent intent = new Intent(this, DeviceControlActivity.class); intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_NAME, device.getName()); intent.putExtra(DeviceControlActivity.EXTRAS_DEVICE_ADDRESS, device.getAddress()); if (mScanning) { mBluetoothAdapter.stopLeScan(mLeScanCallback); mScanning = false; } startActivity(intent); }
@Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.menu_scan: mLeDeviceListAdapter.clear(); scanLeDevice(true); break; case R.id.menu_stop: scanLeDevice(false); break; } return true; }
void scanLeDevice(final boolean enable) { if (enable) { // Stops scanning after a pre-defined scan period. System.out.println("mBluetoothAdapter.startLeScan"); if (mLeDeviceListAdapter != null) { mLeDeviceListAdapter.clear(); mLeDeviceListAdapter.notifyDataSetChanged(); } if (!mScanning) { mScanning = true; mBluetoothAdapter.startLeScan(mLeScanCallback); } } else { if (mScanning) { mScanning = false; mBluetoothAdapter.stopLeScan(mLeScanCallback); } } }
private void initRecyclerView() { RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); mLeDeviceListAdapter = new LeDeviceListAdapter(); mLeDeviceListAdapter.setMyItemClickListener(this); recyclerView.setAdapter(mLeDeviceListAdapter); recyclerView.addOnScrollListener( new HidingScrollListener() { @Override public void onHide() { hideViews(); } @Override public void onShow() { showViews(); } }); scanLeDevice(true); mLeDeviceListAdapter.setMyItemClickListener(this); }
@Override protected void onListItemClick(ListView l, View v, int position, long id) { Log.d(TAG, "Item Clicked"); final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position); if (device == null || device.getName() == null) return; Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show(); ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle(); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); prefs.edit().putString("last_connected_device_address", device.getAddress()).apply(); if (btDevice == null) { ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice(); newBtDevice.name = device.getName(); newBtDevice.address = device.getAddress(); newBtDevice.save(); } else { btDevice.name = device.getName(); btDevice.address = device.getAddress(); btDevice.save(); } if (device.getName().toLowerCase().contains("dexcom")) { if (!CollectionServiceStarter.isBTShare(getApplicationContext())) { prefs.edit().putString("dex_collection_method", "DexcomShare").apply(); prefs.edit().putBoolean("calibration_notifications", false).apply(); } if (prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0 || prefs.getString("share_key", "SM00000000").length() < 10) { requestSerialNumber(prefs); } else returnToHome(); } else if (device.getName().toLowerCase().contains("bridge")) { if (!CollectionServiceStarter.isDexbridgeWixel(getApplicationContext())) prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply(); if (prefs.getString("dex_txid", "00000").compareTo("00000") == 0 || prefs.getString("dex_txid", "00000").length() < 5) { requestTransmitterId(prefs); } else returnToHome(); } else if (device.getName().toLowerCase().contains("drip")) { if (!(CollectionServiceStarter.isBTWixel(getApplicationContext()) || CollectionServiceStarter.isWifiandBTWixel(getApplicationContext()))) { prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply(); } returnToHome(); } else { returnToHome(); } }
@Override protected void onResume() { super.onResume(); SessionM.getInstance().onActivityResume(this); if (!mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT); } mLeDeviceListAdapter = new LeDeviceListAdapter(); mLeDeviceListAdapter.clear(); setListAdapter(mLeDeviceListAdapter); scanLeDevice(true); }
public void onPauseProcess() { System.out.println("BLUNOActivity onPause"); scanLeDevice(false); mainContext.unregisterReceiver(mGattUpdateReceiver); mLeDeviceListAdapter.clear(); mConnectionState = connectionStateEnum.isToScan; onConectionStateChange(mConnectionState); mScanDeviceDialog.dismiss(); if (mBluetoothLeService != null) { mBluetoothLeService.disconnect(); mHandler.postDelayed(mDisonnectingOverTimeRunnable, 10000); // mBluetoothLeService.close(); } mSCharacteristic = null; }
@Override protected void onPause() { super.onPause(); scanLeDevice(false); mLeDeviceListAdapter.clear(); }