// Writes the server credentials to file for later use. private void commitServerCredentials() throws IOException { try { ServerCredentials serverCredentials = new ServerCredentials( ipAddressField.getText().toString(), usernameField.getText().toString(), passwordField.getText().toString(), syncActivated, lastSyncSuccessDate); serverCredentials.write(); } catch (IllegalArgumentException e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); } }
@Override public void onResume() { super.onResume(); SyncUtil.setSyncSettingsActivity(this); try { ServerCredentials serverCredentials = ServerCredentials.read(); if (serverCredentials.getIPAddress().equals("")) { ipAddressField.setText("192.168.0.1"); } else { ipAddressField.setText(serverCredentials.getIPAddress()); } usernameField.setText(serverCredentials.getUsername()); passwordField.setText(serverCredentials.getPassword()); automaticSyncCheckBox.setChecked(serverCredentials.getSyncActivated()); syncActivated = serverCredentials.getSyncActivated(); lastSyncSuccessDate = serverCredentials.getLastSyncDate(); } catch (IOException e) { // If reading fails, then no text is put into the fields, except for // the default IP. ipAddressField.setText("192.168.0.1"); } }