1 package eu
.alefzero
.owncloud
.ui
.activity
;
3 import android
.accounts
.AccountAuthenticatorActivity
;
4 import android
.app
.Activity
;
5 import android
.os
.Bundle
;
6 import android
.view
.View
;
7 import android
.view
.View
.OnClickListener
;
9 public class PreferencesNewSession
extends AccountAuthenticatorActivity
implements OnClickListener
{
11 public void onCreate(Bundle savedInstanceState
){
12 super.onCreate(savedInstanceState
);
13 //setContentView(R.layout.add_new_session);
15 EditText et;// = (EditText) findViewById(R.id.newSession_sessionName);
17 et = (EditText) findViewById(R.id.newSession_URL);
18 if (getIntent().hasExtra("sessionURL")) {
20 URI uri = new URI(getIntent().getStringExtra("sessionURL"));
21 String url = uri.getHost();
22 if (uri.getPort() != -1) {
23 url += ":" + String.valueOf(uri.getPort());
25 if (uri.getPath() != null) {
31 et = (EditText) findViewById(R.id.newSession_username);
32 if (uri.getAuthority() != null) {
33 if (uri.getUserInfo().indexOf(':') != -1) {
34 et.setText(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(':')));
35 et = (EditText) findViewById(R.id.newSession_password);
36 et.setText(uri.getUserInfo().substring(uri.getUserInfo().indexOf(':')+1));
38 et.setText(uri.getUserInfo());
42 } catch (URISyntaxException e) {
43 Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
47 mReturnData = new Intent();
48 setResult(Activity.RESULT_OK, mReturnData);
49 ((Button) findViewById(R.id.button1)).setOnClickListener(this);
50 ((Button) findViewById(R.id.button2)).setOnClickListener(this);*/
54 protected void onResume() {
58 public void onClick(View v
) {
59 /* switch (v.getId()) {
61 Intent intent = new Intent();
62 if (getIntent().hasExtra("sessionId")) {
63 intent.putExtra("sessionId", getIntent().getIntExtra("sessionId", -1));
65 //String sessionName = ((EditText) findViewById(R.id.newSession_sessionName)).getText().toString();
66 // if (sessionName.trim().equals("") || !isNameValid(sessionName)) {
67 // Toast.makeText(this, R.string.new_session_session_name_error, Toast.LENGTH_LONG).show();
70 URI uri = prepareURI();
72 //intent.putExtra("sessionName", sessionName);
73 intent.putExtra("sessionURL", uri.toString());
74 setResult(Activity.RESULT_OK, intent);
75 AccountManager accMgr = AccountManager.get(this);
76 Account a = new Account("OwnCloud", AccountAuthenticatorService.ACCOUNT_TYPE);
77 accMgr.addAccountExplicitly(a, "asd", null);
82 setResult(Activity.RESULT_CANCELED);
88 /*private URI prepareURI() {
92 String username = ((EditText) findViewById(R.id.newSession_username)).getText().toString().trim();
93 String password = ((EditText) findViewById(R.id.newSession_password)).getText().toString().trim();
94 String hostname = ((EditText) findViewById(R.id.newSession_URL)).getText().toString().trim();
96 if (hostname.matches("[A-Za-z]://")) {
97 scheme = hostname.substring(0, hostname.indexOf("://")+3);
98 hostname = hostname.substring(hostname.indexOf("://")+3);
102 if (!username.equals("")) {
103 if (!password.equals("")) {
104 username += ":" + password + "@";
109 url = scheme + username + hostname;
112 } catch (URISyntaxException e) {
113 Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
114 Toast.makeText(this, R.string.new_session_uri_error, Toast.LENGTH_LONG).show();
119 private boolean isNameValid(String string) {
120 return string.matches("[A-Za-z0-9 _-]*");
124 public void onBackPressed() {
125 setResult(Activity
.RESULT_CANCELED
);
126 super.onBackPressed();