summaryrefslogtreecommitdiff
path: root/Defogger/src/no/mork/android/defogger/ScannerActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'Defogger/src/no/mork/android/defogger/ScannerActivity.java')
-rw-r--r--Defogger/src/no/mork/android/defogger/ScannerActivity.java80
1 files changed, 67 insertions, 13 deletions
diff --git a/Defogger/src/no/mork/android/defogger/ScannerActivity.java b/Defogger/src/no/mork/android/defogger/ScannerActivity.java
index 72b72bd..5ec114f 100644
--- a/Defogger/src/no/mork/android/defogger/ScannerActivity.java
+++ b/Defogger/src/no/mork/android/defogger/ScannerActivity.java
@@ -1,23 +1,77 @@
package no.mork.android.defogger;
import android.app.Activity;
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+//import android.widget.ArrayAdapter;
import android.widget.Toast;
+//class LeDeviceListAdapter extends ArrayAdapter {
+// protected void addDevice(final BluetoothDevice device);
+//}
+
public class ScannerActivity extends Activity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- //setContentView(R.layout.scanning);
-
- CharSequence text = "Hello toast!";
-
- Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
- Intent intent = new Intent();
- intent.putExtra("scan_ret", "This data is returned when scan activity is finished.");
- setResult(RESULT_OK, intent);
- finish();
- }
+
+ // Stops scanning after 10 seconds.
+ private static final long SCAN_PERIOD = 10000;
+ private BluetoothAdapter bluetoothAdapter;
+ private boolean mScanning;
+ private Handler handler;
+ // private LeDeviceListAdapter leDeviceListAdapter;
+ private BluetoothAdapter.LeScanCallback leScanCallback;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ //setContentView(R.layout.scanning);
+
+ bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+
+ leScanCallback = new BluetoothAdapter.LeScanCallback() {
+
+ @Override
+ public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
+ runOnUiThread(new Runnable() {
+
+ @Override
+ public void run() {
+ // leDeviceListAdapter.addDevice(device);
+ // leDeviceListAdapter.notifyDataSetChanged();
+ }
+ });
+ }
+ };
+
+ CharSequence text = "Hello toast!";
+
+ Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG).show();
+ Intent intent = new Intent();
+ intent.putExtra("scan_ret", "This data is returned when scan activity is finished.");
+ setResult(RESULT_OK, intent);
+ finish();
+ }
+
+ protected void scanForCamera(final boolean enable) {
+ if (enable) {
+ // Stops scanning after a pre-defined scan period.
+ handler.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ mScanning = false;
+ bluetoothAdapter.stopLeScan(leScanCallback);
+ }
+ }, SCAN_PERIOD);
+
+ mScanning = true;
+ bluetoothAdapter.startLeScan(leScanCallback);
+ } else {
+ mScanning = false;
+ bluetoothAdapter.stopLeScan(leScanCallback);
+ }
+ }
+
}