summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-03 14:08:40 +0200
committerMichael Meeks <michael.meeks@suse.com>2012-08-06 10:23:10 +0100
commitb5d6989e8b7a739881f54ce9db0d560fb69e7eb9 (patch)
treeb3f89831b5f29e39fd018879f59424b75e906c59 /android
parent98e52c47474e91dcaa5d41d8fd4925b17689fd65 (diff)
Implemented Server selector.
Change-Id: Ib6d0712c498e831a559df00d301ea2d4b851deed
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/AndroidManifest.xml5
-rw-r--r--android/sdremote/res/layout/activity_selector.xml72
-rw-r--r--android/sdremote/res/layout/activity_selector_sublayout_server.xml20
-rw-r--r--android/sdremote/res/values/strings.xml3
-rw-r--r--android/sdremote/res/values/styles.xml2
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/Launcher.java23
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java161
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java3
8 files changed, 260 insertions, 29 deletions
diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml
index 14f457ba52b2..cea2e1482e1f 100644
--- a/android/sdremote/AndroidManifest.xml
+++ b/android/sdremote/AndroidManifest.xml
@@ -13,12 +13,9 @@
<application
android:label="@string/app_name"
android:theme="@style/Theme.ImpressRemote" >
- <activity
- android:name="TestClient"
- android:label="" >
+ <activity android:name=".SelectorActivity" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
-
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
diff --git a/android/sdremote/res/layout/activity_selector.xml b/android/sdremote/res/layout/activity_selector.xml
new file mode 100644
index 000000000000..6f4cfa158cd8
--- /dev/null
+++ b/android/sdremote/res/layout/activity_selector.xml
@@ -0,0 +1,72 @@
+<?xml version="1.0" encoding="utf-8"?>
+<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent" >
+
+ <LinearLayout
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_margin="10dip"
+ android:orientation="vertical" >
+
+ <LinearLayout
+ android:id="@+id/selector_container_bluetooth"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/selector_label_none"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/selector_noservers"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <TextView
+ android:id="@+id/selector_label_bluetooth"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/bluetooth"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <ImageView
+ android:id="@+id/selector_divider1"
+ android:layout_width="fill_parent"
+ android:layout_height="2dip"
+ android:src="@color/medium_grey" />
+
+ <LinearLayout
+ android:id="@+id/selector_list_bluetooth"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" />
+ </LinearLayout>
+
+ <LinearLayout
+ android:id="@+id/selector_container_network"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/selector_label_network"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/wifi"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <ImageView
+ android:id="@+id/selector_divider1"
+ android:layout_width="fill_parent"
+ android:layout_height="2dip"
+ android:src="@color/medium_grey" />
+
+ <LinearLayout
+ android:id="@+id/selector_list_network"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" />
+ </LinearLayout>
+ </LinearLayout>
+
+</ScrollView> \ No newline at end of file
diff --git a/android/sdremote/res/layout/activity_selector_sublayout_server.xml b/android/sdremote/res/layout/activity_selector_sublayout_server.xml
new file mode 100644
index 000000000000..14bec2349d8e
--- /dev/null
+++ b/android/sdremote/res/layout/activity_selector_sublayout_server.xml
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical" >
+
+ <ImageView
+ android:id="@+id/sub_divider"
+ android:layout_width="fill_parent"
+ android:layout_height="1dip"
+ android:src="@color/medium_grey" />
+
+ <TextView
+ android:id="@+id/selector_sub_label"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_margin="10dip"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index ac51b864f488..0e14caa5a519 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -20,5 +20,8 @@
<string name="options_volumeswitching_descripton">Change slides using volume buttons</string>
<string name="options_switchcomputer">Switch computer</string>
<string name="blankscreen_return">Return to Slide</string>
+ <string name="bluetooth">Bluetooth</string>
+ <string name="wifi">WI-FI</string>
+ <string name="selector_noservers">Searching for computers…</string>
</resources> \ No newline at end of file
diff --git a/android/sdremote/res/values/styles.xml b/android/sdremote/res/values/styles.xml
index c95fb0cdbce7..e5a465100222 100644
--- a/android/sdremote/res/values/styles.xml
+++ b/android/sdremote/res/values/styles.xml
@@ -7,6 +7,7 @@
<color name="black">#000000</color>
<color name="light_grey">#E8E9E8</color>
<color name="medium_grey">#C1C2C1</color>
+ <color name="text_grey">#5E5F5F</color>
<integer name="thumbnail_border_width">3</integer>
@@ -48,6 +49,7 @@
<item name="android:actionDropDownStyle">@style/Theme.ImpressRemote.ActionBarMenu</item>
<item name="android:windowBackground">@color/light_grey</item>
<item name="android:homeAsUpIndicator">@drawable/up_indicator_white</item>
+ <item name="android:textColor">@color/text_grey</item>
</style>
</resources> \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/Launcher.java b/android/sdremote/src/org/libreoffice/impressremote/Launcher.java
deleted file mode 100644
index 8b27ebf01eeb..000000000000
--- a/android/sdremote/src/org/libreoffice/impressremote/Launcher.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- */
-package org.libreoffice.impressremote;
-
-import android.app.Activity;
-import android.os.Bundle;
-
-public class Launcher extends Activity {
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
-
-}
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
new file mode 100644
index 000000000000..4bed7105fca2
--- /dev/null
+++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
@@ -0,0 +1,161 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+package org.libreoffice.impressremote;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map.Entry;
+
+import org.libreoffice.impressremote.communication.CommunicationService;
+import org.libreoffice.impressremote.communication.CommunicationService.Protocol;
+import org.libreoffice.impressremote.communication.CommunicationService.Server;
+
+import android.app.Activity;
+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.View;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+public class SelectorActivity extends Activity {
+
+ private CommunicationService mCommunicationService;
+
+ private LinearLayout mBluetoothList;
+ private LinearLayout mNetworkList;
+ private TextView mNoServerLabel;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.activity_selector);
+
+ IntentFilter aFilter = new IntentFilter(
+ CommunicationService.MSG_SERVERLIST_CHANGED);
+ LocalBroadcastManager.getInstance(this).registerReceiver(mListener,
+ aFilter);
+
+ mBluetoothList = (LinearLayout) findViewById(R.id.selector_list_bluetooth);
+ mNetworkList = (LinearLayout) findViewById(R.id.selector_list_network);
+ mNoServerLabel = (TextView) findViewById(R.id.selector_label_none);
+
+ refreshLists();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ doBindService();
+ }
+
+ @Override
+ protected void onPause() {
+ // TODO Auto-generated method stub
+ super.onPause();
+ doUnbindService();
+ }
+
+ void doBindService() {
+ Intent aIntent = new Intent(this, CommunicationService.class);
+ startService(aIntent);
+ bindService(aIntent, mConnection, Context.BIND_IMPORTANT);
+ }
+
+ void doUnbindService() {
+ unbindService(mConnection);
+ }
+
+ 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;
+ }
+ };
+
+ private BroadcastReceiver mListener = new BroadcastReceiver() {
+
+ @Override
+ public void onReceive(Context aContext, Intent aIntent) {
+ if (aIntent.getAction().equals(
+ CommunicationService.MSG_SERVERLIST_CHANGED)) {
+ refreshLists();
+ }
+
+ }
+ };
+
+ private HashMap<Server, View> mBluetoothServers = new HashMap<Server, View>();
+ private HashMap<Server, View> mNetworkServers = new HashMap<Server, View>();
+
+ private void refreshLists() {
+ if (mCommunicationService == null)
+ return;
+
+ Server[] aServers = mCommunicationService.getServers();
+
+ // Bluetooth -- Remove old
+ for (Entry<Server, View> aEntry : mBluetoothServers.entrySet()) {
+ if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
+ mBluetoothServers.remove(aEntry.getKey());
+ mBluetoothList.removeView(aEntry.getValue());
+ }
+ }
+ // Network -- Remove old
+ for (Entry<Server, View> aEntry : mNetworkServers.entrySet()) {
+ if (!Arrays.asList(aServers).contains(aEntry.getKey())) {
+ mNetworkServers.remove(aEntry.getKey());
+ mNetworkList.removeView(aEntry.getValue());
+ }
+ }
+ // Add all new
+ for (Server aServer : aServers) {
+ boolean aIsBluetooth = (aServer.getProtocol() == Protocol.BLUETOOTH);
+ HashMap<Server, View> aMap = aIsBluetooth ? mBluetoothServers
+ : mNetworkServers;
+ LinearLayout aLayout = aIsBluetooth ? mBluetoothList : mNetworkList;
+
+ if (!aMap.containsValue(aServer)) {
+ View aView = getLayoutInflater().inflate(
+ R.layout.activity_selector_sublayout_server,
+ aLayout);
+ TextView aText = (TextView) aView
+ .findViewById(R.id.selector_sub_label);
+ aText.setText(aServer.getName());
+ aMap.put(aServer, aView);
+ }
+
+ }
+ // Hide as necessary
+
+ mBluetoothList.setVisibility((mBluetoothServers.size() != 0) ? View.VISIBLE
+ : View.INVISIBLE);
+ mNetworkList.setVisibility((mNetworkServers.size() != 0) ? View.VISIBLE
+ : View.INVISIBLE);
+
+ mNoServerLabel.setVisibility((mBluetoothServers.size() == 0)
+ && (mNetworkServers.size() == 0) ? View.VISIBLE
+ : View.INVISIBLE);
+ }
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
index 5ce7897e2d0c..c30f9c25085d 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/ServerFinder.java
@@ -135,7 +135,6 @@ public class ServerFinder {
}
public Server[] getServerList() {
- return (Server[]) mServerList.toArray();
+ return mServerList.toArray(new Server[mServerList.size()]);
}
-
}