summaryrefslogtreecommitdiff
path: root/android/sdremote
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-23 15:06:22 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-23 15:07:14 +0200
commite29c020ee25fb820f4ae49c5f8d1e3df38aa76da (patch)
treecd753193ff8fbfeec72d146734a697de8422bb8f /android/sdremote
parente4b0ce8887a743d30a0107bc7b8f652b0e3b074c (diff)
Manual IP adding implemented.
Change-Id: Ifad2a206e3ddbb46094be6638581358484522695
Diffstat (limited to 'android/sdremote')
-rw-r--r--android/sdremote/AndroidManifest.xml4
-rw-r--r--android/sdremote/res/layout/dialog_addserver.xml46
-rw-r--r--android/sdremote/res/menu/selector_activity.xml6
-rw-r--r--android/sdremote/res/values/strings.xml6
-rw-r--r--android/sdremote/res/values/styles.xml3
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java75
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java52
7 files changed, 191 insertions, 1 deletions
diff --git a/android/sdremote/AndroidManifest.xml b/android/sdremote/AndroidManifest.xml
index b21ce6a2043e..6572366f7062 100644
--- a/android/sdremote/AndroidManifest.xml
+++ b/android/sdremote/AndroidManifest.xml
@@ -15,7 +15,9 @@
<application
android:label="@string/app_name"
android:theme="@style/Theme.ImpressRemote" >
- <activity android:name=".SelectorActivity" >
+ <activity
+ android:name=".SelectorActivity"
+ android:uiOptions="splitActionBarWhenNarrow" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
diff --git a/android/sdremote/res/layout/dialog_addserver.xml b/android/sdremote/res/layout/dialog_addserver.xml
new file mode 100644
index 000000000000..01ddba28c73c
--- /dev/null
+++ b/android/sdremote/res/layout/dialog_addserver.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/addserver_root"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/addserver_namelabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/addserver_entername" />
+
+ <EditText
+ android:id="@+id/addserver_nameentry"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10"
+ android:inputType="textCapWords" >
+
+ <requestFocus />
+ </EditText>
+
+ <TextView
+ android:id="@+id/addserver_addressabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/addserver_enteraddress" />
+
+ <EditText
+ android:id="@+id/addserver_addressentry"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10"
+ android:inputType="textUri" >
+
+ </EditText>
+
+ <CheckBox
+ android:id="@+id/addserver_remember"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:checked="true"
+ android:text="@string/addserver_remember" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/android/sdremote/res/menu/selector_activity.xml b/android/sdremote/res/menu/selector_activity.xml
new file mode 100644
index 000000000000..dab6e207b678
--- /dev/null
+++ b/android/sdremote/res/menu/selector_activity.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:id="@+id/menu_selector_addServer" android:title="@string/addserver" android:showAsAction="always"></item>
+
+
+</menu> \ No newline at end of file
diff --git a/android/sdremote/res/values/strings.xml b/android/sdremote/res/values/strings.xml
index 6ede30d83423..fb1ac80c845f 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -32,5 +32,11 @@
<string name="about_close">Close</string>
<string name="about_versionstring">Version: {0} (Build ID: {1})</string>
<string name="about_copyright">Copyright \u00A9 2012 LibreOffice Contributors and/or their affiliates.</string>
+ <string name="addserver">Add Server</string>
+ <string name="addserver_entername">Server name:</string>
+ <string name="addserver_enteraddress">Server address as IP or hostname:</string>
+ <string name="addserver_remember">Remember this server next time</string>
+ <string name="addserver_add">Add</string>
+ <string name="addserver_cancel">Cancel</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 de47193feb9f..73d2209746b2 100644
--- a/android/sdremote/res/values/styles.xml
+++ b/android/sdremote/res/values/styles.xml
@@ -24,6 +24,8 @@
<item name="background">@color/orange</item>
<item name="android:titleTextStyle">@style/Theme.ImpressRemote.ActionBar.Title</item>
<item name="titleTextStyle">@style/Theme.ImpressRemote.ActionBar.Title</item>
+ <item name="backgroundSplit">@color/text_grey</item>
+ <item name="android:backgroundSplit">@color/text_grey</item>
</style>
<style name="Theme.ImpressRemote.ActionBarWidget" parent="android:style/Widget.Holo.Light">
@@ -54,6 +56,7 @@
<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/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
index 5c83e5a66fe1..0de5b011d411 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
@@ -16,21 +16,29 @@ import org.libreoffice.impressremote.communication.CommunicationService;
import org.libreoffice.impressremote.communication.Server;
import org.libreoffice.impressremote.communication.Server.Protocol;
+import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
+import android.content.DialogInterface;
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.View.OnClickListener;
+import android.widget.CheckBox;
+import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.actionbarsherlock.app.SherlockActivity;
+import com.actionbarsherlock.view.Menu;
+import com.actionbarsherlock.view.MenuInflater;
+import com.actionbarsherlock.view.MenuItem;
public class SelectorActivity extends SherlockActivity {
@@ -69,6 +77,73 @@ public class SelectorActivity extends SherlockActivity {
}
@Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ MenuInflater inflater = getSupportMenuInflater();
+ inflater.inflate(R.menu.selector_activity, menu);
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.menu_selector_addServer:
+
+ AlertDialog.Builder builder;
+ AlertDialog alertDialog;
+
+ LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
+ final View layout = inflater.inflate(R.layout.dialog_addserver,
+ null);
+
+ // TextView text = (TextView) layout.findViewById(R.id.text);
+ // text.setText("Hello, this is a custom dialog!");
+ // ImageView image = (ImageView) layout.findViewById(R.id.image);
+ // image.setImageResource(R.drawable.android);
+
+ builder = new AlertDialog.Builder(this);
+ builder.setView(layout);
+ builder.setTitle(R.string.addserver);
+ builder.setPositiveButton(R.string.addserver_add,
+ new DialogInterface.OnClickListener() {
+ @Override
+ public void onClick(DialogInterface dialog,
+ int which) {
+ EditText aAddressEntry = (EditText) layout
+ .findViewById(R.id.addserver_addressentry);
+ EditText aNameEntry = (EditText) layout
+ .findViewById(R.id.addserver_nameentry);
+ CheckBox aRememberServer = (CheckBox) layout
+ .findViewById(R.id.addserver_remember);
+ mCommunicationService
+ .addServer(aAddressEntry
+ .getText()
+ .toString(),
+ aNameEntry.getText()
+ .toString(),
+ aRememberServer.isChecked());
+ refreshLists();
+ }
+ });
+ builder.setNegativeButton(R.string.addserver_cancel, null);
+ alertDialog = builder.create();
+ alertDialog.show();
+
+ // Context mContext = getApplicationContext();
+ // Dialog dialog = new Dialog(mContext);
+ //
+ // dialog.setContentView(R.layout.dialog_addserver);
+ // dialog.setTitle(R.string.addserver);
+
+ // TextView text = (TextView) dialog.findViewById(R.id.text);
+ // text.setText("Hello, this is a custom dialog!");
+ // ImageView image = (ImageView) dialog.findViewById(R.id.image);
+ // image.setImageResource(R.drawable.android);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @Override
public void onBackPressed() {
mCommunicationService.stopSearching();
Intent aIntent = new Intent(this, CommunicationService.class);
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index 3b6334f9e0a0..bafef5ec0993 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -9,10 +9,17 @@
package org.libreoffice.impressremote.communication;
import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.libreoffice.impressremote.communication.Server.Protocol;
import android.app.Service;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.os.Binder;
import android.os.IBinder;
@@ -173,6 +180,8 @@ public class CommunicationService extends Service implements Runnable {
@Override
public void onCreate() {
// TODO Create a notification (if configured).
+ loadServersFromPreferences();
+
mThread = new Thread(this);
mThread.start();
}
@@ -180,6 +189,8 @@ public class CommunicationService extends Service implements Runnable {
@Override
public void onDestroy() {
// TODO Destroy the notification (as necessary).
+ mManualServers.clear();
+
mThread.interrupt();
mThread = null;
}
@@ -192,6 +203,7 @@ public class CommunicationService extends Service implements Runnable {
ArrayList<Server> aServers = new ArrayList<Server>();
aServers.addAll(mNetworkFinder.getServerList());
aServers.addAll(mBluetoothFinder.getServerList());
+ aServers.addAll(mManualServers.values());
return aServers.toArray(new Server[aServers.size()]);
}
@@ -203,5 +215,45 @@ public class CommunicationService extends Service implements Runnable {
return mReceiver.isSlideShowRunning();
}
+ /**
+ * Manually add a new (network) server to the list of servers.
+ * @param aAddress
+ * @param aRemember
+ */
+ public void addServer(String aAddress, String aName, boolean aRemember) {
+ for (String aServer : mManualServers.keySet()) {
+ if (aServer.equals(aAddress))
+ return;
+ }
+ mManualServers.put(aAddress, new Server(Protocol.NETWORK, aAddress,
+ aName, 0));
+ if (aRemember) {
+ SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
+ MODE_PRIVATE);
+ Editor aEditor = aPref.edit();
+ aEditor.putString(aAddress, aName);
+ aEditor.apply();
+ }
+ }
+
+ /**
+ * Key to use with getSharedPreferences to obtain a Map of stored servers.
+ * The keys are the ip/hostnames, the values are the friendly names.
+ */
+ private static final String SERVERSTORAGE_KEY = "sdremote_storedServers";
+ private HashMap<String, Server> mManualServers = new HashMap<String, Server>();
+
+ void loadServersFromPreferences() {
+ SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
+ MODE_PRIVATE);
+
+ Map<String, String> aStoredMap = (Map<String, String>) aPref.getAll();
+
+ for (Entry<String, String> aServerEntry : aStoredMap.entrySet()) {
+ mManualServers.put(aServerEntry.getKey(), new Server(
+ Protocol.NETWORK, aServerEntry.getKey(),
+ aServerEntry.getValue(), 0));
+ }
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file