diff options
Diffstat (limited to 'android')
11 files changed, 156 insertions, 36 deletions
diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml index 613e7d9f232a..e60bc67abe47 100644 --- a/android/sdremote/AndroidManifest.xml +++ b/android/sdremote/AndroidManifest.xml @@ -19,6 +19,7 @@ android:name=".SelectorActivity" android:icon="@drawable/actionbar_icon_computer" android:label="@string/selector_choose_a_computer" + android:title="@string/app_name" android:uiOptions="splitActionBarWhenNarrow" > <intent-filter> <action android:name="android.intent.action.MAIN" /> @@ -28,7 +29,8 @@ </activity> <activity android:name=".PairingActivity" - android:icon="@drawable/actionbar_icon_computer" > + android:icon="@drawable/actionbar_icon_computer" + android:noHistory="true" > </activity> <service android:name=".communication.CommunicationService" > diff --git a/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java b/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java new file mode 100644 index 000000000000..4e0eb91e8aac --- /dev/null +++ b/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java @@ -0,0 +1,50 @@ +package org.libreoffice.impressremote; + +import org.libreoffice.impressremote.communication.CommunicationService; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.content.IntentFilter; + +/** + * This class is used to centralise the processing of Broadcasts concerning + * presentation/connection status changes which result in a change of activity. + * + * I.e. this will switch to the correct activity and correctly set up the + * activity backstack when switching activity. + * + * To use create this on activity startup, and pass messages from your + * BroadcastReceiver's onReceive. + * + */ +public class ActivityChangeBroadcastProcessor { + + private Activity mActivity; + + public ActivityChangeBroadcastProcessor(Activity aActivity) { + mActivity = aActivity; + } + + public void addToFilter(IntentFilter aFilter) { + aFilter.addAction(CommunicationService.STATUS_CONNECTED_NOSLIDESHOW); + aFilter.addAction(CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING); + } + + public void onReceive(Context aContext, Intent aIntent) { + if (aIntent.getAction().equals( + CommunicationService.STATUS_CONNECTED_NOSLIDESHOW)) { + Intent nIntent = new Intent(mActivity, + StartPresentationActivity.class); + nIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + mActivity.startActivity(nIntent); + } else if (aIntent + .getAction() + .equals(CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING)) { + Intent nIntent = new Intent(mActivity, PresentationActivity.class); + nIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + mActivity.startActivity(nIntent); + } + } + +} diff --git a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java index 495aad49f207..9fcd13e5201a 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PairingActivity.java @@ -29,18 +29,23 @@ import com.actionbarsherlock.app.SherlockActivity; public class PairingActivity extends SherlockActivity { private CommunicationService mCommunicationService; private TextView mPinText; + private ActivityChangeBroadcastProcessor mBroadcastProcessor; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); bindService(new Intent(this, CommunicationService.class), mConnection, Context.BIND_IMPORTANT); IntentFilter aFilter = new IntentFilter( CommunicationService.MSG_PAIRING_STARTED); aFilter.addAction(CommunicationService.MSG_PAIRING_SUCCESSFUL); + + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + mBroadcastProcessor.addToFilter(aFilter); + LocalBroadcastManager.getInstance(this).registerReceiver(mListener, aFilter); @@ -106,7 +111,7 @@ public class PairingActivity extends SherlockActivity { StartPresentationActivity.class); startActivity(nIntent); } - + mBroadcastProcessor.onReceive(aContext, aIntent); } }; diff --git a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java index e877c64bcc09..a2765e40f344 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/PresentationActivity.java @@ -8,9 +8,11 @@ import org.libreoffice.impressremote.communication.CommunicationService; import org.libreoffice.impressremote.communication.SlideShow.Timer; import android.app.AlertDialog; +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.content.SharedPreferences; import android.os.Bundle; @@ -19,6 +21,7 @@ import android.os.IBinder; import android.preference.PreferenceManager; import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentTransaction; +import android.support.v4.content.LocalBroadcastManager; import android.text.format.DateFormat; import android.util.AttributeSet; import android.view.KeyEvent; @@ -41,14 +44,23 @@ public class PresentationActivity extends SherlockFragmentActivity { private ThumbnailFragment mThumbnailFragment; private PresentationFragment mPresentationFragment; private static ActionBarManager mActionBarManager; + private ActivityChangeBroadcastProcessor mBroadcastProcessor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + bindService(new Intent(this, CommunicationService.class), mConnection, Context.BIND_IMPORTANT); + IntentFilter aFilter = new IntentFilter(); + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + mBroadcastProcessor.addToFilter(aFilter); + LocalBroadcastManager.getInstance(this).registerReceiver(mListener, + aFilter); + //((FrameLayout) findViewById(R.id.framelayout)).addView(mLayout); setContentView(R.layout.activity_presentation); if (savedInstanceState == null) { @@ -67,6 +79,18 @@ public class PresentationActivity extends SherlockFragmentActivity { } @Override + public void onBackPressed() { + if (getSupportFragmentManager().getBackStackEntryCount() > 0) { + super.onBackPressed(); + return; + } + Intent aIntent = new Intent(this, SelectorActivity.class); + aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(aIntent); + mCommunicationService.disconnect(); + } + + @Override protected void onDestroy() { mActionBarManager.stop(); unbindService(mConnection); @@ -501,4 +525,12 @@ public class PresentationActivity extends SherlockFragmentActivity { } } + + private BroadcastReceiver mListener = new BroadcastReceiver() { + + @Override + public void onReceive(Context aContext, Intent aIntent) { + mBroadcastProcessor.onReceive(aContext, aIntent); + } + }; } diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java index ba692c31008b..b26d9ee7f862 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java @@ -49,6 +49,7 @@ public class SelectorActivity extends SherlockActivity { private View mNetworkContainer; private LinearLayout mNetworkList; private TextView mNoServerLabel; + private ActivityChangeBroadcastProcessor mBroadcastProcessor; /** Called when the activity is first created. */ @Override @@ -58,6 +59,10 @@ public class SelectorActivity extends SherlockActivity { IntentFilter aFilter = new IntentFilter( CommunicationService.MSG_SERVERLIST_CHANGED); + + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + mBroadcastProcessor.addToFilter(aFilter); + LocalBroadcastManager.getInstance(this).registerReceiver(mListener, aFilter); @@ -191,7 +196,9 @@ public class SelectorActivity extends SherlockActivity { if (aIntent.getAction().equals( CommunicationService.MSG_SERVERLIST_CHANGED)) { refreshLists(); + return; } + 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 98026fd055df..43f0d1458a77 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java @@ -19,11 +19,13 @@ import com.actionbarsherlock.app.SherlockActivity; public class StartPresentationActivity extends SherlockActivity { private CommunicationService mCommunicationService = null; private boolean mIsBound = false; + private ActivityChangeBroadcastProcessor mBroadcastProcessor; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_startpresentation); bindService(new Intent(this, CommunicationService.class), mConnection, Context.BIND_IMPORTANT); @@ -31,6 +33,10 @@ public class StartPresentationActivity extends SherlockActivity { IntentFilter aFilter = new IntentFilter( CommunicationService.MSG_SLIDESHOW_STARTED); + + mBroadcastProcessor = new ActivityChangeBroadcastProcessor(this); + mBroadcastProcessor.addToFilter(aFilter); + LocalBroadcastManager.getInstance(this).registerReceiver(mListener, aFilter); @@ -39,6 +45,14 @@ public class StartPresentationActivity extends SherlockActivity { } @Override + public void onBackPressed() { + Intent aIntent = new Intent(this, SelectorActivity.class); + aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); + startActivity(aIntent); + mCommunicationService.disconnect(); + } + + @Override protected void onDestroy() { super.onDestroy(); unbindService(mConnection); @@ -81,13 +95,7 @@ public class StartPresentationActivity extends SherlockActivity { @Override public void onReceive(Context aContext, Intent aIntent) { - if (aIntent.getAction().equals( - CommunicationService.MSG_SLIDESHOW_STARTED)) { - Intent nIntent = new Intent(StartPresentationActivity.this, - PresentationActivity.class); - startActivity(nIntent); - } - + mBroadcastProcessor.onReceive(aContext, aIntent); } }; } diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java index c495e4c6688c..740602205043 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/BluetoothClient.java @@ -30,8 +30,8 @@ public class BluetoothClient extends Client { public BluetoothClient(Server aServer, CommunicationService aCommunicationService, - boolean aBluetoothWasEnabled) { - super(aServer, aCommunicationService); + Receiver aReceiver, boolean aBluetoothWasEnabled) { + super(aServer, aCommunicationService, aReceiver); try { mAdapter = BluetoothAdapter.getDefaultAdapter(); mBluetoothWasEnabled = aBluetoothWasEnabled; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java index 148da4acdf1a..5e6a50b937f1 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Client.java @@ -45,14 +45,13 @@ public abstract class Client { protected CommunicationService mCommunicationService; - protected Client(Server aServer, CommunicationService aCommunicationService) { + protected Client(Server aServer, + CommunicationService aCommunicationService, + Receiver aReceiver) { mServer = aServer; mCommunicationService = aCommunicationService; - latestInstance = this; - } - - public void setReceiver(Receiver aReceiver) { mReceiver = aReceiver; + latestInstance = this; } protected void startListening() { diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index 982dc7aaed94..ff46f2624790 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -73,7 +73,6 @@ public class CommunicationService extends Service implements Runnable { while (true) { // Condition try { - wait(); } catch (InterruptedException e) { // We have finished @@ -84,21 +83,23 @@ public class CommunicationService extends Service implements Runnable { if ((mStateDesired == State.CONNECTED && mState == State.CONNECTED) || (mStateDesired == State.DISCONNECTED && mState == State.CONNECTED)) { mClient.closeConnection(); + mClient = null; mState = State.DISCONNECTED; } if (mStateDesired == State.CONNECTED) { mState = State.CONNECTING; switch (mServerDesired.getProtocol()) { case NETWORK: - mClient = new NetworkClient(mServerDesired, this); + mClient = new NetworkClient(mServerDesired, this, + mReceiver); break; case BLUETOOTH: mClient = new BluetoothClient(mServerDesired, this, + mReceiver, mBluetoothPreviouslyEnabled); break; } mTransmitter = new Transmitter(mClient); - mClient.setReceiver(mReceiver); mState = State.CONNECTED; } } @@ -178,6 +179,19 @@ public class CommunicationService extends Service implements Runnable { public static final String MSG_PAIRING_STARTED = "PAIRING_STARTED"; public static final String MSG_PAIRING_SUCCESSFUL = "PAIRING_SUCCESSFUL"; + /** + * Notify the UI that the service has connected to a server AND a slideshow + * is running. + * In this case the PresentationActivity should be started. + */ + public static final String STATUS_CONNECTED_SLIDESHOW_RUNNING = "STATUS_CONNECTED_SLIDESHOW_RUNNING"; + /** + * Notify the UI that the service has connected to a server AND no slideshow + * is running. + * In this case the StartPresentationActivity should be started. + */ + public static final String STATUS_CONNECTED_NOSLIDESHOW = "STATUS_CONNECTED_NOSLIDESHOW"; + private Transmitter mTransmitter; private Client mClient; diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java index c939613a25ef..24b62771e02a 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java @@ -32,8 +32,9 @@ public class NetworkClient extends Client { private Socket mSocket; public NetworkClient(Server aServer, - CommunicationService aCommunicationService) { - super(aServer, aCommunicationService); + CommunicationService aCommunicationService, + Receiver aReceiver) { + super(aServer, aCommunicationService, aReceiver); try { mName = aServer.getName(); mSocket = new Socket(aServer.getAddress(), PORT); diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java index 955459c5c3e9..c4a097ef6f70 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/Receiver.java @@ -10,9 +10,6 @@ package org.libreoffice.impressremote.communication; import java.util.ArrayList; -import org.libreoffice.impressremote.PresentationActivity; -import org.libreoffice.impressremote.StartPresentationActivity; - import android.content.Context; import android.content.Intent; import android.support.v4.content.LocalBroadcastManager; @@ -46,19 +43,24 @@ public class Receiver { int aCurrentSlide = Integer.parseInt(aCommand.get(2)); mSlideShow.setLength(aSlideShowlength); mSlideShow.setCurrentSlide(aCurrentSlide); - // Intent aIntent = new Intent( - // CommunicationService.MSG_SLIDESHOW_STARTED); - // LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); - Intent aIntent = new Intent(mContext.getApplicationContext(), - PresentationActivity.class); - aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.getApplicationContext().startActivity(aIntent); + // Intent aIntent = new Intent(mContext.getApplicationContext(), + // PresentationActivity.class); + // aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + // mContext.getApplicationContext().startActivity(aIntent); + Intent aIntent = new Intent( + CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING); + LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); } else if (aInstruction.equals("slideshow_finished")) { mSlideShow = new SlideShow(mContext); - Intent aIntent = new Intent(mContext.getApplicationContext(), - StartPresentationActivity.class); - aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - mContext.getApplicationContext().startActivity(aIntent); + // Intent aIntent = new Intent(mContext.getApplicationContext(), + // StartPresentationActivity.class); + // aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + // aIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); + // mContext.getApplicationContext().startActivity(aIntent); + Intent aIntent = new Intent( + CommunicationService.STATUS_CONNECTED_NOSLIDESHOW); + LocalBroadcastManager.getInstance(mContext).sendBroadcast(aIntent); } else { if (mSlideShow == null) return; |