1 package eu
.alefzero
.owncloud
.ui
.activity
;
4 import java
.net
.URISyntaxException
;
6 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticatorService
;
8 import android
.accounts
.Account
;
9 import android
.accounts
.AccountAuthenticatorActivity
;
10 import android
.accounts
.AccountManager
;
11 import android
.app
.Activity
;
12 import android
.content
.Intent
;
13 import android
.os
.Bundle
;
14 import android
.util
.Log
;
15 import android
.view
.View
;
16 import android
.view
.View
.OnClickListener
;
17 import android
.widget
.Button
;
18 import android
.widget
.EditText
;
19 import android
.widget
.Toast
;
21 public class PreferencesNewSession
extends AccountAuthenticatorActivity
implements OnClickListener
{
22 private Intent mReturnData
;
23 private final String TAG
= "OwnCloudPreferencesNewSession";
25 public void onCreate(Bundle savedInstanceState
){
26 super.onCreate(savedInstanceState
);
27 //setContentView(R.layout.add_new_session);
29 EditText et;// = (EditText) findViewById(R.id.newSession_sessionName);
31 et = (EditText) findViewById(R.id.newSession_URL);
32 if (getIntent().hasExtra("sessionURL")) {
34 URI uri = new URI(getIntent().getStringExtra("sessionURL"));
35 String url = uri.getHost();
36 if (uri.getPort() != -1) {
37 url += ":" + String.valueOf(uri.getPort());
39 if (uri.getPath() != null) {
45 et = (EditText) findViewById(R.id.newSession_username);
46 if (uri.getAuthority() != null) {
47 if (uri.getUserInfo().indexOf(':') != -1) {
48 et.setText(uri.getUserInfo().substring(0, uri.getUserInfo().indexOf(':')));
49 et = (EditText) findViewById(R.id.newSession_password);
50 et.setText(uri.getUserInfo().substring(uri.getUserInfo().indexOf(':')+1));
52 et.setText(uri.getUserInfo());
56 } catch (URISyntaxException e) {
57 Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
61 mReturnData = new Intent();
62 setResult(Activity.RESULT_OK, mReturnData);
63 ((Button) findViewById(R.id.button1)).setOnClickListener(this);
64 ((Button) findViewById(R.id.button2)).setOnClickListener(this);*/
68 protected void onResume() {
72 public void onClick(View v
) {
73 /* switch (v.getId()) {
75 Intent intent = new Intent();
76 if (getIntent().hasExtra("sessionId")) {
77 intent.putExtra("sessionId", getIntent().getIntExtra("sessionId", -1));
79 //String sessionName = ((EditText) findViewById(R.id.newSession_sessionName)).getText().toString();
80 // if (sessionName.trim().equals("") || !isNameValid(sessionName)) {
81 // Toast.makeText(this, R.string.new_session_session_name_error, Toast.LENGTH_LONG).show();
84 URI uri = prepareURI();
86 //intent.putExtra("sessionName", sessionName);
87 intent.putExtra("sessionURL", uri.toString());
88 setResult(Activity.RESULT_OK, intent);
89 AccountManager accMgr = AccountManager.get(this);
90 Account a = new Account("OwnCloud", AccountAuthenticatorService.ACCOUNT_TYPE);
91 accMgr.addAccountExplicitly(a, "asd", null);
96 setResult(Activity.RESULT_CANCELED);
102 private URI
prepareURI() {
106 String username = ((EditText) findViewById(R.id.newSession_username)).getText().toString().trim();
107 String password = ((EditText) findViewById(R.id.newSession_password)).getText().toString().trim();
108 String hostname = ((EditText) findViewById(R.id.newSession_URL)).getText().toString().trim();
110 if (hostname.matches("[A-Za-z]://")) {
111 scheme = hostname.substring(0, hostname.indexOf("://")+3);
112 hostname = hostname.substring(hostname.indexOf("://")+3);
116 if (!username.equals("")) {
117 if (!password.equals("")) {
118 username += ":" + password + "@";
123 url = scheme + username + hostname;
126 } catch (URISyntaxException e) {
127 Log.e(TAG, "Incorrect URI syntax " + e.getLocalizedMessage());
128 Toast.makeText(this, R.string.new_session_uri_error, Toast.LENGTH_LONG).show();
133 private boolean isNameValid(String string
) {
134 return string
.matches("[A-Za-z0-9 _-]*");
138 public void onBackPressed() {
139 setResult(Activity
.RESULT_CANCELED
);
140 super.onBackPressed();