summaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-21 22:17:46 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-21 22:25:18 +0200
commit3cadf6de64519da4ec11f16e048c05e4058a5ed6 (patch)
tree63c18a3be131d397e1d6647719155247010c6612 /android
parentn760019: removing problematic code that disrupts numbering level (diff)
downloadcore-3cadf6de64519da4ec11f16e048c05e4058a5ed6.tar.gz
core-3cadf6de64519da4ec11f16e048c05e4058a5ed6.zip
Added bluez_bluetooth headers as a module.
Change-Id: Id9f4e59b5c46c7bee3cf0b129f523d963c0407a6
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java110
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java6
2 files changed, 114 insertions, 2 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java
new file mode 100644
index 000000000000..6d3735153c4c
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.libreoffice.impressremote.communication;
+
+import java.net.Socket;
+import java.util.UUID;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.bluetooth.BluetoothSocket;
+import android.content.Context;
+
+/**
+ * Standard Network client. Connects to a server using Sockets.
+ *
+ * @author Andrzej J.R. Hunt
+ */
+public class BluetoothClient extends Client {
+
+ private static final int PORT = 5;
+
+ private Socket mSocket;
+
+ public BluetoothClient(String bluetoothAddress, Context aContext) {
+ super(aContext);
+ try {
+ BluetoothAdapter aAdapter = BluetoothAdapter.getDefaultAdapter();
+ BluetoothDevice aDevice = aAdapter
+ .getRemoteDevice(bluetoothAddress);
+ BluetoothSocket aSocket = aDevice
+ .createRfcommSocketToServiceRecord(UUID
+ .fromString("00001101-0000-1000-8000-00805f9b34fb"));
+ aSocket.connect();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ // BluetoothSocket aSocket = new BluetoothClient(bluetoothAddress, aContext)
+ // .createRfcommSocketToServiceRecord(UUID
+ // .fromString("00001101-0000-1000-8000-00805F9B34F
+ // }
+ // try {
+ // mSocket = new Socket(ipAddress, PORT);
+ // mInputStream = mSocket.getInputStream();
+ // mReader = new BufferedReader(new InputStreamReader(mInputStream,
+ // CHARSET));
+ // mOutputStream = mSocket.getOutputStream();
+ // // Pairing.
+ // Random aRandom = new Random();
+ // String aPin = "" + (aRandom.nextInt(9000) + 1000);
+ // while (aPin.length() < 4) {
+ // aPin = "0" + aPin; // Add leading zeros if necessary
+ // }
+ // Intent aIntent = new Intent(
+ // CommunicationService.MSG_PAIRING_STARTED);
+ // aIntent.putExtra("PIN", aPin);
+ // mPin = aPin;
+ // LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent);
+ // // Send out
+ // String aName = CommunicationService.getDeviceName(); // TODO: get the proper name
+ // sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + aPin
+ // + "\n\n");
+ //
+ // // Wait until we get the appropriate string back...
+ // System.out.println("SF:waiting");
+ // String aTemp = mReader.readLine();
+ // System.out.println("SF:waited");
+ // if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) {
+ // return;
+ // } else {
+ // aIntent = new Intent(
+ // CommunicationService.MSG_PAIRING_SUCCESSFUL);
+ // LocalBroadcastManager.getInstance(mContext).sendBroadcast(
+ // aIntent);
+ // }
+ // while (mReader.readLine().length() != 0) {
+ // // Get rid of extra lines
+ // System.out.println("SF: empty line");
+ // }
+ // System.out.println("SD: empty");
+ // startListening();
+ // } catch (UnknownHostException e) {
+ // // TODO Tell the user we have a problem
+ // e.printStackTrace();
+ // } catch (IOException e) {
+ // // TODO As above
+ // e.printStackTrace();
+ // }
+
+ }
+
+ @Override
+ public void closeConnection() {
+ // try {
+ // if (mSocket != null)
+ // mSocket.close();
+ // } catch (IOException e) {
+ // // TODO Auto-generated catch block
+ // e.printStackTrace();
+ // }
+ }
+
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index b3fc690031a8..3b6334f9e0a0 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -81,12 +81,14 @@ public class CommunicationService extends Service implements Runnable {
case NETWORK:
mClient = new NetworkClient(
mServerDesired.getAddress(), this);
- mTransmitter = new Transmitter(mClient);
- mClient.setReceiver(mReceiver);
break;
case BLUETOOTH:
+ mClient = new BluetoothClient(
+ mServerDesired.getAddress(), this);
break;
}
+ mTransmitter = new Transmitter(mClient);
+ mClient.setReceiver(mReceiver);
mState = State.CONNECTED;
}
}