From 5962129ea8076ae816900684e620498ca90103cc Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Mon, 17 Sep 2012 17:06:43 +0200 Subject: Dialog for connection, more activity launching cleanup. Change-Id: I1ff8508daa2863020c6d7fa735f0f23b1ce96d8f --- android/sdremote/AndroidManifest.xml | 4 ++- android/sdremote/res/values/strings.xml | 1 + .../ActivityChangeBroadcastProcessor.java | 6 +++++ .../impressremote/SelectorActivity.java | 21 ++++++++++++--- .../impressremote/StartPresentationActivity.java | 6 ----- .../communication/CommunicationService.java | 2 ++ .../impressremote/communication/NetworkClient.java | 31 +++++++++++++++------- 7 files changed, 52 insertions(+), 19 deletions(-) (limited to 'android') diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml index e60bc67abe47..6db223ee7d00 100644 --- a/android/sdremote/AndroidManifest.xml +++ b/android/sdremote/AndroidManifest.xml @@ -14,7 +14,9 @@ + android:theme="@style/Theme.ImpressRemote" + android:title="@string/app_name" + android:icon="@drawable/ic_launcher" > Searching for computers… Remove server Choose a Computer + Attempting to connect to {0}... In Impress, click on the "Slideshow" menu and select "Impress Remote". Choose \"{0}\" as your device. Then input this PIN: diff --git a/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java b/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java index 4e0eb91e8aac..3df8874984b8 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java +++ b/android/sdremote/src/org/libreoffice/impressremote/ActivityChangeBroadcastProcessor.java @@ -29,6 +29,7 @@ public class ActivityChangeBroadcastProcessor { public void addToFilter(IntentFilter aFilter) { aFilter.addAction(CommunicationService.STATUS_CONNECTED_NOSLIDESHOW); aFilter.addAction(CommunicationService.STATUS_CONNECTED_SLIDESHOW_RUNNING); + aFilter.addAction(CommunicationService.STATUS_PAIRING_PINVALIDATION); } public void onReceive(Context aContext, Intent aIntent) { @@ -44,6 +45,11 @@ public class ActivityChangeBroadcastProcessor { Intent nIntent = new Intent(mActivity, PresentationActivity.class); nIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); mActivity.startActivity(nIntent); + } else if (aIntent.getAction().equals( + CommunicationService.STATUS_PAIRING_PINVALIDATION)) { + Intent nIntent = new Intent(mActivity, PairingActivity.class); + nIntent.putExtras(aIntent.getExtras()); // Pass on pin and other info. + mActivity.startActivity(nIntent); } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java index b26d9ee7f862..0803045fcac7 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java @@ -8,6 +8,7 @@ */ package org.libreoffice.impressremote; +import java.text.MessageFormat; import java.util.Arrays; import java.util.HashMap; import java.util.Map.Entry; @@ -17,6 +18,7 @@ import org.libreoffice.impressremote.communication.Server; import org.libreoffice.impressremote.communication.Server.Protocol; import android.app.AlertDialog; +import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -51,6 +53,8 @@ public class SelectorActivity extends SherlockActivity { private TextView mNoServerLabel; private ActivityChangeBroadcastProcessor mBroadcastProcessor; + ProgressDialog mProgressDialog = null; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -160,6 +164,9 @@ public class SelectorActivity extends SherlockActivity { mCommunicationService.stopSearching(); } doUnbindService(); + if (mProgressDialog != null) { + mProgressDialog.dismiss(); + } } void doBindService() { @@ -303,9 +310,17 @@ public class SelectorActivity extends SherlockActivity { } if (aDesiredServer != null) { mCommunicationService.connectTo(aDesiredServer); - Intent aIntent = new Intent(SelectorActivity.this, - PairingActivity.class); - startActivity(aIntent); + // Connect Service and wait for broadcast + String aFormat = getResources().getString( + R.string.selector_dialog_connecting); + String aDialogText = MessageFormat.format(aFormat, + aDesiredServer.getName()); + + mProgressDialog = ProgressDialog.show(SelectorActivity.this, + "", aDialogText, true); + // Intent aIntent = new Intent(SelectorActivity.this, + // PairingActivity.class); + // startActivity(aIntent); } } diff --git a/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java b/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java index 43f0d1458a77..ab59946a6a96 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java +++ b/android/sdremote/src/org/libreoffice/impressremote/StartPresentationActivity.java @@ -66,12 +66,6 @@ public class StartPresentationActivity extends SherlockActivity { mCommunicationService = ((CommunicationService.CBinder) aService) .getService(); - if (mCommunicationService.isSlideShowRunning()) { - Intent nIntent = new Intent(StartPresentationActivity.this, - PresentationActivity.class); - startActivity(nIntent); - } - } @Override diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java index ff46f2624790..085cdff98b9f 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java @@ -192,6 +192,8 @@ public class CommunicationService extends Service implements Runnable { */ public static final String STATUS_CONNECTED_NOSLIDESHOW = "STATUS_CONNECTED_NOSLIDESHOW"; + public static final String STATUS_PAIRING_PINVALIDATION = "STATUS_PAIRING_PINVALIDATION"; + 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 24b62771e02a..f875a056db38 100644 --- a/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java +++ b/android/sdremote/src/org/libreoffice/impressremote/communication/NetworkClient.java @@ -56,17 +56,30 @@ public class NetworkClient extends Client { + "\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(mCommunicationService) - .sendBroadcast(aIntent); + + 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); + 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 System.out.println("SF: empty line"); -- cgit