summaryrefslogtreecommitdiff
path: root/android/sdremote
diff options
context:
space:
mode:
authorArtur Dryomov <artur.dryomov@gmail.com>2013-07-11 19:56:30 +0300
committerMichael Meeks <michael.meeks@suse.com>2013-07-25 18:01:51 +0100
commit8eb2f0ef16d5a12bd2b2251aaa394be90a9eebf3 (patch)
treee70cc534a40959f936ca090801a1d8f528fec5ed /android/sdremote
parentfc961aeaf667fbcbc4990678b987bf4291b06572 (diff)
Add the computer connection activity.
It shows proper instructions for Bluetooth and WiFi at moment, it should be helpful for solving possible issues with the connection process. Change-Id: Ie81bd211fa2b47e3392e1ef83a52a15ea54fe370
Diffstat (limited to 'android/sdremote')
-rw-r--r--android/sdremote/AndroidManifest.xml5
-rw-r--r--android/sdremote/res/layout/fragment_computer_connection.xml76
-rw-r--r--android/sdremote/res/values/dimens.xml6
-rw-r--r--android/sdremote/res/values/strings.xml7
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionActivity.java28
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionFragment.java217
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/ComputersFragment.java11
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java7
8 files changed, 356 insertions, 1 deletions
diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml
index 36064da7ac4c..e8225a33cc3c 100644
--- a/android/sdremote/AndroidManifest.xml
+++ b/android/sdremote/AndroidManifest.xml
@@ -32,6 +32,11 @@
</activity>
<activity
+ android:name=".ComputerConnectionActivity"
+ android:label="@string/title_connection">
+ </activity>
+
+ <activity
android:name=".SelectorActivity"
android:label="@string/selector_choose_a_computer"
android:uiOptions="splitActionBarWhenNarrow">
diff --git a/android/sdremote/res/layout/fragment_computer_connection.xml b/android/sdremote/res/layout/fragment_computer_connection.xml
new file mode 100644
index 000000000000..7b004569bfaa
--- /dev/null
+++ b/android/sdremote/res/layout/fragment_computer_connection.xml
@@ -0,0 +1,76 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ViewAnimator xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/view_animator"
+ android:inAnimation="@android:anim/fade_in"
+ android:outAnimation="@android:anim/fade_out"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent">
+
+ <ProgressBar
+ android:id="@android:id/progress"
+ style="?android:progressBarStyleLarge"
+ android:layout_gravity="center"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"/>
+
+ <LinearLayout
+ android:id="@+id/layout_pin_validation"
+ android:orientation="vertical"
+ android:paddingLeft="@dimen/padding_horizontal_connection_layout"
+ android:paddingRight="@dimen/padding_horizontal_connection_layout"
+ android:layout_gravity="center"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:text="@string/message_impress_pin_validation"
+ android:gravity="center_horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <TextView
+ android:id="@+id/text_pin"
+ android:textSize="@dimen/text_size_pin"
+ android:gravity="center_horizontal"
+ android:paddingTop="@dimen/padding_vertical_pin"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/layout_error_message"
+ android:orientation="vertical"
+ android:paddingLeft="@dimen/padding_horizontal_connection_layout"
+ android:paddingRight="@dimen/padding_horizontal_connection_layout"
+ android:layout_gravity="center"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+
+ <TextView
+ android:id="@+id/text_error_title"
+ android:text="@string/message_connection_failed_title"
+ android:textStyle="bold"
+ android:textSize="@dimen/text_size_error_title"
+ android:gravity="center_horizontal"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <TextView
+ android:id="@+id/text_primary_error_message"
+ android:text="@string/message_impress_remote_enabling"
+ android:gravity="center_horizontal"
+ android:paddingTop="@dimen/padding_vertical_error_message"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ <TextView
+ android:id="@+id/text_secondary_error_message"
+ android:gravity="center_horizontal"
+ android:paddingTop="@dimen/padding_vertical_error_message"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"/>
+
+ </LinearLayout>
+
+</ViewAnimator> \ No newline at end of file
diff --git a/android/sdremote/res/values/dimens.xml b/android/sdremote/res/values/dimens.xml
index 61f9ded3591a..4af04087d552 100644
--- a/android/sdremote/res/values/dimens.xml
+++ b/android/sdremote/res/values/dimens.xml
@@ -2,7 +2,13 @@
<resources>
<dimen name="padding_horizontal_list_item">8dp</dimen>
+ <dimen name="padding_horizontal_connection_layout">40dp</dimen>
+
+ <dimen name="padding_vertical_pin">10dp</dimen>
+ <dimen name="padding_vertical_error_message">10dp</dimen>
<dimen name="text_size_list_item">18sp</dimen>
+ <dimen name="text_size_pin">35sp</dimen>
+ <dimen name="text_size_error_title">20sp</dimen>
</resources> \ No newline at end of file
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 865067de9d28..ceffa3eeb620 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -69,7 +69,14 @@
<string name="title_bluetooth" translatable="false">Bluetooth</string>
<string name="title_wifi" translatable="false">WiFi</string>
<string name="title_licenses">Open source licenses</string>
+ <string name="title_connection">Connection</string>
<string name="menu_licenses">Open source licenses</string>
+ <string name="message_impress_pin_validation">Go to “Slide Show → Impress Remote” in LibreOffice Impress and enter the code.</string>
+ <string name="message_connection_failed_title">Connection failed</string>
+ <string name="message_impress_remote_enabling">Make sure you enabled remote control. Go to “Tools → Options → LibreOffice Impress → General” in LibreOffice Impress.</string>
+ <string name="message_impress_wifi_enabling">You should enable experimental features at “Tools → Options → LibreOffice → Advanced” as well.</string>
+ <string name="message_impress_pairing_check">If you have Bluetooth pairing issues check instructions related to your desktop OS.</string>
+
</resources>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionActivity.java b/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionActivity.java
new file mode 100644
index 000000000000..e773f51c2ff4
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionActivity.java
@@ -0,0 +1,28 @@
+package org.libreoffice.impressremote;
+
+import android.os.Bundle;
+import android.support.v4.app.FragmentTransaction;
+
+import com.actionbarsherlock.app.SherlockFragmentActivity;
+import org.libreoffice.impressremote.communication.Server;
+
+public class ComputerConnectionActivity extends SherlockFragmentActivity {
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ setUpComputerConnectionFragment(extractReceivedComputer());
+ }
+
+ private void setUpComputerConnectionFragment(Server aComputer) {
+ FragmentTransaction aTransaction = getSupportFragmentManager().beginTransaction();
+
+ aTransaction.replace(android.R.id.content, ComputerConnectionFragment.newInstance(aComputer));
+
+ aTransaction.commit();
+ }
+
+ private Server extractReceivedComputer() {
+ return getIntent().getParcelableExtra("COMPUTER");
+ }
+}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionFragment.java b/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionFragment.java
new file mode 100644
index 000000000000..2ed0fabc1fcc
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/ComputerConnectionFragment.java
@@ -0,0 +1,217 @@
+package org.libreoffice.impressremote;
+
+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.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.ViewAnimator;
+
+import com.actionbarsherlock.app.SherlockFragment;
+import org.libreoffice.impressremote.communication.CommunicationService;
+import org.libreoffice.impressremote.communication.Server;
+
+public class ComputerConnectionFragment extends SherlockFragment implements ServiceConnection {
+ private Server mComputer;
+
+ private CommunicationService mCommunicationService;
+ private BroadcastReceiver mIntentsReceiver;
+
+ public static ComputerConnectionFragment newInstance(Server aComputer) {
+ ComputerConnectionFragment aFragment = new ComputerConnectionFragment();
+
+ aFragment.setArguments(buildArguments(aComputer));
+
+ return aFragment;
+ }
+
+ private static Bundle buildArguments(Server aComputer) {
+ Bundle aArguments = new Bundle();
+
+ aArguments.putParcelable("COMPUTER", aComputer);
+
+ return aArguments;
+ }
+
+ @Override
+ public void onCreate(Bundle aSavedInstance) {
+ super.onCreate(aSavedInstance);
+
+ mComputer = getArguments().getParcelable("COMPUTER");
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater aInflater, ViewGroup aContainer, Bundle aSavedInstance) {
+ return aInflater.inflate(R.layout.fragment_computer_connection, aContainer, false);
+ }
+
+ @Override
+ public void onActivityCreated(Bundle savedInstanceState) {
+ super.onActivityCreated(savedInstanceState);
+
+ bindService();
+ }
+
+ private void bindService() {
+ Intent aServiceIntent = new Intent(getActivity(), CommunicationService.class);
+
+ getActivity().bindService(aServiceIntent, this, Context.BIND_AUTO_CREATE);
+ }
+
+ @Override
+ public void onServiceConnected(ComponentName aComponentName, IBinder aBinder) {
+ CommunicationService.CBinder aServiceBinder = (CommunicationService.CBinder) aBinder;
+
+ mCommunicationService = aServiceBinder.getService();
+
+ mCommunicationService.connectTo(mComputer);
+ }
+
+ private boolean isServiceBound() {
+ return mCommunicationService != null;
+ }
+
+ @Override
+ public void onServiceDisconnected(ComponentName aComponentName) {
+ mCommunicationService = null;
+ }
+
+ @Override
+ public void onResume() {
+ super.onResume();
+
+ registerIntentsReceiver();
+ }
+
+ private void registerIntentsReceiver() {
+ mIntentsReceiver = new IntentsReceiver(this);
+ IntentFilter aIntentFilter = buildIntentsReceiverFilter();
+
+ LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mIntentsReceiver, aIntentFilter);
+ }
+
+ private static class IntentsReceiver extends BroadcastReceiver {
+ private final ComputerConnectionFragment mComputerConnectionFragment;
+
+ public IntentsReceiver(ComputerConnectionFragment aComputerConnectionFragment) {
+ mComputerConnectionFragment = aComputerConnectionFragment;
+ }
+
+ @Override
+ public void onReceive(Context aContext, Intent aIntent) {
+ if (CommunicationService.MSG_PAIRING_STARTED.equals(aIntent.getAction())) {
+ String aPin = aIntent.getStringExtra("PIN");
+
+ mComputerConnectionFragment.setUpPinValidationInstructions(aPin);
+
+ return;
+ }
+
+ if (CommunicationService.MSG_PAIRING_SUCCESSFUL.equals(aIntent.getAction())) {
+ mComputerConnectionFragment.setUpPresentation();
+
+ return;
+ }
+
+ if (CommunicationService.STATUS_CONNECTION_FAILED.equals(aIntent.getAction())) {
+ mComputerConnectionFragment.setUpErrorMessage();
+ }
+ }
+ }
+
+ private IntentFilter buildIntentsReceiverFilter() {
+ IntentFilter aIntentFilter = new IntentFilter();
+ aIntentFilter.addAction(CommunicationService.MSG_PAIRING_STARTED);
+ aIntentFilter.addAction(CommunicationService.MSG_PAIRING_SUCCESSFUL);
+ aIntentFilter.addAction(CommunicationService.STATUS_CONNECTION_FAILED);
+
+ return aIntentFilter;
+ }
+
+ public void setUpPinValidationInstructions(String aPin) {
+ TextView aPinTextView = (TextView) getView().findViewById(R.id.text_pin);
+ aPinTextView.setText(aPin);
+
+ showPinValidationLayout();
+ }
+
+ private void showPinValidationLayout() {
+ ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator);
+ LinearLayout aValidationLayout = (LinearLayout) getView().findViewById(R.id.layout_pin_validation);
+
+ aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aValidationLayout));
+ }
+
+ public void setUpPresentation() {
+ // TODO: implement
+
+ getActivity().finish();
+ }
+
+ public void setUpErrorMessage() {
+ TextView aSecondaryMessageTextView = (TextView) getView().findViewById(R.id.text_secondary_error_message);
+ aSecondaryMessageTextView.setText(buildSecondaryErrorMessage());
+
+ showErrorMessageLayout();
+ }
+
+ private String buildSecondaryErrorMessage() {
+ switch (mComputer.getProtocol()) {
+ case BLUETOOTH:
+ return getString(R.string.message_impress_pairing_check);
+
+ case TCP:
+ return getString(R.string.message_impress_wifi_enabling);
+
+ default:
+ return "";
+ }
+ }
+
+ private void showErrorMessageLayout() {
+ ViewAnimator aViewAnimator = (ViewAnimator) getView().findViewById(R.id.view_animator);
+ LinearLayout aMessageLayout = (LinearLayout) getView().findViewById(R.id.layout_error_message);
+
+ aViewAnimator.setDisplayedChild(aViewAnimator.indexOfChild(aMessageLayout));
+ }
+
+ @Override
+ public void onPause() {
+ super.onPause();
+
+ unregisterIntentsReceiver();
+ }
+
+ private void unregisterIntentsReceiver() {
+ try {
+ getActivity().unregisterReceiver(mIntentsReceiver);
+ } catch (IllegalArgumentException e) {
+ // Receiver not registered.
+ // Fixed in Honeycomb: Android’s issue #6191.
+ }
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ unbindService();
+ }
+
+ private void unbindService() {
+ if (!isServiceBound()) {
+ return;
+ }
+
+ getActivity().unbindService(this);
+ }
+}
diff --git a/android/sdremote/src/org/libreoffice/impressremote/ComputersFragment.java b/android/sdremote/src/org/libreoffice/impressremote/ComputersFragment.java
index b776af5cae62..80cf4c0fe7fc 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/ComputersFragment.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/ComputersFragment.java
@@ -20,6 +20,8 @@ import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.support.v4.content.LocalBroadcastManager;
+import android.view.View;
+import android.widget.ListView;
import com.actionbarsherlock.app.SherlockListFragment;
import org.libreoffice.impressremote.communication.CommunicationService;
@@ -209,6 +211,15 @@ public class ComputersFragment extends SherlockListFragment implements ServiceCo
// Fixed in Honeycomb: Android’s issue #6191.
}
}
+
+ @Override
+ public void onListItemClick(ListView aListView, View aView, int aPosition, long aId) {
+ Server aComputer = getComputersAdapter().getItem(aPosition);
+
+ Intent aIntent = new Intent(getActivity(), ComputerConnectionActivity.class);
+ aIntent.putExtra("COMPUTER", aComputer);
+ startActivity(aIntent);
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 7718d39cd5e3..d85661d860d8 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -119,7 +119,12 @@ public class CommunicationService extends Service implements Runnable, MessagesL
if (mStateDesired == State.CONNECTED) {
mState = State.CONNECTING;
- openConnection();
+ try {
+ openConnection();
+ }
+ catch (RuntimeException e) {
+ connectionFailed();
+ }
}
}
}