From 38cc47f8b1715525cf4a2ccaab7464e9ed1c734c Mon Sep 17 00:00:00 2001 From: "Siqi LIU (via Code Review)" Date: Fri, 12 Apr 2013 23:49:21 +0000 Subject: fdo#61873 - add WiFi experimental feature alert. fixes reconnect crash. Won't crash when server-end disconnect. seperate Client construction and initialization so that Client() will release its mutex lock and won't block service.run(). Otherwise onBackPressed() will be blocked in PairingActivity Change-Id: I424a470aa02b0c74b28cb9f9ba79489aa0d4ab1b --- android/sdremote/AndroidManifest.xml | 5 + android/sdremote/res/layout/activity_reconnect.xml | 12 ++- android/sdremote/res/layout/dialog_addserver.xml | 12 ++- android/sdremote/res/values/strings.xml | 6 +- .../libreoffice/impressremote/PairingActivity.java | 53 +++++++++- .../impressremote/SelectorActivity.java | 66 ++++++++---- .../impressremote/StartPresentationActivity.java | 15 +++ .../communication/BluetoothClient.java | 37 ++++--- .../impressremote/communication/Client.java | 7 +- .../communication/CommunicationService.java | 23 +++-- .../impressremote/communication/NetworkClient.java | 111 +++++++++++---------- .../communication/ReconnectionActivity.java | 81 +++++++++++++++ .../impressremote/communication/Server.java | 35 ++++++- 13 files changed, 361 insertions(+), 102 deletions(-) (limited to 'android') diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml index d279fbb51c9f..8eaf63da1df2 100644 --- a/android/sdremote/AndroidManifest.xml +++ b/android/sdremote/AndroidManifest.xml @@ -57,6 +57,11 @@ android:icon="@drawable/icon_options" android:label="@string/options" > + + diff --git a/android/sdremote/res/layout/activity_reconnect.xml b/android/sdremote/res/layout/activity_reconnect.xml index 8baa76d1a73f..0d2f8bb75de4 100644 --- a/android/sdremote/res/layout/activity_reconnect.xml +++ b/android/sdremote/res/layout/activity_reconnect.xml @@ -40,7 +40,17 @@ android:gravity="center_horizontal" android:text="@string/reconnect_description2" android:textAppearance="?android:attr/textAppearanceMedium" /> + + - \ No newline at end of file + diff --git a/android/sdremote/res/layout/dialog_addserver.xml b/android/sdremote/res/layout/dialog_addserver.xml index 01ddba28c73c..475aabd6d7a1 100644 --- a/android/sdremote/res/layout/dialog_addserver.xml +++ b/android/sdremote/res/layout/dialog_addserver.xml @@ -3,8 +3,18 @@ android:id="@+id/addserver_root" android:layout_width="match_parent" android:layout_height="match_parent" + android:padding="12dp" android:orientation="vertical" > + + - \ No newline at end of file + diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml index a08edd1345ae..84edffc8a3f7 100644 --- a/android/sdremote/res/values/strings.xml +++ b/android/sdremote/res/values/strings.xml @@ -7,6 +7,7 @@ Handle to resize view. Blank Screen Options + Reconnect... h:mmaa mm:ss Start @@ -15,6 +16,8 @@ Reset Resume Decline Calls + Help + #1 Verify Impress is running \n#2 For Bluetooth user, enable \"Preference\"-\"LibreOffice Impress\"-\"General\"-\"Enable remote control\"\n#3 For WiFi user, tick \"Preferece\"-\"LibreOffice\"-\"Advanced\"-\"Enable Experimental Features\" \n Automatically decline all incoming calls. Volume Switching Change slides using volume buttons @@ -49,6 +52,7 @@ Add Cancel Your connection has been dropped. - Attempting to reconnect… + Please try to reconnect + This is still an experimental feature. You need to \"enable experimental features\" in \"Preference\"-\"LibreOffice\"-\"Advanced\" on your computer. \nThe use over Bluetooth is recommanded. diff --git a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java index f9e6c9282fda..0b0624e533b2 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java @@ -10,18 +10,25 @@ package org.libreoffice.impressremote; import java.text.MessageFormat; +import org.libreoffice.impressremote.communication.CommunicationService; +import org.libreoffice.impressremote.communication.CommunicationService.State; import android.content.BroadcastReceiver; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; +import android.content.ServiceConnection; import android.os.Bundle; +import android.os.IBinder; import android.support.v4.content.LocalBroadcastManager; import android.widget.TextView; import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.view.MenuItem; public class PairingActivity extends SherlockActivity { private ActivityChangeBroadcastProcessor mBroadcastProcessor; + private CommunicationService mCommunicationService; /** Called when the activity is first created. */ @Override @@ -29,8 +36,8 @@ public class PairingActivity extends SherlockActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_pairing); - - mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + bindService(new Intent(this, CommunicationService.class), mConnection, + Context.BIND_IMPORTANT); IntentFilter aFilter = new IntentFilter(); @@ -55,6 +62,22 @@ public class PairingActivity extends SherlockActivity { getSupportActionBar().setTitle(aServerName); } + @Override + public void onPause(){ + super.onPause(); + unbindService(mConnection); + } + + @Override + public void onBackPressed() { + mCommunicationService.getClient().closeConnection(); + + Intent aIntent = new Intent(this, SelectorActivity.class); + aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(aIntent); + } + + private BroadcastReceiver mListener = new BroadcastReceiver() { @Override @@ -63,6 +86,32 @@ public class PairingActivity extends SherlockActivity { } }; + private ServiceConnection mConnection = new ServiceConnection() { + + @Override + public void onServiceConnected(ComponentName aClassName, + IBinder aService) { + mCommunicationService = ((CommunicationService.CBinder) aService) + .getService(); + + } + + @Override + public void onServiceDisconnected(ComponentName aClassName) { + mCommunicationService = null; + } + }; + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + } + return super.onOptionsItemSelected(item); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java index 3b0f6842ba76..560e5d30a5a6 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java @@ -63,6 +63,8 @@ public class SelectorActivity extends SherlockActivity { super.onCreate(savedInstanceState); setContentView(R.layout.activity_selector); + if (mCommunicationService != null) + mCommunicationService.disconnect(); IntentFilter aFilter = new IntentFilter( CommunicationService.MSG_SERVERLIST_CHANGED); aFilter.addAction(CommunicationService.STATUS_CONNECTION_FAILED); @@ -223,26 +225,50 @@ public class SelectorActivity extends SherlockActivity { if (mProgressDialog != null) { mProgressDialog.dismiss(); - String aFormat = getResources().getString( - R.string.selector_dialog_connectionfailed); - String aDialogText = MessageFormat.format(aFormat, - mCommunicationService - .getPairingDeviceName()); - - AlertDialog.Builder builder = new AlertDialog.Builder( - SelectorActivity.this); - builder.setMessage(aDialogText) - .setCancelable(false) - .setPositiveButton( - R.string.selector_dialog_connectionfailed_ok, - new DialogInterface.OnClickListener() { - public void onClick( - DialogInterface dialog, - int id) { - dialog.dismiss(); - } - }); - builder.show(); + if (mCommunicationService != null) { + String aFormat = getResources().getString( + R.string.selector_dialog_connectionfailed); + String aDialogText = MessageFormat.format(aFormat, + mCommunicationService.getPairingDeviceName()); + + AlertDialog.Builder builder = new AlertDialog.Builder( + SelectorActivity.this); + builder.setMessage(aDialogText) + .setCancelable(false) + .setNeutralButton(R.string.help, + new DialogInterface.OnClickListener() { + public void onClick( + DialogInterface dialog, + int id) { + dialog.dismiss(); + AlertDialog.Builder builder = new AlertDialog.Builder( + SelectorActivity.this); + builder.setMessage( + R.string.ConnectionFailedHelp) + .setCancelable(false) + .setPositiveButton( + R.string.selector_dialog_connectionfailed_ok, + new DialogInterface.OnClickListener() { + public void onClick( + DialogInterface dialog, + int id) { + dialog.dismiss(); + } + }); + builder.show(); + } + }) + .setPositiveButton( + R.string.selector_dialog_connectionfailed_ok, + new DialogInterface.OnClickListener() { + public void onClick( + DialogInterface dialog, + int id) { + dialog.dismiss(); + } + }); + builder.show(); + } } } mBroadcastProcessor.onReceive(aContext, aIntent); diff --git a/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java index 44a3368e845b..163b8fa6ba44 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java @@ -10,6 +10,7 @@ package org.libreoffice.impressremote; import org.libreoffice.impressremote.communication.CommunicationService; +import android.app.AlertDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -18,6 +19,7 @@ import android.content.IntentFilter; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; +import android.support.v4.app.FragmentTransaction; import android.support.v4.content.LocalBroadcastManager; import android.view.View; import android.view.View.OnClickListener; @@ -37,6 +39,7 @@ public class StartPresentationActivity extends SherlockActivity { bindService(new Intent(this, CommunicationService.class), mConnection, Context.BIND_IMPORTANT); + getSupportActionBar().setDisplayHomeAsUpEnabled(true); IntentFilter aFilter = new IntentFilter( CommunicationService.MSG_SLIDESHOW_STARTED); @@ -97,6 +100,18 @@ public class StartPresentationActivity extends SherlockActivity { mBroadcastProcessor.onReceive(aContext, aIntent); } }; + + @Override + public boolean onOptionsItemSelected( + com.actionbarsherlock.view.MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java index 07a626f3803e..c2e7a61dbc16 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java @@ -58,6 +58,27 @@ public class BluetoothClient extends Client { mSocket.connect(); Log.i(Globals.TAG, "BluetoothClient: connected"); + } + + @Override + public void closeConnection() { + try { + if (mSocket != null) + mSocket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + protected void onDisconnect() { + if (!mBluetoothWasEnabled) { + mAdapter.disable(); + } + } + + @Override + public void validating() throws IOException { + // TODO Auto-generated method stub mInputStream = mSocket.getInputStream(); mReader = new BufferedReader(new InputStreamReader(mInputStream, @@ -80,22 +101,6 @@ public class BluetoothClient extends Client { } - @Override - public void closeConnection() { - try { - if (mSocket != null) - mSocket.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - protected void onDisconnect() { - if (!mBluetoothWasEnabled) { - mAdapter.disable(); - } - } - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java index 198b87332af6..ea6d4b9f4383 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java @@ -15,7 +15,11 @@ import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.util.ArrayList; +import org.libreoffice.impressremote.Globals; +import org.libreoffice.impressremote.communication.CommunicationService.State; + import android.content.Intent; +import android.util.Log; /** * Generic Client for the remote control. To implement a Client for a specific @@ -37,6 +41,7 @@ public abstract class Client { public abstract void closeConnection(); + public abstract void validating() throws IOException; private Receiver mReceiver; protected Server mServer; @@ -75,11 +80,11 @@ public abstract class Client { aList.add(aTemp); } if (aTemp == null) { - mCommunicationService.connectTo(mServer); Intent aIntent = new Intent( mCommunicationService .getApplicationContext(), ReconnectionActivity.class); + aIntent.putExtra("server", mServer); aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mCommunicationService.getApplicationContext() .startActivity(aIntent); diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index 8028f00ea956..f7401fbde351 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -102,30 +102,36 @@ public class CommunicationService extends Service implements Runnable { case NETWORK: mClient = new NetworkClient(mServerDesired, this, mReceiver); + mClient.validating(); break; case BLUETOOTH: mClient = new BluetoothClient(mServerDesired, this, mReceiver, mBluetoothPreviouslyEnabled); + mClient.validating(); break; } mTransmitter = new Transmitter(mClient); mState = State.CONNECTED; } catch (IOException e) { Log.i(Globals.TAG, "CommunicationService.run: " + e); - mClient = null; - mState = State.DISCONNECTED; - Intent aIntent = new Intent( - CommunicationService.STATUS_CONNECTION_FAILED); - LocalBroadcastManager.getInstance(this) - .sendBroadcast(aIntent); + connextionFailed(); } } } + Log.i(Globals.TAG, "CommunicationService.finished work"); } } } + private void connextionFailed() { + mClient = null; + mState = State.DISCONNECTED; + Intent aIntent = new Intent( + CommunicationService.STATUS_CONNECTION_FAILED); + LocalBroadcastManager.getInstance(this).sendBroadcast(aIntent); + } + private boolean mBluetoothPreviouslyEnabled; public void startSearching() { @@ -174,6 +180,7 @@ public class CommunicationService extends Service implements Runnable { } public void disconnect() { + Log.d(Globals.TAG, "Service Disconnected"); synchronized (mConnectionVariableMutex) { mStateDesired = State.DISCONNECTED; synchronized (this) { @@ -328,6 +335,10 @@ public class CommunicationService extends Service implements Runnable { } + public Client getClient() { + return mClient; + } + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java index 2e88a171a8a5..fbd51fa23f85 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java @@ -31,73 +31,38 @@ public class NetworkClient extends Client { private static final int PORT = 1599; private Socket mSocket; + private Intent mIntent; + private String mPin; + private Server mServer; public NetworkClient(Server aServer, - CommunicationService aCommunicationService, - Receiver aReceiver) throws UnknownHostException, - IOException { + CommunicationService aCommunicationService, Receiver aReceiver) + throws UnknownHostException, IOException { super(aServer, aCommunicationService, aReceiver); - mSocket = new Socket(aServer.getAddress(), PORT); + mServer = aServer; + mSocket = new Socket(mServer.getAddress(), PORT); mInputStream = mSocket.getInputStream(); mReader = new BufferedReader(new InputStreamReader(mInputStream, - CHARSET)); + CHARSET)); mOutputStream = mSocket.getOutputStream(); + // Pairing. - String aPin = setupPin(aServer); - Intent aIntent = new Intent(CommunicationService.MSG_PAIRING_STARTED); - aIntent.putExtra("PIN", aPin); - mPin = aPin; + mPin = setupPin(mServer); + mIntent = new Intent(CommunicationService.MSG_PAIRING_STARTED); + mIntent.putExtra("PIN", mPin); LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast( - aIntent); + mIntent); // 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... - String aTemp = mReader.readLine(); - - if (aTemp == null) { - throw new IOException( - "End of stream reached before any data received."); - } - - while (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) { - if (aTemp.equals("LO_SERVER_VALIDATING_PIN")) { - // Broadcast that we need a pin screen. - aIntent = new Intent( - CommunicationService.STATUS_PAIRING_PINVALIDATION); - aIntent.putExtra("PIN", aPin); - aIntent.putExtra("SERVERNAME", aServer.getName()); - mPin = aPin; - LocalBroadcastManager.getInstance(mCommunicationService) - .sendBroadcast(aIntent); - while (mReader.readLine().length() != 0) { - // Read off empty lines - } - aTemp = mReader.readLine(); - } else { - return; - } - } - - aIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL); - LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast( - aIntent); - - while (mReader.readLine().length() != 0) { - // Get rid of extra lines - Log.i(Globals.TAG, "NetworkClient: extra line"); - } - Log.i(Globals.TAG, "NetworkClient: calling startListening"); - startListening(); - + String aName = CommunicationService.getDeviceName(); // TODO: get the + // proper name + sendCommand("LO_SERVER_CLIENT_PAIR\n" + aName + "\n" + mPin + "\n\n"); } private String setupPin(Server aServer) { // Get settings SharedPreferences aPreferences = mCommunicationService - .getSharedPreferences("sdremote_authorisedremotes", - android.content.Context.MODE_PRIVATE); + .getSharedPreferences("sdremote_authorisedremotes", + android.content.Context.MODE_PRIVATE); if (aPreferences.contains(aServer.getName())) { return aPreferences.getString(aServer.getName(), ""); } else { @@ -132,6 +97,46 @@ public class NetworkClient extends Client { } } + @Override + public void validating() throws IOException { + + // Wait until we get the appropriate string back... + String aTemp = mReader.readLine(); + + if (aTemp == null) { + throw new IOException( + "End of stream reached before any data received."); + } + + while (!aTemp.equals("LO_SERVER_SERVER_PAIRED")) { + if (aTemp.equals("LO_SERVER_VALIDATING_PIN")) { + // Broadcast that we need a pin screen. + mIntent = new Intent( + CommunicationService.STATUS_PAIRING_PINVALIDATION); + mIntent.putExtra("PIN", mPin); + mIntent.putExtra("SERVERNAME", mServer.getName()); + LocalBroadcastManager.getInstance(mCommunicationService) + .sendBroadcast(mIntent); + while (mReader.readLine().length() != 0) { + // Read off empty lines + } + aTemp = mReader.readLine(); + } else { + return; + } + } + + mIntent = new Intent(CommunicationService.MSG_PAIRING_SUCCESSFUL); + LocalBroadcastManager.getInstance(mCommunicationService).sendBroadcast( + mIntent); + + while (mReader.readLine().length() != 0) { + // Get rid of extra lines + Log.i(Globals.TAG, "NetworkClient: extra line"); + } + Log.i(Globals.TAG, "NetworkClient: calling startListening"); + startListening(); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ReconnectionActivity.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ReconnectionActivity.java index 8417cde28535..86227372fc85 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/ReconnectionActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ReconnectionActivity.java @@ -8,18 +8,99 @@ */ package org.libreoffice.impressremote.communication; +import org.libreoffice.impressremote.ActivityChangeBroadcastProcessor; import org.libreoffice.impressremote.R; +import org.libreoffice.impressremote.SelectorActivity; +import android.content.BroadcastReceiver; +import android.content.ComponentName; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; +import android.content.ServiceConnection; import android.os.Bundle; +import android.os.IBinder; +import android.support.v4.content.LocalBroadcastManager; import com.actionbarsherlock.app.SherlockActivity; +import com.actionbarsherlock.view.MenuItem; public class ReconnectionActivity extends SherlockActivity { + private ActivityChangeBroadcastProcessor mBroadcastProcessor; + private CommunicationService mCommunicationService; + + // private TextView mCountDownTextView; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_reconnect); + // mCountDownTextView = (TextView) findViewById(R.id.countDownTV); + + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + + bindService(new Intent(this, CommunicationService.class), mConnection, + Context.BIND_IMPORTANT); + + final Server desiredServer = getIntent().getParcelableExtra("server"); + + IntentFilter aFilter = new IntentFilter(); + + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + mBroadcastProcessor.addToFilter(aFilter); + + LocalBroadcastManager.getInstance(this).registerReceiver(mListener, + aFilter); + + getSupportActionBar().setTitle(desiredServer.getName()); + + // TODO Connection to desired server + // Create a countdown clock for 10 seconds, then double the delay + // with every failure. Until it reaches 1min. Like Gmail retry + + } + + private BroadcastReceiver mListener = new BroadcastReceiver() { + + @Override + public void onReceive(Context aContext, Intent aIntent) { + mBroadcastProcessor.onReceive(aContext, aIntent); + } + }; + + private ServiceConnection mConnection = new ServiceConnection() { + + @Override + public void onServiceConnected(ComponentName aClassName, + IBinder aService) { + mCommunicationService = ((CommunicationService.CBinder) aService) + .getService(); + + } + + @Override + public void onServiceDisconnected(ComponentName aClassName) { + mCommunicationService = null; + } + }; + + @Override + public void onBackPressed() { + Intent aIntent = new Intent(this, SelectorActivity.class); + aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(aIntent); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + + switch (item.getItemId()) { + case android.R.id.home: + onBackPressed(); + return true; + } + return super.onOptionsItemSelected(item); } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java index 77e6eb3fcc7f..503f87a42fc6 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Server.java @@ -8,7 +8,10 @@ */ package org.libreoffice.impressremote.communication; -public class Server { +import android.os.Parcel; +import android.os.Parcelable; + +public class Server implements Parcelable { public enum Protocol { NETWORK, BLUETOOTH @@ -56,6 +59,36 @@ public class Server { public String toString() { return getClass().getName() + '@' + Integer.toHexString(hashCode()) + ":{" + mAddress + "," + mName + "}"; } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeString(mAddress); + out.writeString(mName); + out.writeString(mProtocol.name()); + out.writeLong(mTimeDiscovered); + } + + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { + public Server createFromParcel(Parcel in) { + return new Server(in); + } + + public Server[] newArray(int size) { + return new Server[size]; + } + }; + + private Server(Parcel in) { + mAddress = in.readString(); + mName = in.readString(); + mProtocol = Protocol.valueOf(in.readString()); + mTimeDiscovered = in.readLong(); + } } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit