diff options
author | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-08-22 12:44:42 +0200 |
---|---|---|
committer | Andrzej J.R. Hunt <andrzej@ahunt.org> | 2012-08-22 20:23:07 +0200 |
commit | 1db66c2a1a8ad5a60c68b09ddacc1bb6e021299f (patch) | |
tree | f4693b0a0c1a689783c9dbf956a56d8d350afb3a /android | |
parent | another build integrating solution for android (diff) | |
download | core-1db66c2a1a8ad5a60c68b09ddacc1bb6e021299f.tar.gz core-1db66c2a1a8ad5a60c68b09ddacc1bb6e021299f.zip |
Bluetooth connection working (Linux).
Change-Id: Iac77c3ce0ab0ea7bda3105c58859888e55e64d2d
Diffstat (limited to 'android')
4 files changed, 76 insertions, 58 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java index 6d3735153c4c..9880b8f8964e 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java @@ -8,6 +8,8 @@ */ package org.libreoffice.impressremote.communication; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.net.Socket; import java.util.UUID; @@ -15,6 +17,8 @@ import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothDevice; import android.bluetooth.BluetoothSocket; import android.content.Context; +import android.content.Intent; +import android.support.v4.content.LocalBroadcastManager; /** * Standard Network client. Connects to a server using Sockets. @@ -31,67 +35,77 @@ public class BluetoothClient extends Client { super(aContext); try { BluetoothAdapter aAdapter = BluetoothAdapter.getDefaultAdapter(); + System.out.println("Attemtping to connect to:" + bluetoothAddress); BluetoothDevice aDevice = aAdapter .getRemoteDevice(bluetoothAddress); + aAdapter.cancelDiscovery(); BluetoothSocket aSocket = aDevice .createRfcommSocketToServiceRecord(UUID - .fromString("00001101-0000-1000-8000-00805f9b34fb")); + .fromString("00001101-0000-1000-8000-00805F9B34FB")); aSocket.connect(); + // mSocket = aSocket; + System.out.println("Connected"); + + mInputStream = aSocket.getInputStream(); + mReader = new BufferedReader(new InputStreamReader(mInputStream, + CHARSET)); + mOutputStream = aSocket.getOutputStream(); + + // mOutputStream.write(20); + // mOutputStream.write(20); + // mOutputStream.write(20); + // mOutputStream.flush(); + // System.out.println("reading"); + // while (true) { + // System.out.println(mInputStream.read()); + // } + String aTemp = mReader.readLine(); + System.out.println("SF:waited"); + if (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) { + return; + } + while (mReader.readLine().length() != 0) { + // Get rid of extra lines + } + Intent aIntent = new Intent( + CommunicationService.MSG_PAIRING_SUCCESSFUL); + LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); + startListening(); + // 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 { + // + // } + // while (mReader.readLine().length() != 0) { + // // Get rid of extra lines + // System.out.println("SF: empty line"); + // } + // System.out.println("SD: empty"); + // startListening(); } 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(); - // } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java index a6866186b8da..b001d1a862c6 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothFinder.java @@ -11,6 +11,7 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.support.v4.content.LocalBroadcastManager; public class BluetoothFinder { @@ -32,9 +33,8 @@ public class BluetoothFinder { return; // No bluetooth adapter found (emulator, special devices) } System.out.println("BT:Discovery starting"); - IntentFilter aFilter = new IntentFilter( - BluetoothAdapter.ACTION_DISCOVERY_FINISHED); - aFilter.addAction(BluetoothDevice.ACTION_FOUND); + IntentFilter aFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND); + aFilter.addAction(BluetoothAdapter.ACTION_DISCOVERY_FINISHED); mContext.registerReceiver(mReceiver, aFilter); mAdapter.enable(); @@ -64,7 +64,7 @@ public class BluetoothFinder { @Override public void onReceive(Context context, Intent aIntent) { // TODO Auto-generated method stub - System.out.println("Received intent"); + System.out.print("Received intent<<<"); System.out.println(aIntent.getAction()); if (aIntent.getAction().equals(BluetoothDevice.ACTION_FOUND)) { BluetoothDevice aDevice = (BluetoothDevice) aIntent.getExtras() @@ -77,7 +77,8 @@ public class BluetoothFinder { System.out.println("Now we have: " + mServerList.size()); Intent aNIntent = new Intent( CommunicationService.MSG_SERVERLIST_CHANGED); - mContext.sendBroadcast(aNIntent); + LocalBroadcastManager.getInstance(mContext).sendBroadcast( + aNIntent); // System.out.println("Found " + aDevice.getName()); // try { // // "f36d0a20-e876-11e1-aff1-0800200c9a66" diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java index a3fe70e40791..407540a19721 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java @@ -35,6 +35,8 @@ public class Receiver { } public void parseCommand(ArrayList<String> aCommand) { + if (aCommand.size() == 0) + return; // E.g. if empty line received for whatever reason. String aInstruction = aCommand.get(0); if (aInstruction.equals("slideshow_started")) { int aSlideShowlength = Integer.parseInt(aCommand.get(1)); diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java index 79839e779042..406383c3d71d 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java @@ -13,6 +13,7 @@ import org.libreoffice.impressremote.communication.Server.Protocol; import android.content.Context; import android.content.Intent; +import android.support.v4.content.LocalBroadcastManager; public class ServerFinder { @@ -169,7 +170,7 @@ public class ServerFinder { */ private void notifyActivity() { Intent aIntent = new Intent(CommunicationService.MSG_SERVERLIST_CHANGED); - mContext.sendBroadcast(aIntent); + LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); } public Collection<Server> getServerList() { |