summaryrefslogtreecommitdiff
path: root/Defogger/src/no/mork/android/defogger/IpCamActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'Defogger/src/no/mork/android/defogger/IpCamActivity.java')
-rw-r--r--Defogger/src/no/mork/android/defogger/IpCamActivity.java133
1 files changed, 14 insertions, 119 deletions
diff --git a/Defogger/src/no/mork/android/defogger/IpCamActivity.java b/Defogger/src/no/mork/android/defogger/IpCamActivity.java
index 13a7e75..b99cf29 100644
--- a/Defogger/src/no/mork/android/defogger/IpCamActivity.java
+++ b/Defogger/src/no/mork/android/defogger/IpCamActivity.java
@@ -33,9 +33,6 @@ import android.widget.ListView;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
-import com.google.zxing.integration.android.IntentIntegrator;
-import com.google.zxing.integration.android.IntentResult;
-
import java.lang.StringBuilder;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
@@ -47,15 +44,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
-//import no.mork.android.defogger.ScannerActivity;
-
-public class MainActivity extends Activity {
- private static String msg = "Defogger MainActivity: ";
+public class IpCamActivity extends Activity {
+ private static String msg = "Defogger IPCamActivity: ";
- private static final int REQUEST_ENABLE_BT = 1;
- private static final int REQUEST_GET_DEVICE = 2;
-
- private BluetoothAdapter bluetoothAdapter;
private BluetoothGatt mGatt;
private BluetoothGattService ipcamService;
private String pincode;
@@ -70,8 +61,17 @@ public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
-
+ setContentView(R.layout.activity_ipcam);
+
+ // Get the Intent that started this activity and extract parameters
+ Intent intent = getIntent();
+ pincode = intent.getStringExtra("pincode");
+ BluetoothDevice dev = intent.getExtras().getParcelable("btdevice");
+ if (pincode == null || dev == null)
+ finish();
+
+ connectDevice(dev);
+
EditText cmd = (EditText) findViewById(R.id.command);
cmd.setOnEditorActionListener(new OnEditorActionListener() {
@Override
@@ -88,107 +88,6 @@ public class MainActivity extends Activity {
@Override
protected void onResume() {
super.onResume();
- getBluetoothAdapter();
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent dataIntent) {
- super.onActivityResult(requestCode, resultCode, dataIntent);
-
- switch (requestCode) {
- case IntentIntegrator.REQUEST_CODE:
- IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, dataIntent);
- if (scanResult != null)
- handleQRScanResult(scanResult);
- break;
- case REQUEST_ENABLE_BT:
- if (resultCode != RESULT_OK) { // user refused to enable BT?
- setStatus("Bluetooth is disabled");
- finish();
- }
-
- break;
- case REQUEST_GET_DEVICE:
- if (resultCode != RESULT_OK) {
- setStatus("Failed to find a camera");
- break;
- }
-
- BluetoothDevice dev = dataIntent.getExtras().getParcelable("btdevice");
- if (dev == null) {
- setStatus("No camera selected");
- break;
- }
-
- pincode = dataIntent.getStringExtra("pincode");
- if (pincode == null || pincode.length() < 6) {
- setStatus("Bogus pincode");
- break;
- }
-
- connectDevice(dev);
- break;
- default:
- Log.d(msg, "unknown request???");
- }
- }
-
- // find and enable a bluetooth adapter with LE support
- protected void getBluetoothAdapter() {
- final BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
- bluetoothAdapter = bluetoothManager.getAdapter();
-
- if (bluetoothAdapter == null) {
- setStatus("Bluetooth is unsupported");
- finish();
- }
-
- if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
- setStatus("No Bluetooth Low Energy support");
- finish();
- }
-
- if (!bluetoothAdapter.isEnabled()) {
- Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
- startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
- }
- }
-
- public void startScannerActivity(View view) {
- disconnectDevice();
- Intent intent = new Intent(view.getContext(), ScannerActivity.class);
- startActivityForResult(intent, REQUEST_GET_DEVICE);
- }
-
- public void startQRReaderActivity(View view) {
- IntentIntegrator integrator = new IntentIntegrator(this);
- integrator.initiateScan();
- }
-
- private void handleQRScanResult(IntentResult res) {
- Log.d(msg, "QR scan resturned: " + res.toString());
-
- // DCS-8000LH,A3,12345678,B0C554AABBCC,DCS-8000LH-BBCC,123456
- String[] data = res.getContents().split(",");
- if (data.length != 6 || data[3].length() != 12 || data[5].length() != 6) {
- setStatus("Unexpected QR scan result - wrong format");
- return;
- }
-
- pincode = data[5];
-
- StringBuilder mac = new StringBuilder(data[3]);
- mac.insert(10, ':');
- mac.insert(8, ':');
- mac.insert(6, ':');
- mac.insert(4, ':');
- mac.insert(2, ':');
-
- if (!bluetoothAdapter.checkBluetoothAddress(mac.toString())) {
- Log.d(msg, "Got invalid MAC address from QR scan:" + mac.toString());
- return;
- }
- connectDevice(mac.toString());
}
// utilities
@@ -465,11 +364,6 @@ public class MainActivity extends Activity {
mGatt = device.connectGatt(this, true, gattClientCallback);
}
- private void connectDevice(String macaddress) {
- BluetoothDevice device = bluetoothAdapter.getRemoteDevice(macaddress);
- connectDevice(device);
- }
-
private void disconnectDevice() {
// reset status to default
connected = false;
@@ -480,6 +374,7 @@ public class MainActivity extends Activity {
return;
Log.d(msg, "disconnectDevice() " + mGatt.getDevice().getAddress());
mGatt.close();
+ finish();
}
// camera specific code