summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J. R. Hunt <andrzej@ahunt.org>2012-07-11 17:44:41 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-08-06 10:22:54 +0100
commit9d7d8eb7a8a7a26e85f5fa8fde9580947bf005ab (patch)
treea88e3dec6e2e5cad9913b8670c595d54f4e088bd /android
parenta4e7636536da9548998ae7e8c6ff1bc21b5b8765 (diff)
Image export, encoding and decoding. Protocol improvements.
Change-Id: Ibbc7ac02c5946a49c1cd777abc2853fe7e158009
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/TestClient.java1
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/Client.java92
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java10
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java12
4 files changed, 77 insertions, 38 deletions
diff --git a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
index e275efb9af11..ff25d0fb7aa4 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/TestClient.java
@@ -77,6 +77,7 @@ public class TestClient extends Activity {
}
void doUnbindService() {
+ mCommunicationService.disconnect();
mCommunicationService.setActivityMessenger(null);
if (mIsBound) {
unbindService(mConnection);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
index 7014d7881aa9..049950a970bf 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java
@@ -29,48 +29,70 @@ public abstract class Client {
private Receiver mReceiver;
public void setReceiver(Receiver aReceiver) {
- aReceiver = mReceiver;
+ mReceiver = aReceiver;
}
- private void listen() {
- ByteArrayBuffer aBuffer = new ByteArrayBuffer(10);
- byte aTemp;
+ protected void startListening() {
- try {
- while ((aTemp = (byte) mInputStream.read()) != 0x0d) {
- aBuffer.append(aTemp);
- }
- } catch (IOException e1) {
- // TODO stream couldn't be opened.
- e1.printStackTrace();
- }
+ Thread t = new Thread() {
+ public void run() {
+ listen();
+ };
- String aLengthString;
- try {
- aLengthString = new String(aBuffer.toByteArray(), CHARSET);
- } catch (UnsupportedEncodingException e1) {
- throw new Error("Specified network encoding [" + CHARSET
- + " not available.");
- }
+ };
+ t.start();
+ }
- int aLength = Integer.parseInt(aLengthString);
+ private void listen() {
+ while (true) {
+ ByteArrayBuffer aBuffer = new ByteArrayBuffer(0);
+ int aTemp;
+ System.out.println("Now listening");
+ try {
+ while ((aTemp = mInputStream.read()) != 0x0a) {
+ if (aTemp == -1) {
+ System.out.println("EOF Reached!!!");
+ }
+ System.out.println("Char: " + aTemp);
+ aBuffer.append((byte) aTemp);
+ }
+ } catch (IOException e1) {
+ // TODO stream couldn't be opened.
+ e1.printStackTrace();
+ }
+ System.out.println("Escaped the loop!");
+ String aLengthString;
+ try {
+ aLengthString = new String(aBuffer.toByteArray(), CHARSET);
+ } catch (Exception e1) {
+ e1.printStackTrace();
+ throw new Error("Specified network encoding [" + CHARSET
+ + " not available.");
+ }
- byte[] aCommand = new byte[aLength];
- try {
- mInputStream.read(aCommand, 0, aLength);
- } catch (IOException e) {
- // TODO close and notify that the connection has closed
- e.printStackTrace();
- }
- String aCommandString;
- try {
- aCommandString = new String(aCommand, CHARSET);
- } catch (UnsupportedEncodingException e) {
- throw new Error("Specified network encoding [" + CHARSET
- + " not available.");
+ int aLength = Integer.parseInt(aLengthString);
+ System.out.println("Lenth = " + aLength);
+ byte[] aCommand = new byte[aLength];
+ try {
+ int readIn = 0;
+ while (readIn < aLength) {
+ readIn += mInputStream.read(aCommand, 0, aLength - readIn);
+// System.out.println("Read in :" + readIn + " of : "
+// + aLength);
+ }
+ } catch (IOException e) {
+ // TODO close and notify that the connection has closed
+ e.printStackTrace();
+ }
+ String aCommandString;
+ try {
+ aCommandString = new String(aCommand, CHARSET);
+ } catch (UnsupportedEncodingException e) {
+ throw new Error("Specified network encoding [" + CHARSET
+ + " not available.");
+ }
+ mReceiver.parseCommand(aCommandString);
}
- mReceiver.parseCommand(aCommandString);
-
}
private void parseCommand(String aCommand) {
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
index b51711dc703e..3a2b4bf52ebd 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java
@@ -4,6 +4,8 @@ import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
+import android.os.StrictMode;
+
/**
* Standard Network client. Connects to a server using Sockets.
*
@@ -16,13 +18,16 @@ public class NetworkClient extends Client {
private Socket mSocket;
public NetworkClient(String ipAddress) {
-
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
+ .permitAll().build();
+ StrictMode.setThreadPolicy(policy);
System.out.println("Attempting to open port.");
try {
mSocket = new Socket(ipAddress, PORT);
System.out.println("We seem to have opened.");
mInputStream = mSocket.getInputStream();
mOutputStream = mSocket.getOutputStream();
+ startListening();
} catch (UnknownHostException e) {
// TODO Tell the user we have a problem
e.printStackTrace();
@@ -36,7 +41,8 @@ public class NetworkClient extends Client {
@Override
public void closeConnection() {
try {
- mSocket.close();
+ if (mSocket != null)
+ mSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
index b6a3c9742b02..a46cd4fc3045 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java
@@ -30,6 +30,16 @@ public class Receiver {
return;
}
try {
+// int aPrinted = 0;
+// while (aPrinted < aJSONCommandString.length()) {
+// if (aPrinted + 100 < aJSONCommandString.length())
+// System.out.println(aJSONCommandString.substring(aPrinted,
+// aPrinted + 100));
+// else
+// System.out.println(aJSONCommandString.substring(aPrinted));
+// aPrinted += 100;
+// }
+
JSONObject aJSONCommand = new JSONObject(aJSONCommandString);
String aInstruction = aJSONCommand.getString("command");
if (aInstruction.equals("slide_updated")) {
@@ -47,7 +57,7 @@ public class Receiver {
}
} else if (aInstruction.equals("slide_preview")) {
int aSlideNumber = aJSONCommand.getInt("slide_number");
- String aImageString = aJSONCommand.getString("image");
+ String aImageString = aJSONCommand.getString("image_preview");
byte[] aImage = Base64.decode(aImageString, Base64.DEFAULT);
Message aMessage = Message.obtain(null,
CommunicationService.MSG_SLIDE_PREVIEW);