From fb0a28df82aa67db4536232ab502a8cc85ac9e4f Mon Sep 17 00:00:00 2001 From: "Andrzej J.R. Hunt" Date: Thu, 23 Aug 2012 20:23:34 +0200 Subject: [PATCH] Removal of manually added servers. Change-Id: Ia46eccb8c7ace05054e952f49e2a2c65a462b83f --- .../res/menu/selector_contextmenu.xml | 4 ++ android/sdremote/res/values/strings.xml | 1 + .../impressremote/SelectorActivity.java | 53 +++++++++++++------ .../communication/CommunicationService.java | 41 +++++++++----- 4 files changed, 70 insertions(+), 29 deletions(-) create mode 100644 android/sdremote/res/menu/selector_contextmenu.xml 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 @@ + + + + \ 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 @@ Bluetooth WI-FI Searching for computers… + Remove server In Impress, click on the "Slideshow" menu and select "Impress Remote". Choose \"{0}\" as your device. Then input this PIN: 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 mBluetoothServers = new HashMap(); private HashMap mNetworkServers = new HashMap(); + private void deleteServer(View aView) { + for (Entry 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 @@ -215,6 +215,26 @@ public class CommunicationService extends Service implements Runnable { return mReceiver.isSlideShowRunning(); } + /** + * 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 mManualServers = new HashMap(); + + void loadServersFromPreferences() { + SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY, + MODE_PRIVATE); + + Map aStoredMap = (Map) aPref.getAll(); + + for (Entry 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 @@ -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 mManualServers = new HashMap(); + 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 aStoredMap = (Map) aPref.getAll(); - - for (Entry 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