Implemented Server selector.

Change-Id: Ib6d0712c498e831a559df00d301ea2d4b851deed
This commit is contained in:
Andrzej J.R. Hunt 2012-08-03 14:08:40 +02:00 committed by Michael Meeks
parent 98e52c4747
commit b5d6989e8b
8 changed files with 260 additions and 29 deletions

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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>

View File

@ -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: */

View File

@ -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: */

View File

@ -135,7 +135,6 @@ public class ServerFinder {
}
public Server[] getServerList() {
return (Server[]) mServerList.toArray();
return mServerList.toArray(new Server[mServerList.size()]);
}
}