private void activeCamera() { camera = getCameraInstance(); try { if (camera != null) { frameLayout = new FrameLayout(this); frameLayout.setLayoutParams( new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // Create a new camera view and add it to the layout preview = new Preview(this, camera); frameLayout.addView(preview); // Create a new draw view and add it to the layout drawViewConnexionBluetooth = new DrawViewConnexionBluetooth(this, screenPoint); drawViewConnexionBluetooth.setInfo("Bluetooth - listenning ..."); frameLayout.addView(drawViewConnexionBluetooth); // Set the layout as the apps content view setContentView(frameLayout); } else { Toast toast = Toast.makeText(context, "Unable to find camera. Closing.", Toast.LENGTH_SHORT); toast.show(); finish(); } } catch (Exception e) { if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "Load error = " + e.getMessage()); } ; if (camera != null) { camera.release(); camera = null; } } }
@Override public void handleMessage(Message msg) { switch (msg.what) { case MESSAGE_STATE_CHANGE: if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "MESSAGE_STATE_CHANGE: " + msg.arg1); } ; switch (msg.arg1) { case BluetoothChatService.STATE_CONNECTED: if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "Connected"); } ; // setStatus(context.getResources().getString(R.string.bt_connected)); statut = BluetoothChatService.STATE_CONNECTED; drawViewConnexionBluetooth.setInfo( "Bluetooth - Connected to " + connectedDeviceName); drawViewConnexionBluetooth.invalidate(); break; case BluetoothChatService.STATE_CONNECTING: // setStatus(context.getResources().getString(R.string.bt_connecting)); if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "Connecting"); } ; statut = BluetoothChatService.STATE_CONNECTING; drawViewConnexionBluetooth.setInfo("Bluetooth - Connecteing ..."); drawViewConnexionBluetooth.invalidate(); break; case BluetoothChatService.STATE_LISTEN: if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "listenning"); } ; // setStatus(context.getResources().getString(R.string.bt_listenning)); statut = BluetoothChatService.STATE_LISTEN; drawViewConnexionBluetooth.setInfo("Bluetooth - Listenning ..."); drawViewConnexionBluetooth.invalidate(); break; case BluetoothChatService.STATE_NONE: if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "None"); } ; // setStatus(context.getResources().getString(R.string.bt_connected_no)); statut = BluetoothChatService.STATE_NONE; drawViewConnexionBluetooth.setInfo("Bluetooth - Stand by"); drawViewConnexionBluetooth.invalidate(); break; } break; case MESSAGE_WRITE: byte[] writeBuf = (byte[]) msg.obj; String writeMessage = new String(writeBuf); if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "MESSAGE_WRITE: " + writeMessage); } ; // messageAdapter.add("Me: " + writeMessage); break; case MESSAGE_READ: String readMessage = ""; byte[] readBuf = (byte[]) msg.obj; byte byteEntete = readBuf[0]; String refSend = Character.toString((char) byteEntete); if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "MESSAGE_READ - byteEntete: " + refSend); } ; if (refSend.equalsIgnoreCase(Params.REP_DATA)) { readMessage = "Data received"; } else if (refSend.equalsIgnoreCase(Params.REP_JPG)) { readMessage = "JPG received"; } else if (refSend.equalsIgnoreCase(Params.REP_PNG)) { readMessage = "PNG received"; } else { readMessage = new String(readBuf, 0, msg.arg1); if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "MESSAGE_READ: " + readMessage); } ; String strRep = readMessage.substring(0, 1); if (strRep.equalsIgnoreCase(Params.REP_MESSAGE)) { readMessage = "Msg:" + readMessage.substring(1); } if (strRep.equalsIgnoreCase(Params.REP_SMS)) { readMessage = "SMS:" + readMessage.substring(1); } if (strRep.equalsIgnoreCase(Params.REP_NOTIF)) { readMessage = "Notif:" + readMessage.substring(1); } } drawViewConnexionBluetooth.setMessage(readMessage); drawViewConnexionBluetooth.invalidate(); // messageAdapter.add(connectedDeviceName +": " + readMessage); break; case MESSAGE_DEVICE_NAME: connectedDeviceName = msg.getData().getString(DEVICE_NAME); if (Params.TAG_FG_DEBUG && fgDebugLocal) { Log.i(Params.TAG_GEN, TAG_LOCAL + "DEVICE_NAME = " + connectedDeviceName); } ; drawViewConnexionBluetooth.setInfo("Bluetooth - Connected to " + connectedDeviceName); drawViewConnexionBluetooth .invalidate(); // setStatus(context.getResources().getString(R.string.bt_connected_to) + " " + connectedDeviceName); // Toast.makeText(context, context.getResources().getString(R.string.bt_connected_to) // + connectedDeviceName, Toast.LENGTH_SHORT).show(); break; case MESSAGE_TOAST: // Toast.makeText(context, msg.getData().getString(TOAST),Toast.LENGTH_SHORT).show(); break; } }