Removal of manually added servers.
Change-Id: Ia46eccb8c7ace05054e952f49e2a2c65a462b83f
This commit is contained in:
4
android/sdremote/res/menu/selector_contextmenu.xml
Normal file
4
android/sdremote/res/menu/selector_contextmenu.xml
Normal file
@@ -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>
|
@@ -23,6 +23,7 @@
|
|||||||
<string name="bluetooth">Bluetooth</string>
|
<string name="bluetooth">Bluetooth</string>
|
||||||
<string name="wifi">WI-FI</string>
|
<string name="wifi">WI-FI</string>
|
||||||
<string name="selector_noservers">Searching for computers…</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_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_2_deviceName">Choose \"{0}\" as your device.</string>
|
||||||
<string name="pairing_instructions_3">Then input this PIN:</string>
|
<string name="pairing_instructions_3">Then input this PIN:</string>
|
||||||
|
@@ -95,11 +95,6 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
final View layout = inflater.inflate(R.layout.dialog_addserver,
|
final View layout = inflater.inflate(R.layout.dialog_addserver,
|
||||||
null);
|
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 = new AlertDialog.Builder(this);
|
||||||
builder.setView(layout);
|
builder.setView(layout);
|
||||||
builder.setTitle(R.string.addserver);
|
builder.setTitle(R.string.addserver);
|
||||||
@@ -128,16 +123,6 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
alertDialog = builder.create();
|
alertDialog = builder.create();
|
||||||
alertDialog.show();
|
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 true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
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> mBluetoothServers = new HashMap<Server, View>();
|
||||||
private HashMap<Server, View> mNetworkServers = 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() {
|
private void refreshLists() {
|
||||||
if (mCommunicationService != null) {
|
if (mCommunicationService != null) {
|
||||||
|
|
||||||
@@ -256,6 +255,9 @@ public class SelectorActivity extends SherlockActivity {
|
|||||||
aText.setText(aServer.getName());
|
aText.setText(aServer.getName());
|
||||||
aLayout.addView(aView);
|
aLayout.addView(aView);
|
||||||
aMap.put(aServer, aText);
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
@@ -215,6 +215,26 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
return mReceiver.isSlideShowRunning();
|
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<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.
|
* Manually add a new (network) server to the list of servers.
|
||||||
* @param aAddress
|
* @param aAddress
|
||||||
@@ -236,24 +256,17 @@ public class CommunicationService extends Service implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public void removeServer(Server aServer) {
|
||||||
* Key to use with getSharedPreferences to obtain a Map of stored servers.
|
|
||||||
* The keys are the ip/hostnames, the values are the friendly names.
|
mManualServers.remove(aServer.getAddress());
|
||||||
*/
|
|
||||||
private static final String SERVERSTORAGE_KEY = "sdremote_storedServers";
|
|
||||||
private HashMap<String, Server> mManualServers = new HashMap<String, Server>();
|
|
||||||
|
|
||||||
void loadServersFromPreferences() {
|
|
||||||
SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
|
SharedPreferences aPref = getSharedPreferences(SERVERSTORAGE_KEY,
|
||||||
MODE_PRIVATE);
|
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: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
Reference in New Issue
Block a user