/** Check if we're connected to a terminal with the given host. */ private int getConnectedState(HostBean host) { // always disconnected if we dont have backend service if (this.manager == null) return STATE_UNKNOWN; if (manager.getConnectedBridge(host) != null) return STATE_CONNECTED; if (manager.disconnected.contains(host)) return STATE_DISCONNECTED; return STATE_UNKNOWN; }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { // create menu to handle hosts // create menu to handle deleting and sharing lists AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo; final HostBean host = (HostBean) this.getListView().getItemAtPosition(info.position); menu.setHeaderTitle(host.getNickname()); // edit, disconnect, delete MenuItem connect = menu.add(R.string.list_host_disconnect); final TerminalBridge bridge = bound.getConnectedBridge(host); connect.setEnabled((bridge != null)); connect.setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { bridge.dispatchDisconnect(true); updateHandler.sendEmptyMessage(-1); return true; } }); MenuItem edit = menu.add(R.string.list_host_edit); edit.setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(HostListActivity.this, HostEditorActivity.class); intent.putExtra(Intent.EXTRA_TITLE, host.getId()); HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); return true; } }); MenuItem portForwards = menu.add(R.string.list_host_portforwards); portForwards.setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(HostListActivity.this, PortForwardListActivity.class); intent.putExtra(Intent.EXTRA_TITLE, host.getId()); HostListActivity.this.startActivityForResult(intent, REQUEST_EDIT); return true; } }); if (!TransportFactory.canForwardPorts(host.getProtocol())) portForwards.setEnabled(false); MenuItem delete = menu.add(R.string.list_host_delete); delete.setOnMenuItemClickListener( new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { // prompt user to make sure they really want this new AlertDialog.Builder(HostListActivity.this) .setMessage(getString(R.string.delete_message, host.getNickname())) .setPositiveButton( R.string.delete_pos, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // make sure we disconnect if (bridge != null) bridge.dispatchDisconnect(true); hostdb.deleteHost(host); updateHandler.sendEmptyMessage(-1); } }) .setNegativeButton(R.string.delete_neg, null) .create() .show(); return true; } }); }