Пример #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
 /**
  * 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();
 }
Пример #3
0
 @Override
 public void onBackPressed() {
   if (lastBackPress + 2000 > System.currentTimeMillis()) {
     ArrayList<Server> mServers = Atomic.getInstance().getServersAsArrayList();
     for (Server server : mServers) {
       if (binder.getService().hasConnection(server.getId())) {
         DisconnectServer(server);
       }
     }
     binder.getService().stopForegroundCompat(R.string.app_name);
     System.exit(0);
   } else {
     Toast.makeText(this, R.string.back_twice_exit, Toast.LENGTH_LONG).show();
     lastBackPress = System.currentTimeMillis();
   }
 }
Пример #4
0
  /**
   * Start activity to edit server with given id
   *
   * @param serverId The id of the server
   */
  private void editServer(int serverId) {
    Server server = Atomic.getInstance().getServerById(serverId);

    if (server.getStatus() != Status.DISCONNECTED) {
      Toast.makeText(
              this,
              getResources().getString(R.string.disconnect_before_editing),
              Toast.LENGTH_SHORT)
          .show();
    } else {
      Intent intent = new Intent(this, AddServerActivity.class);
      intent.setAction(AddServerActivity.ACTION_EDIT_SERVER);
      intent.putExtra(Extra.SERVER, serverId);
      startActivityForResult(intent, 0);
    }
  }
Пример #5
0
  /** On menu item selected */
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
      case R.id.add:
        startActivityForResult(new Intent(this, AddServerActivity.class), 0);
        break;
      case R.id.about:
        startActivity(new Intent(this, AboutActivity.class));
        break;
      case R.id.settings:
        startActivity(new Intent(this, SettingsActivity.class));
        break;
      case R.id.disconnect_all:
        ArrayList<Server> mServers = Atomic.getInstance().getServersAsArrayList();
        binder.getService().clearReconnectList();
        for (Server server : mServers) {
          DisconnectServer(server);
        }
        // ugly
        // binder.getService().stopForegroundCompat(R.string.app_name);
    }

    return true;
  }