示例#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);
      }
    }
  }
示例#2
0
 /** On activity result */
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   if (resultCode == RESULT_OK) {
     // Refresh list from database
     adapter.loadServers();
   }
 }
示例#3
0
 private void ConnectServer(Server s) {
   if (s.getStatus() == Status.DISCONNECTED) {
     binder.connect(s);
     s.setStatus(Status.CONNECTING);
     adapter.notifyDataSetChanged();
   }
 }
示例#4
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;
  }
示例#5
0
 /**
  * Delete server
  *
  * @param serverId
  */
 public void deleteServer(int serverId) {
   Database db = new Database(this);
   db.removeServerById(serverId);
   db.close();
   // make sure we don't accidentally reconnect it
   binder.getService().removeReconnection(serverId);
   Atomic.getInstance().removeServerById(serverId);
   adapter.loadServers();
 }
示例#6
0
  /** On resume */
  @Override
  public void onResume() {
    super.onResume();

    // Start and connect to service
    Intent intent = new Intent(this, IRCService.class);
    intent.setAction(IRCService.ACTION_BACKGROUND);
    startService(intent);
    int flags = 0;
    if (android.os.Build.VERSION.SDK_INT >= 14) {
      flags |= Context.BIND_ABOVE_CLIENT;
    }
    bindService(intent, this, flags);

    receiver = new ServerReceiver(this);
    registerReceiver(receiver, new IntentFilter(Broadcast.SERVER_UPDATE));

    adapter.loadServers();
  }
示例#7
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);
  }
示例#8
0
 /** On server status update */
 @Override
 public void onStatusUpdate() {
   adapter.loadServers();
 }