コード例 #1
0
ファイル: aRDP.java プロジェクト: JesseGu/bVNC
  protected void saveAndWriteRecent() {
    // We need server address or SSH server to be filled out to save. Otherwise,
    // we keep adding empty connections.
    if (selected.getConnectionType() == Constants.CONN_TYPE_SSH
            && selected.getSshServer().equals("")
        || selected.getAddress().equals("")) return;

    SQLiteDatabase db = database.getWritableDatabase();
    db.beginTransaction();
    try {
      selected.save(db);
      MostRecentBean mostRecent = getMostRecent(db);
      if (mostRecent == null) {
        mostRecent = new MostRecentBean();
        mostRecent.setConnectionId(selected.get_Id());
        mostRecent.Gen_insert(db);
      } else {
        mostRecent.setConnectionId(selected.get_Id());
        mostRecent.Gen_update(db);
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
      db.close();
    }
  }
コード例 #2
0
ファイル: aRDP.java プロジェクト: JesseGu/bVNC
 public void arriveOnPage() {
   ArrayList<ConnectionBean> connections = new ArrayList<ConnectionBean>();
   ConnectionBean.getAll(
       database.getReadableDatabase(),
       ConnectionBean.GEN_TABLE_NAME,
       connections,
       ConnectionBean.newInstance);
   Collections.sort(connections);
   connections.add(0, new ConnectionBean(this));
   int connectionIndex = 0;
   if (connections.size() > 1) {
     MostRecentBean mostRecent = getMostRecent(database.getReadableDatabase());
     if (mostRecent != null) {
       for (int i = 1; i < connections.size(); ++i) {
         if (connections.get(i).get_Id() == mostRecent.getConnectionId()) {
           connectionIndex = i;
           break;
         }
       }
     }
   }
   spinnerConnection.setAdapter(
       new ArrayAdapter<ConnectionBean>(
           this,
           R.layout.connection_list_entry,
           connections.toArray(new ConnectionBean[connections.size()])));
   spinnerConnection.setSelection(connectionIndex, false);
   selected = connections.get(connectionIndex);
   updateViewFromSelected();
   IntroTextDialog.showIntroTextIfNecessary(this, database, isFree && startingOrHasPaused);
   startingOrHasPaused = false;
 }
コード例 #3
0
  public void saveAndWriteRecent(boolean saveEmpty) {
    Database database = new Database(c);

    // We need server address or SSH server to be filled out to save. Otherwise,
    // we keep adding empty connections.
    // However, if there is partial data from a URI, we can present the edit screen.
    // Alternately, perhaps we could process some extra data
    if ((getConnectionType() == Constants.CONN_TYPE_SSH && getSshServer().equals("")
            || getAddress().equals(""))
        && !saveEmpty) {
      return;
    }

    SQLiteDatabase db = database.getWritableDatabase();
    db.beginTransaction();
    try {
      save(db);
      MostRecentBean mostRecent = getMostRecent(db);
      if (mostRecent == null) {
        mostRecent = new MostRecentBean();
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_insert(db);
      } else {
        mostRecent.setConnectionId(get_Id());
        mostRecent.Gen_update(db);
      }
      db.setTransactionSuccessful();
    } finally {
      db.endTransaction();
      db.close();
    }
    if (db.isOpen()) {
      db.close();
    }
  }
コード例 #4
0
ファイル: aRDP.java プロジェクト: JesseGu/bVNC
 /**
  * Return the object representing the app global state in the database, or null if the object
  * hasn't been set up yet
  *
  * @param db App's database -- only needs to be readable
  * @return Object representing the single persistent instance of MostRecentBean, which is the
  *     app's global state
  */
 public static MostRecentBean getMostRecent(SQLiteDatabase db) {
   ArrayList<MostRecentBean> recents = new ArrayList<MostRecentBean>(1);
   MostRecentBean.getAll(db, MostRecentBean.GEN_TABLE_NAME, recents, MostRecentBean.GEN_NEW);
   if (recents.size() == 0) return null;
   return recents.get(0);
 }
コード例 #5
0
  static ConnectionBean createLoadFromUri(Uri dataUri, Context ctx) {
    ConnectionBean connection = new ConnectionBean(ctx);
    if (dataUri == null) return connection;
    Database database = new Database(ctx);
    String host = dataUri.getHost();

    // Intent generated by connection shortcut widget
    if (host != null && host.startsWith(Constants.CONNECTION)) {
      int port = 0;
      int idx = host.indexOf(':');

      if (idx != -1) {
        try {
          port = Integer.parseInt(host.substring(idx + 1));
        } catch (NumberFormatException nfe) {
        }
        host = host.substring(0, idx);
      }

      if (connection.Gen_read(database.getReadableDatabase(), port)) {
        MostRecentBean bean = getMostRecent(database.getReadableDatabase());
        if (bean != null) {
          bean.setConnectionId(connection.get_Id());
          bean.Gen_update(database.getWritableDatabase());
          database.close();
        }
      }
      return connection;
    }

    // search based on nickname
    SQLiteDatabase queryDb = database.getReadableDatabase();
    String connectionName = dataUri.getQueryParameter(Constants.PARAM_CONN_NAME);
    Cursor nickCursor = null;
    if (connectionName != null)
      nickCursor =
          queryDb.query(
              GEN_TABLE_NAME,
              new String[] {GEN_FIELD__ID},
              GEN_FIELD_NICKNAME + " = ?",
              new String[] {connectionName},
              null,
              null,
              null);
    if (nickCursor != null && nickCursor.moveToFirst()) {
      // there could be many values, so we will just pick one
      Log.i(
          TAG,
          String.format(Locale.US, "Loding connection info from nickname: %s", connectionName));
      connection.Gen_populate(nickCursor, connection.Gen_columnIndices(nickCursor));
      nickCursor.close();
      database.close();
      return connection;
    }
    if (nickCursor != null) nickCursor.close();

    // search based on hostname
    Cursor hostCursor = null;
    if (host != null)
      hostCursor =
          queryDb.query(
              GEN_TABLE_NAME,
              new String[] {GEN_FIELD__ID},
              GEN_FIELD_ADDRESS + " = ?",
              new String[] {host},
              null,
              null,
              null);
    if (hostCursor != null && hostCursor.moveToFirst()) {
      Log.i(TAG, String.format(Locale.US, "Loding connection info from hostname: %s", host));
      connection.Gen_populate(hostCursor, connection.Gen_columnIndices(hostCursor));
      hostCursor.close();
      database.close();
      return connection;
    }
    if (hostCursor != null) hostCursor.close();
    database.close();
    return connection;
  }