Пример #1
0
  private void saveFTPSettings(View v) {
    Configuration conf = userAccount.getConfiguration();
    AttributeList<FileTransferConnection> conList = conf.getFileTransferConncetions();
    FileTransferConnection con = conList.get(0);

    con.setHost(new SingleAttribute<String>("host", host.getText().toString()));
    con.setPort(new SingleAttribute<String>("port", port.getText().toString()));
    con.setUsername(new SingleAttribute<String>("username", username.getText().toString()));
    con.setPassword(new SingleAttribute<String>("password", password.getText().toString()));
    con.setHttpUrl(new SingleAttribute<String>("httpurl", httpUrl.getText().toString()));

    if (ftp.isChecked()) {
      FileTransferProtocol ftp = FileTransferProtocol.FTP;
      con.setProtocol(ftp);
    }
    if (sftp.isChecked()) {
      FileTransferProtocol sftp = FileTransferProtocol.SFTP;
      con.setProtocol(sftp);
    }
    ArrayList<FileTransferConnection> attributes = new ArrayList<FileTransferConnection>();
    attributes.add(con);
    conList.setAttributes(attributes);
    conf.setFileTransferConnections(conList);
    userAccount.setConfiguration(conf);

    try {
      AccountManager am = new AccountManager();
      am.encryptAndSaveAccount(
          userAccount, HelloWorldBasic.getUsername(), HelloWorldBasic.getPassword(), null);
      SettingsChooser.setSuccessMessage("FTP");
      goBackToSettingsChooser();
    } catch (Exception e) {
      Toast.makeText(this, "Sorry, settings couldn't be saved", Toast.LENGTH_LONG).show();
    }
  }
Пример #2
0
  private void initftp() {

    sftp.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Log.i(I, "clicked on SFTP");
            port.setText(FileTransferProtocol.SFTP.standardPort() + "");
          }
        });

    ftp.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            Log.i(I, "clicked on FTP");
            port.setText(FileTransferProtocol.FTP.standardPort() + "");
          }
        });

    FileTransferConnection conn =
        userAccount.getConfiguration().getFileTransferConncetions().get(0);

    String value = "";

    value = conn.getHost().getValue();
    if (value != "") {
      host.setText(value);
      value = "";
    }
    value = conn.getPassword().getValue();
    if (value != "") {
      password.setText(value);
      value = "";
    }
    value = conn.getUsername().getValue();
    if (value != "") {
      username.setText(value);
      value = "";
    }
    value = conn.getPort().getValue();
    if (value != "") {
      port.setText(value);
    }
    value = conn.getProtocol().lowerCaseName();
    if (value != "") {
      String name = conn.getProtocol().lowerCaseName();
      if (name == "ftp") {
        ftp.setChecked(true);
        name = "";
      }
      name = conn.getProtocol().lowerCaseName();
      if (name == "sftp") {
        sftp.setChecked(true);
      }
    }
    // try to get HttpUrl-Field (only in android-accounts available)
    try {
      value = conn.getHttpUrl().getValue();
      if (value != "") {
        httpUrl.setText(value);
      } else if (conn.getHost().getValue() != "") {
        httpUrl.setText(NamingHelper.generateHttpUrlFromFtpSettings());
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }