Ejemplo n.º 1
0
  /** Do the autoconnect stuff */
  private void autoconnect() {
    // If we don't have any servers to go with.
    if (Atomic.getInstance().getServersAsArrayList().size() < 1) return;
    // Or we've done this already
    if (!doAutoconnect.getValue()) return;
    // We don't need to get this far.

    // Are we connected to the greater wide not-us?
    NetworkInfo ninf =
        ((ConnectivityManager) (this.getSystemService(Service.CONNECTIVITY_SERVICE)))
            .getActiveNetworkInfo();
    // If there's no way out, or we aren't actually connected,
    if (ninf == null || ninf.getState() != NetworkInfo.State.CONNECTED) {
      // We don't need to bother, but we should say something.
      Toast.makeText(this, "Autoconnect skipped due to network outage", Toast.LENGTH_LONG).show();
      return;
    }
    // Some slime...
    Log.d("ServerList", "Doing autoconnect");
    for (int idx = 0; idx < adapter.getCount(); idx++) {
      Server s = adapter.getItem(idx);
      if (s.getAutoconnect() && s.getStatus() == Status.DISCONNECTED) {
        ConnectServer(s);
      }
    }
  }
Ejemplo n.º 2
0
  /** On long click */
  @Override
  public boolean onItemLongClick(AdapterView<?> l, View v, int position, long id) {
    final Server server = adapter.getItem(position);

    if (server == null) {
      // "Add server" view selected
      return true;
    }

    // This lets us change if we're going to CONNECT or DISCONNECT from a server from the long-press
    // menu.
    int mangleString = R.string.connect;

    if (server.getStatus() != Status.DISCONNECTED) {
      mangleString = R.string.disconnect;
    }

    final int fMangleString = mangleString;

    final CharSequence[] items = {
      getString(fMangleString),
      getString(R.string.edit),
      getString(R.string.duplicate_server),
      getString(R.string.delete)
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(server.getTitle());
    builder.setItems(
        items,
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
            switch (item) {
              case 0: // Connect/Disconnect
                if (fMangleString == R.string.connect) {
                  ConnectServer(server);
                } else if (fMangleString == R.string.disconnect) {
                  DisconnectServer(server);
                }
                break;
              case 1: // Edit
                editServer(server.getId());
                break;
              case 2:
                duplicateServer(server.getId());
                break;
              case 3: // Delete
                binder.getService().getConnection(server.getId()).quitServer();
                deleteServer(server.getId());
                break;
            }
          }
        });
    AlertDialog alert = builder.create();
    alert.show();
    return true;
  }
Ejemplo n.º 3
0
  /** On server selected */
  @Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Server server = adapter.getItem(position);

    if (server == null) {
      // "Add server" was selected
      startActivityForResult(new Intent(this, AddServerActivity.class), 0);
      return;
    }

    Intent intent = new Intent(this, ConversationActivity.class);

    if (server.getStatus() == Status.DISCONNECTED && !server.mayReconnect()) {
      server.setStatus(Status.PRE_CONNECTING);
      intent.putExtra("connect", true);
    }

    intent.putExtra("serverId", server.getId());
    startActivity(intent);
  }