summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authorAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-23 20:23:34 +0200
committerAndrzej J.R. Hunt <andrzej@ahunt.org>2012-08-23 20:24:24 +0200
commitfb0a28df82aa67db4536232ab502a8cc85ac9e4f (patch)
tree4e4ec1857052005f6dc6dadbd8c23815855af0db /android
parent4908c8d79745057ebece07c7834e318a7366d6d0 (diff)
Removal of manually added servers.
Change-Id: Ia46eccb8c7ace05054e952f49e2a2c65a462b83f
Diffstat (limited to 'android')
-rw-r--r--android/sdremote/res/menu/selector_contextmenu.xml4
-rw-r--r--android/sdremote/res/values/strings.xml1
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java53
-rw-r--r--android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java41
4 files changed, 70 insertions, 29 deletions
diff --git a/android/sdremote/res/menu/selector_contextmenu.xml b/android/sdremote/res/menu/selector_contextmenu.xml
new file mode 100644
index 000000000000..d3c99a15592c
--- /dev/null
+++ b/android/sdremote/res/menu/selector_contextmenu.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<menu xmlns:android="http://schemas.android.com/apk/res/android" >
+ <item android:id="@+id/selector_context_delete" android:title="@string/selector_delete"></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 fb1ac80c845f..61a340428ac2 100644
--- a/android/sdremote/res/values/strings.xml
+++ b/android/sdremote/res/values/strings.xml
@@ -23,6 +23,7 @@
<string name="bluetooth">Bluetooth</string>
<string name="wifi">WI-FI</string>
<string name="selector_noservers">Searching for computers…</string>
+ <string name="selector_delete">Remove server</string>
<string name="pairing_instructions_1">In Impress, click on the "Slideshow" menu and select "Impress Remote".</string>
<string name="pairing_instructions_2_deviceName">Choose \"{0}\" as your device.</string>
<string name="pairing_instructions_3">Then input this PIN:</string>
diff --git a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
index 0de5b011d411..5503408f935f 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/SelectorActivity.java
@@ -95,11 +95,6 @@ public class SelectorActivity extends SherlockActivity {
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);
@@ -128,16 +123,6 @@ public class SelectorActivity extends SherlockActivity {
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);
@@ -213,6 +198,20 @@ public class SelectorActivity extends SherlockActivity {
private HashMap<Server, View> mBluetoothServers = new HashMap<Server, View>();
private HashMap<Server, View> mNetworkServers = new HashMap<Server, View>();
+ private void deleteServer(View aView) {
+ for (Entry<Server, View> aEntry : mNetworkServers.entrySet()) {
+ System.out.println(aEntry.getKey().getName());
+ System.out.println(aView);
+ System.out.println(aEntry.getValue());
+ if (aEntry.getValue() == aView
+ .findViewById(R.id.selector_sub_label)
+ || aEntry.getValue().findViewById(
+ R.id.selector_sub_label) == aView
+ .findViewById(R.id.selector_sub_label))
+ mCommunicationService.removeServer(aEntry.getKey());
+ }
+ }
+
private void refreshLists() {
if (mCommunicationService != null) {
@@ -256,6 +255,9 @@ public class SelectorActivity extends SherlockActivity {
aText.setText(aServer.getName());
aLayout.addView(aView);
aMap.put(aServer, aText);
+
+ // registerForContextMenu(aView);
+ registerForContextMenu(aText);
}
}
@@ -304,5 +306,26 @@ public class SelectorActivity extends SherlockActivity {
}
};
+ View aLastSelected = null;
+
+ public void onCreateContextMenu(android.view.ContextMenu menu, View v,
+ android.view.ContextMenu.ContextMenuInfo menuInfo) {
+ super.onCreateContextMenu(menu, v, menuInfo);
+ aLastSelected = v;
+ android.view.MenuInflater inflater = getMenuInflater();
+ inflater.inflate(R.menu.selector_contextmenu, menu);
+
+ }
+
+ @Override
+ public boolean onContextItemSelected(android.view.MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.selector_context_delete:
+ deleteServer(aLastSelected);
+ refreshLists();
+ return true;
+ }
+ return super.onContextItemSelected(item);
+ }
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ \ No newline at end of file
diff --git a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
index bafef5ec0993..89b94dd5ccea 100644
--- a/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
+++ b/android/sdremote/src/org/libreoffice/impressremote/communication/CommunicationService.java
@@ -216,6 +216,26 @@ public class CommunicationService extends Service implements Runnable {
}
/**
+ * 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));
+ }
+ }
+
+ /**
* Manually add a new (network) server to the list of servers.
* @param aAddress
* @param aRemember
@@ -236,24 +256,17 @@ public class CommunicationService extends Service implements Runnable {
}
}
- /**
- * 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>();
+ public void removeServer(Server aServer) {
+
+ mManualServers.remove(aServer.getAddress());
- void loadServersFromPreferences() {
SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
MODE_PRIVATE);
+ Editor aEditor = aPref.edit();
+ aEditor.remove(aServer.getAddress());
+ aEditor.apply();
- 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