new stuff for account authenticator
authorBartek Przybylski <bart.p.pl@gmail.com>
Thu, 3 May 2012 13:37:30 +0000 (15:37 +0200)
committerBartek Przybylski <bart.p.pl@gmail.com>
Thu, 3 May 2012 13:37:30 +0000 (15:37 +0200)
13 files changed:
res/layout/account_setup.xml
res/values/strings.xml
src/eu/alefzero/owncloud/AccountUtils.java [new file with mode: 0644]
src/eu/alefzero/owncloud/authenticator/AuthUtils.java [deleted file]
src/eu/alefzero/owncloud/authenticator/AuthenticationRunnable.java [new file with mode: 0644]
src/eu/alefzero/owncloud/authenticator/OnAuthenticationResultListener.java [new file with mode: 0644]
src/eu/alefzero/owncloud/syncadapter/ContactSyncAdapter.java
src/eu/alefzero/owncloud/ui/activity/AuthenticatorActivity.java
src/eu/alefzero/owncloud/ui/activity/FileDisplayActivity.java
src/eu/alefzero/owncloud/ui/activity/Preferences.java
src/eu/alefzero/owncloud/ui/adapter/LandingScreenAdapter.java
src/eu/alefzero/owncloud/ui/fragment/FileListFragment.java
src/eu/alefzero/webdav/WebdavClient.java

index 145576b..90c02f8 100644 (file)
                 android:textColor="@android:color/black"\r
                 android:text="@string/setup_btn_connect" >\r
             </Button>\r
                 android:textColor="@android:color/black"\r
                 android:text="@string/setup_btn_connect" >\r
             </Button>\r
-\r
+<!-- \r
             <Button\r
                 android:id="@+id/buttonNotUser"\r
                 android:layout_width="fill_parent"\r
             <Button\r
                 android:id="@+id/buttonNotUser"\r
                 android:layout_width="fill_parent"\r
                 android:textColor="@android:color/black"\r
                 android:text="Get started!" >\r
             </Button>\r
                 android:textColor="@android:color/black"\r
                 android:text="Get started!" >\r
             </Button>\r
-            \r
+-->       \r
         </LinearLayout>\r
     </LinearLayout>\r
 \r
         </LinearLayout>\r
     </LinearLayout>\r
 \r
index 31e8b03..8233e3b 100644 (file)
@@ -73,4 +73,6 @@
        <item>30</item>
        <item>60</item>
        </string-array>
        <item>30</item>
        <item>60</item>
        </string-array>
+    <string name="auth_trying_to_login">Trying to login</string>
+    <string name="auth_no_ssl">No SSL</string>
 </resources>
 </resources>
diff --git a/src/eu/alefzero/owncloud/AccountUtils.java b/src/eu/alefzero/owncloud/AccountUtils.java
new file mode 100644 (file)
index 0000000..4077775
--- /dev/null
@@ -0,0 +1,61 @@
+/* ownCloud Android client application\r
+ *   Copyright (C) 2011  Bartek Przybylski\r
+ *\r
+ *   This program is free software: you can redistribute it and/or modify\r
+ *   it under the terms of the GNU General Public License as published by\r
+ *   the Free Software Foundation, either version 3 of the License, or\r
+ *   (at your option) any later version.\r
+ *\r
+ *   This program is distributed in the hope that it will be useful,\r
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ *   GNU General Public License for more details.\r
+ *\r
+ *   You should have received a copy of the GNU General Public License\r
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
+ *\r
+ */\r
+\r
+package eu.alefzero.owncloud;\r
+\r
+import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
+\r
+import android.accounts.Account;\r
+import android.accounts.AccountManager;\r
+import android.content.Context;\r
+import android.content.SharedPreferences;\r
+import android.preference.PreferenceManager;\r
+\r
+public class AccountUtils {\r
+  public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";\r
+  public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";\r
+  public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
+  \r
+  /**\r
+   * Can be used to get the currently selected ownCloud account in the preferences\r
+   * \r
+   * @param context The current appContext\r
+   * @return The current account or null, if there is none yet.\r
+   */\r
+  public static Account getCurrentOwnCloudAccount(Context context){\r
+         Account[] ocAccounts = AccountManager.get(context).getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
+         Account defaultAccount = null;\r
+         \r
+         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);\r
+         String accountName = appPreferences.getString("select_oc_account", null);\r
+         \r
+         if(accountName != null){\r
+                 for(Account account : ocAccounts){\r
+                         if(account.name.equals(accountName)){\r
+                                 defaultAccount = account;\r
+                                 break;\r
+                         }\r
+                 }\r
+         } else if (ocAccounts.length != 0) {\r
+           // we at least need to take first account as fallback\r
+           defaultAccount = ocAccounts[0];\r
+         }\r
+         \r
+       return defaultAccount;\r
+  }\r
+}\r
diff --git a/src/eu/alefzero/owncloud/authenticator/AuthUtils.java b/src/eu/alefzero/owncloud/authenticator/AuthUtils.java
deleted file mode 100644 (file)
index 8287e12..0000000
+++ /dev/null
@@ -1,254 +0,0 @@
-/* ownCloud Android client application\r
- *   Copyright (C) 2011  Bartek Przybylski\r
- *\r
- *   This program is free software: you can redistribute it and/or modify\r
- *   it under the terms of the GNU General Public License as published by\r
- *   the Free Software Foundation, either version 3 of the License, or\r
- *   (at your option) any later version.\r
- *\r
- *   This program is distributed in the hope that it will be useful,\r
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- *   GNU General Public License for more details.\r
- *\r
- *   You should have received a copy of the GNU General Public License\r
- *   along with this program.  If not, see <http://www.gnu.org/licenses/>.\r
- *\r
- */\r
-\r
-package eu.alefzero.owncloud.authenticator;\r
-\r
-import java.io.IOException;\r
-import java.net.MalformedURLException;\r
-import java.net.URL;\r
-import java.net.UnknownHostException;\r
-import org.apache.http.conn.ClientConnectionManager;\r
-import org.apache.http.conn.scheme.Scheme;\r
-import org.apache.http.conn.scheme.SchemeRegistry;\r
-\r
-import org.apache.http.impl.client.DefaultHttpClient;\r
-\r
-import org.apache.commons.httpclient.auth.BasicScheme;\r
-import org.apache.http.HttpHost;\r
-import org.apache.http.HttpResponse;\r
-import org.apache.http.HttpVersion;\r
-import org.apache.http.auth.AuthScope;\r
-import org.apache.http.auth.UsernamePasswordCredentials;\r
-import org.apache.http.client.ClientProtocolException;\r
-import org.apache.http.client.methods.HttpHead;\r
-import org.apache.http.conn.params.ConnManagerPNames;\r
-import org.apache.http.conn.params.ConnPerRouteBean;\r
-import org.apache.http.conn.scheme.PlainSocketFactory;\r
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;\r
-import org.apache.http.params.BasicHttpParams;\r
-import org.apache.http.params.HttpParams;\r
-import org.apache.http.params.HttpProtocolParams;\r
-import org.apache.http.protocol.BasicHttpContext;\r
-\r
-import eu.alefzero.owncloud.ui.activity.AuthenticatorActivity;\r
-\r
-\r
-import android.accounts.Account;\r
-import android.accounts.AccountManager;\r
-import android.content.Context;\r
-import android.content.SharedPreferences;\r
-import android.os.Handler;\r
-import android.preference.PreferenceManager;\r
-import android.util.Log;\r
-\r
-public class AuthUtils {\r
-  public static final String WEBDAV_PATH_1_2 = "/webdav/owncloud.php";\r
-  public static final String WEBDAV_PATH_2_0 = "/files/webdav.php";\r
-  public static final String CARDDAV_PATH_2_0 = "/apps/contacts/carddav.php";\r
-  \r
-  private static String mResultMsg = "";\r
-  \r
-  public static boolean authenticate(URL url, String username, String password,\r
-                                     Handler handler, Context context) {\r
-    String strippedPath = url.toString().endsWith("/") ?\r
-                          url.toString().substring(0, url.toString().length()-1) :\r
-                          url.toString();\r
-    String webdatPath = strippedPath + WEBDAV_PATH_2_0;\r
-    URL complete_url = null;\r
-    try {\r
-      complete_url = new URL(webdatPath);\r
-    } catch (MalformedURLException e) {\r
-      // should never happend\r
-      sendResult(false, handler, context, "URL error");\r
-      return false;\r
-    }\r
-    \r
-    // version 2.0 success\r
-    if (tryGetWebdav(complete_url, username, password, handler, context)) {\r
-      sendResult(true, handler, context, complete_url.toString());\r
-      return true;\r
-    }\r
-    \r
-    if (mResultMsg.equals("401")) {\r
-       sendResult(false, handler, context, "Invalid login or/and password");\r
-       return false;\r
-    }\r
-    \r
-    if (!mResultMsg.equals("404")) {\r
-      sendResult(false, handler, context, "Server error: " + mResultMsg);\r
-      return false;\r
-    }\r
-    \r
-    webdatPath = strippedPath + WEBDAV_PATH_1_2;\r
-    try {\r
-      complete_url = new URL(webdatPath);\r
-    } catch (MalformedURLException e) {\r
-      // should never happend\r
-      sendResult(false, handler, context, "URL error");\r
-      return false;\r
-    }\r
-    \r
-    // version 1.2 success\r
-    if (tryGetWebdav(complete_url, username, password, handler, context)) {\r
-      sendResult(true, handler, context, complete_url.toString());\r
-      return true;\r
-    }\r
-    \r
-    if (mResultMsg.equals("401")) {\r
-      sendResult(false, handler, context, "Invalid login or/and password");\r
-      return false;\r
-    }\r
-    \r
-    if (mResultMsg.equals("404")) {\r
-      sendResult(false, handler, context, "Wrong path given");\r
-      return false;\r
-    }\r
-    \r
-    sendResult(false, handler, context, "Server error: " + mResultMsg);\r
-    return false;\r
-  }\r
-  \r
-  public static boolean tryGetWebdav(URL url, String username, String pwd,\r
-                                     Handler handler, Context context) {\r
-    SchemeRegistry schemeRegistry = new SchemeRegistry();\r
- // http scheme\r
- schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));\r
- // https scheme\r
- schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));\r
-\r
- HttpParams params = new BasicHttpParams();\r
- params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30);\r
- params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30));\r
- params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false);\r
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);\r
-\r
- ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);\r
-    \r
-    DefaultHttpClient c = new DefaultHttpClient(cm, params);\r
-    \r
-    c.getCredentialsProvider().setCredentials(\r
-        new AuthScope(url.getHost(), (url.getPort() == -1)?80:url.getPort()), \r
-        new UsernamePasswordCredentials(username, pwd));\r
-    \r
-    BasicHttpContext localcontext  = new BasicHttpContext();\r
-    BasicScheme basicAuth = new BasicScheme();\r
-\r
-    localcontext.setAttribute("preemptive-auth", basicAuth);\r
-    HttpHost targetHost = new HttpHost(url.getHost(), (url.getPort() == -1)\r
-        ? 80\r
-        : url.getPort(), (url.getProtocol().equals("https")) ? "https" : "http");\r
-    HttpHead httpget = new HttpHead(url.toString());\r
-    httpget.setHeader("Host", url.getHost());\r
-    HttpResponse response = null;\r
-    try {\r
-      response = c.execute(targetHost, httpget, localcontext);\r
-    } catch (ClientProtocolException e1) {\r
-      sendResult(false, handler, context, "Protocol error: "\r
-          + e1.getLocalizedMessage());\r
-      return false;\r
-    } catch (UnknownHostException e1) {\r
-      mResultMsg = "Unknowh host: " + e1.getLocalizedMessage();\r
-      return false;\r
-    } catch (IOException e1) {\r
-      mResultMsg = "Error: " + e1.getLocalizedMessage();\r
-      return false;\r
-    }\r
-    String status = response.getStatusLine().toString();\r
-\r
-    status = status.split(" ")[1];\r
-    Log.i("AuthUtils", "Status returned: " + status);\r
-    if (status.equals("200")) {\r
-      return true;\r
-    } else if (status.equals("404")) {\r
-      mResultMsg = "404";\r
-      return false;\r
-    } else if (status.equals("401")) {\r
-      mResultMsg = "401";\r
-      return false;\r
-    }\r
-    mResultMsg = status;\r
-    return false;\r
-  }\r
-  \r
-  public static Thread performOnBackgroundThread(final Runnable r) {\r
-    final Thread t = new Thread() {\r
-      @Override\r
-      public void run() {\r
-        try {\r
-          r.run();\r
-        } finally {}\r
-      }\r
-    };\r
-    t.start();\r
-    return t;\r
-  }\r
-  \r
-  public static void sendResult(final Boolean result,\r
-                                final Handler handler,\r
-                                final Context context,\r
-                                final String message) {\r
-    if (handler == null || context == null) {\r
-      return;\r
-    }\r
-    handler.post(new Runnable() {\r
-      public void run() {\r
-        ((AuthenticatorActivity) context).onAuthenticationResult(result, message); \r
-      }\r
-    });\r
-  }\r
-  \r
-  public static Thread attemptAuth(final URL url, final String username,\r
-                                   final String password, final Handler handler,\r
-                                   final Context context) {\r
-    final Runnable r = new Runnable() {\r
-      \r
-      public void run() {\r
-        authenticate(url, username, password, handler, context);\r
-      }\r
-    };\r
-    return performOnBackgroundThread(r);\r
-  }\r
-  \r
-  /**\r
-   * Can be used to get the currently selected ownCloud account in the preferences\r
-   * \r
-   * @param context The current appContext\r
-   * @return The current account or null, if there is none yet.\r
-   */\r
-  public static Account getCurrentOwnCloudAccount(Context context){\r
-         Account[] ocAccounts = AccountManager.get(context).getAccountsByType(AccountAuthenticator.ACCOUNT_TYPE);\r
-         Account defaultAccount = null;\r
-         \r
-         SharedPreferences appPreferences = PreferenceManager.getDefaultSharedPreferences(context);\r
-         String accountName = appPreferences.getString("select_oc_account", null);\r
-         \r
-         if(accountName != null){\r
-                 for(Account account : ocAccounts){\r
-                         if(account.name.equals(accountName)){\r
-                                 defaultAccount = account;\r
-                                 break;\r
-                         }\r
-                 }\r
-         } else if (ocAccounts.length != 0) {\r
-           // we at least need to take first account as fallback\r
-           defaultAccount = ocAccounts[0];\r
-         }\r
-         \r
-       return defaultAccount;\r
-  }\r
-}\r
diff --git a/src/eu/alefzero/owncloud/authenticator/AuthenticationRunnable.java b/src/eu/alefzero/owncloud/authenticator/AuthenticationRunnable.java
new file mode 100644 (file)
index 0000000..445524c
--- /dev/null
@@ -0,0 +1,83 @@
+/* ownCloud Android client application
+ *   Copyright (C) 2012 Bartek Przybylski
+ *
+ *   This program is free software: you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation, either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+package eu.alefzero.owncloud.authenticator;
+
+import java.net.URL;
+
+import org.apache.commons.httpclient.HttpStatus;
+
+import eu.alefzero.webdav.WebdavClient;
+
+import android.net.Uri;
+import android.os.Handler;
+
+public class AuthenticationRunnable implements Runnable {
+
+  private OnAuthenticationResultListener mListener;
+  private Handler mHandler;
+  private URL mUrl;
+  private String mUsername;
+  private String mPassword;
+  
+  private static final String WEBDAV_2_0_PATH = "/files/webdav.php";
+  
+  public AuthenticationRunnable(URL url, String username, String password) {
+    mListener = null;
+    mUrl = url;
+    mUsername = username;
+    mPassword = password;
+  }
+  
+  public void setOnAuthenticationResultListener(OnAuthenticationResultListener listener, Handler handler) {
+    mListener = listener;
+    mHandler = handler;
+  }
+  
+  @Override
+  public void run() {
+    Uri uri = Uri.parse(mUrl.toString() + WEBDAV_2_0_PATH);
+    WebdavClient client = new WebdavClient(uri);
+    client.setCredentials(mUsername, mPassword);
+    int login_result = client.tryToLogin(); 
+    switch (login_result) {
+      case HttpStatus.SC_OK:
+        postResult(true, uri.toString());
+        break;
+      case HttpStatus.SC_UNAUTHORIZED:
+        postResult(false, "Invalid login or/and password");
+        break;
+      case HttpStatus.SC_NOT_FOUND:
+        postResult(false, "Wrong path given");
+        break;
+      default:
+        postResult(false, "Internal server error, code: " + login_result);
+    }
+  }
+
+  private void postResult(final boolean success, final String message) {
+    if (mHandler != null) {
+      mHandler.post(new Runnable() {
+        @Override
+        public void run() {
+          AuthenticationRunnable.this.mListener.onAuthenticationResult(success, message);
+        }
+      });
+    }
+  }
+}
diff --git a/src/eu/alefzero/owncloud/authenticator/OnAuthenticationResultListener.java b/src/eu/alefzero/owncloud/authenticator/OnAuthenticationResultListener.java
new file mode 100644 (file)
index 0000000..470484e
--- /dev/null
@@ -0,0 +1,7 @@
+package eu.alefzero.owncloud.authenticator;
+
+public interface OnAuthenticationResultListener {
+  
+  public void onAuthenticationResult(boolean success, String message);
+
+}
index 8ddc414..56f5c2b 100644 (file)
@@ -7,8 +7,8 @@ import org.apache.http.HttpResponse;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.ByteArrayEntity;
 
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.entity.ByteArrayEntity;
 
+import eu.alefzero.owncloud.AccountUtils;
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;
-import eu.alefzero.owncloud.authenticator.AuthUtils;
 import eu.alefzero.owncloud.db.ProviderMeta;
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 import android.accounts.Account;
 import eu.alefzero.owncloud.db.ProviderMeta;
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;
 import android.accounts.Account;
@@ -73,7 +73,7 @@ public class ContactSyncAdapter extends AbstractOwnCloudSyncAdapter {
 
     AccountManager am = getAccountManager();
     String uri = am.getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL)
 
     AccountManager am = getAccountManager();
     String uri = am.getUserData(getAccount(), AccountAuthenticator.KEY_OC_URL)
-                   .replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0);
+                   .replace(AccountUtils.WEBDAV_PATH_2_0, AccountUtils.CARDDAV_PATH_2_0);
     uri += "/addressbooks/" + getAccount().name.substring(0, getAccount().name.lastIndexOf('@'))
         + "/default/";
     mAddrBookUri = uri;
     uri += "/addressbooks/" + getAccount().name.substring(0, getAccount().name.lastIndexOf('@'))
         + "/default/";
     mAddrBookUri = uri;
index c62290b..3ecd3e7 100644 (file)
@@ -21,8 +21,6 @@ package eu.alefzero.owncloud.ui.activity;
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
 \r
 import java.net.MalformedURLException;\r
 import java.net.URL;\r
 \r
-import com.actionbarsherlock.ActionBarSherlock;\r
-\r
 import android.accounts.Account;\r
 import android.accounts.AccountAuthenticatorActivity;\r
 import android.accounts.AccountManager;\r
 import android.accounts.Account;\r
 import android.accounts.AccountAuthenticatorActivity;\r
 import android.accounts.AccountManager;\r
@@ -40,202 +38,225 @@ import android.text.InputType;
 import android.util.Log;\r
 import android.view.View;\r
 import android.view.Window;\r
 import android.util.Log;\r
 import android.view.View;\r
 import android.view.Window;\r
-import android.widget.CheckBox;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
+import eu.alefzero.owncloud.authenticator.AuthenticationRunnable;\r
+import eu.alefzero.owncloud.authenticator.OnAuthenticationResultListener;\r
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
 \r
 /**\r
  * This Activity is used to add an ownCloud account to the App\r
 import eu.alefzero.owncloud.db.ProviderMeta.ProviderTableMeta;\r
 \r
 /**\r
  * This Activity is used to add an ownCloud account to the App\r
+ * \r
  * @author Bartek Przybylski\r
  * @author Bartek Przybylski\r
- *\r
+ * \r
  */\r
  */\r
-public class AuthenticatorActivity extends AccountAuthenticatorActivity {\r
-    private Thread mAuthThread;\r
-    private final Handler mHandler = new Handler();\r
-    private boolean mUseSSLConnection;\r
+public class AuthenticatorActivity extends AccountAuthenticatorActivity implements OnAuthenticationResultListener {\r
+  private static final int DIALOG_LOGIN_PROGRESS = 0;\r
+  private static final String TAG = "AuthActivity";\r
 \r
 \r
-    public static final String PARAM_USERNAME = "param_Username";\r
-    public static final String PARAM_HOSTNAME = "param_Hostname";\r
+  private Thread mAuthThread;\r
+  private AuthenticationRunnable mAuthRunnable;\r
+  private final Handler mHandler = new Handler();\r
+  private boolean mUseSSLConnection;\r
 \r
 \r
-    public AuthenticatorActivity() {\r
-      mUseSSLConnection = true;\r
-    }\r
-    \r
-    @Override\r
-    protected void onCreate(Bundle savedInstanceState) {\r
-        super.onCreate(savedInstanceState);\r
-        getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
-        setContentView(R.layout.account_setup);\r
-        if (getIntent().hasExtra(PARAM_USERNAME)) {\r
-            String username = getIntent().getStringExtra(PARAM_HOSTNAME);\r
-            TextView host_text, user_text;\r
-            host_text = (TextView) findViewById(R.id.host_URL);\r
-            user_text = (TextView) findViewById(R.id.account_username);\r
-            host_text.setText(host_text.getText() + username.substring(username.lastIndexOf('@')));\r
-            user_text.setText(user_text.getText() + username.substring(0, username.lastIndexOf('@') - 1));\r
-        }\r
+  public static final String PARAM_USERNAME = "param_Username";\r
+  public static final String PARAM_HOSTNAME = "param_Hostname";\r
+\r
+  public AuthenticatorActivity() {\r
+    mUseSSLConnection = true;\r
+  }\r
+\r
+  @Override\r
+  protected void onCreate(Bundle savedInstanceState) {\r
+    super.onCreate(savedInstanceState);\r
+    getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
+    setContentView(R.layout.account_setup);\r
+    if (getIntent().hasExtra(PARAM_USERNAME)) {\r
+      String username = getIntent().getStringExtra(PARAM_HOSTNAME);\r
+      TextView host_text, user_text;\r
+      host_text = (TextView) findViewById(R.id.host_URL);\r
+      user_text = (TextView) findViewById(R.id.account_username);\r
+      host_text.setText(host_text.getText()\r
+          + username.substring(username.lastIndexOf('@')));\r
+      user_text.setText(user_text.getText()\r
+          + username.substring(0, username.lastIndexOf('@') - 1));\r
     }\r
     }\r
+  }\r
 \r
 \r
-    @Override\r
-    protected Dialog onCreateDialog(int id) {\r
-        final ProgressDialog dialog = new ProgressDialog(this);\r
-        dialog.setMessage("Trying to login");\r
-        dialog.setIndeterminate(true);\r
-        dialog.setCancelable(true);\r
-        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {\r
-            public void onCancel(DialogInterface dialog) {\r
-                Log.i(getClass().getName(), "Login canceled");\r
-                if (mAuthThread != null) {\r
-                    mAuthThread.interrupt();\r
-                    finish();\r
-                }\r
+  @Override\r
+  protected Dialog onCreateDialog(int id) {\r
+    Dialog dialog = null;\r
+    switch (id) {\r
+      case DIALOG_LOGIN_PROGRESS : {\r
+        ProgressDialog working_dialog = new ProgressDialog(this);\r
+        dialog = working_dialog;\r
+        working_dialog.setMessage(getResources().getString(R.string.auth_trying_to_login));\r
+        working_dialog.setIndeterminate(true);\r
+        working_dialog.setCancelable(true);\r
+        working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {\r
+          @Override\r
+          public void onCancel(DialogInterface dialog) {\r
+            Log.i(getClass().getName(), "Login canceled");\r
+            if (mAuthThread != null) {\r
+              mAuthThread.interrupt();\r
+              finish();\r
             }\r
             }\r
+          }\r
         });\r
         });\r
-        return dialog;\r
+        break;\r
+      }\r
+      default :\r
+        Log.e(TAG, "Incorrect dialog called with id = " + id);\r
     }\r
     }\r
+    return dialog;\r
+  }\r
 \r
 \r
-    public void onAuthenticationResult(boolean result, String message) {\r
-        if (result) {\r
-            TextView username_text = (TextView) findViewById(R.id.account_username),\r
-                    password_text = (TextView) findViewById(R.id.account_password);\r
-\r
-            URL url;\r
-            try {\r
-                url = new URL(message);\r
-            } catch (MalformedURLException e) {\r
-                // should never happen\r
-                Log.e(getClass().getName(), "Malformed URL: " + message);\r
-                return;\r
-            }\r
+  public void onAuthenticationResult(boolean success, String message) {\r
+    if (success) {\r
+      TextView username_text = (TextView) findViewById(R.id.account_username), password_text = (TextView) findViewById(R.id.account_password);\r
 \r
 \r
-            String username = username_text.getText().toString().trim();\r
-            String accountName = username + "@" + url.getHost();\r
-            Account account = new Account(accountName, AccountAuthenticator.ACCOUNT_TYPE);\r
-            AccountManager accManager = AccountManager.get(this);\r
-            accManager.addAccountExplicitly(account, password_text.getText().toString(), null);\r
-            \r
-            // Add this account as default in the preferences, if there is none already\r
-            Account defaultAccount = AuthUtils.getCurrentOwnCloudAccount(this);\r
-            if(defaultAccount == null){\r
-               SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(this).edit();\r
-               editor.putString("select_oc_account", accountName);\r
-               editor.commit();\r
-            }\r
+      URL url;\r
+      try {\r
+        url = new URL(message);\r
+      } catch (MalformedURLException e) {\r
+        // should never happen\r
+        Log.e(getClass().getName(), "Malformed URL: " + message);\r
+        return;\r
+      }\r
+\r
+      String username = username_text.getText().toString().trim();\r
+      String accountName = username + "@" + url.getHost();\r
+      Account account = new Account(accountName,\r
+          AccountAuthenticator.ACCOUNT_TYPE);\r
+      AccountManager accManager = AccountManager.get(this);\r
+      accManager.addAccountExplicitly(account, password_text.getText()\r
+          .toString(), null);\r
+\r
+      // Add this account as default in the preferences, if there is none\r
+      // already\r
+      Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
+      if (defaultAccount == null) {\r
+        SharedPreferences.Editor editor = PreferenceManager\r
+            .getDefaultSharedPreferences(this).edit();\r
+        editor.putString("select_oc_account", accountName);\r
+        editor.commit();\r
+      }\r
+\r
+      final Intent intent = new Intent();\r
+      intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE,\r
+          AccountAuthenticator.ACCOUNT_TYPE);\r
+      intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);\r
+      intent.putExtra(AccountManager.KEY_AUTHTOKEN,\r
+          AccountAuthenticator.ACCOUNT_TYPE);\r
+      accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL,\r
+          url.toString());\r
+\r
+      // TODO prepare this URL using a central service\r
+      intent.putExtra(AccountManager.KEY_USERDATA, username);\r
+      accManager.setUserData(\r
+          account,\r
+          AccountAuthenticator.KEY_CONTACT_URL,\r
+          url.toString().replace(AccountUtils.WEBDAV_PATH_2_0,\r
+              AccountUtils.CARDDAV_PATH_2_0));\r
+\r
+      setAccountAuthenticatorResult(intent.getExtras());\r
+      setResult(RESULT_OK, intent);\r
+      Bundle bundle = new Bundle();\r
+      bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
+      getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, bundle);\r
 \r
 \r
-            final Intent intent = new Intent();\r
-            intent.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountAuthenticator.ACCOUNT_TYPE);\r
-            intent.putExtra(AccountManager.KEY_ACCOUNT_NAME, account.name);\r
-            intent.putExtra(AccountManager.KEY_AUTHTOKEN, AccountAuthenticator.ACCOUNT_TYPE);\r
-            accManager.setUserData(account, AccountAuthenticator.KEY_OC_URL, url.toString());\r
-\r
-            // TODO prepare this URL using a central service\r
-            intent.putExtra(AccountManager.KEY_USERDATA, username);\r
-            accManager.setUserData(account, AccountAuthenticator.KEY_CONTACT_URL,\r
-                    url.toString().replace(AuthUtils.WEBDAV_PATH_2_0, AuthUtils.CARDDAV_PATH_2_0)\r
-            );\r
-\r
-            setAccountAuthenticatorResult(intent.getExtras());\r
-            setResult(RESULT_OK, intent);\r
-            Bundle bundle = new Bundle();\r
-            bundle.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);\r
-            getContentResolver().startSync(ProviderTableMeta.CONTENT_URI, bundle);\r
-\r
-            dismissDialog(0);\r
-            finish();\r
-        } else {\r
-            Toast.makeText(this, message, Toast.LENGTH_LONG).show();\r
-            dismissDialog(0);\r
-        }\r
+      dismissDialog(0);\r
+      finish();\r
+    } else {\r
+      Toast.makeText(this, message, Toast.LENGTH_LONG).show();\r
+      dismissDialog(0);\r
     }\r
     }\r
+  }\r
 \r
 \r
-    public void onCancelClick(View view) {\r
-        Log.i(getClass().getName(), "Account creating canceled");\r
-        this.finish();\r
+  public void onOkClick(View view) {\r
+    TextView url_text = (TextView) findViewById(R.id.host_URL);\r
+    TextView username_text = (TextView) findViewById(R.id.account_username);\r
+    TextView password_text = (TextView) findViewById(R.id.account_password);\r
+    Log.i(getClass().getName(), "OK clicked");\r
+    boolean hasErrors = false;\r
+\r
+    URL uri = null;\r
+    if (url_text.getText().toString().trim().length() == 0) {\r
+      url_text.setTextColor(Color.RED);\r
+      hasErrors = true;\r
+    } else {\r
+      url_text.setTextColor(android.R.color.black);\r
+    }\r
+    try {\r
+      String url_str = url_text.getText().toString();\r
+      if (!url_str.startsWith("http://") && !url_str.startsWith("https://")) {\r
+        if (mUseSSLConnection)\r
+          url_str = "https://" + url_str;\r
+        else\r
+          url_str = "http://" + url_str;\r
+      }\r
+      uri = new URL(url_str);\r
+    } catch (MalformedURLException e) {\r
+      url_text.setTextColor(Color.RED);\r
+      e.printStackTrace();\r
+      hasErrors = true;\r
     }\r
 \r
     }\r
 \r
-    public void onOkClick(View view) {\r
-        TextView url_text = (TextView) findViewById(R.id.host_URL);\r
-        TextView username_text = (TextView) findViewById(R.id.account_username);\r
-        TextView password_text = (TextView) findViewById(R.id.account_password);\r
-        Log.i(getClass().getName(), "OK clicked");\r
-        boolean hasErrors = false;\r
-\r
-        URL uri = null;\r
-        if (url_text.getText().toString().trim().length() == 0) {\r
-            url_text.setTextColor(Color.RED);\r
-            hasErrors = true;\r
-        } else {\r
-            url_text.setTextColor(android.R.color.black);\r
-        }\r
-        try {\r
-            String url_str = url_text.getText().toString();\r
-            if (!url_str.startsWith("http://") &&\r
-                    !url_str.startsWith("https://")) {\r
-              if (mUseSSLConnection)\r
-                url_str = "https://" + url_str;\r
-              else\r
-                url_str = "http://" + url_str;\r
-            }\r
-            uri = new URL(url_str);\r
-        } catch (MalformedURLException e) {\r
-            url_text.setTextColor(Color.RED);\r
-            e.printStackTrace();\r
-            hasErrors = true;\r
-        }\r
-\r
-        if (username_text.getText().toString().contains(" ") ||\r
-                username_text.getText().toString().trim().length() == 0) {\r
-            username_text.setTextColor(Color.RED);\r
-            hasErrors = true;\r
-        } else {\r
-            username_text.setTextColor(android.R.color.black);\r
-        }\r
-\r
-        if (password_text.getText().toString().trim().length() == 0) {\r
-            password_text.setTextColor(Color.RED);\r
-            hasErrors = true;\r
-        } else {\r
-            password_text.setTextColor(android.R.color.black);\r
-        }\r
-        if (hasErrors) {\r
-            return;\r
-        }\r
-        \r
-        int new_port = uri.getPort();\r
-        if (new_port == -1) {\r
-          if (mUseSSLConnection)\r
-            new_port = 443;\r
-          else\r
-            new_port = 80;\r
-        }\r
-        \r
-        try {\r
-          uri = new URL(uri.getProtocol(), uri.getHost(), new_port, uri.getPath());\r
-        } catch (MalformedURLException e) {\r
-          e.printStackTrace(); // should not happend\r
-        }\r
-        \r
-        showDialog(0);\r
-        mAuthThread = AuthUtils.attemptAuth(uri,\r
-                username_text.getText().toString(),\r
-                password_text.getText().toString(),\r
-                mHandler,\r
-                AuthenticatorActivity.this);\r
+    if (username_text.getText().toString().contains(" ")\r
+        || username_text.getText().toString().trim().length() == 0) {\r
+      username_text.setTextColor(Color.RED);\r
+      hasErrors = true;\r
+    } else {\r
+      username_text.setTextColor(android.R.color.black);\r
     }\r
     }\r
-    \r
-    public void sslBadgeClick(View view, String val) {\r
-      mUseSSLConnection = ((TextView)view).getText().equals("SSL");\r
+\r
+    if (password_text.getText().toString().trim().length() == 0) {\r
+      password_text.setTextColor(Color.RED);\r
+      hasErrors = true;\r
+    } else {\r
+      password_text.setTextColor(android.R.color.black);\r
     }\r
     }\r
-    \r
-    public void passwordBadgeClick(View view, String val) {\r
-      if(val.equals("Hide")) {\r
-        ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);\r
-      } else {\r
-        ((TextView)view).setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);\r
-      }\r
+    if (hasErrors) {\r
+      return;\r
+    }\r
+\r
+    int new_port = uri.getPort();\r
+    if (new_port == -1) {\r
+      if (mUseSSLConnection)\r
+        new_port = 443;\r
+      else\r
+        new_port = 80;\r
+    }\r
+\r
+    try {\r
+      uri = new URL(uri.getProtocol(), uri.getHost(), new_port, uri.getPath());\r
+    } catch (MalformedURLException e) {\r
+      e.printStackTrace(); // should not happend\r
     }\r
     }\r
+\r
+    showDialog(DIALOG_LOGIN_PROGRESS);\r
+    mAuthRunnable = new AuthenticationRunnable(\r
+        uri,\r
+        username_text.getText().toString(),\r
+        password_text.getText().toString());\r
+    mAuthRunnable.setOnAuthenticationResultListener(this, mHandler);\r
+    mAuthThread = new Thread(mAuthRunnable);\r
+    mAuthThread.start();\r
+  }\r
+\r
+  public void sslBadgeClick(View view, String val) {\r
+    mUseSSLConnection = ((TextView) view).getText().equals("SSL");\r
+  }\r
+\r
+  public void passwordBadgeClick(View view, String val) {\r
+    int input_type = InputType.TYPE_CLASS_TEXT;\r
+    input_type |= val.equals("Hide")\r
+                  ? InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD\r
+                  : InputType.TYPE_TEXT_VARIATION_PASSWORD;\r
+\r
+    ((TextView) view).setInputType(input_type);\r
+  }\r
 }\r
 }\r
index 3522ea0..cac6fea 100644 (file)
@@ -42,9 +42,9 @@ import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;\r
 import com.actionbarsherlock.view.MenuItem;\r
 \r
 import com.actionbarsherlock.view.MenuInflater;\r
 import com.actionbarsherlock.view.MenuItem;\r
 \r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
@@ -93,7 +93,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
     {\r
       builder = new Builder(this);\r
       final EditText dirName = new EditText(getBaseContext());\r
     {\r
       builder = new Builder(this);\r
       final EditText dirName = new EditText(getBaseContext());\r
-      final Account a = AuthUtils.getCurrentOwnCloudAccount(this);\r
+      final Account a = AccountUtils.getCurrentOwnCloudAccount(this);\r
       builder.setView(dirName);\r
       builder.setTitle(R.string.uploader_info_dirname);\r
       dirName.setTextColor(R.color.setup_text_typed);\r
       builder.setView(dirName);\r
       builder.setTitle(R.string.uploader_info_dirname);\r
       dirName.setTextColor(R.color.setup_text_typed);\r
@@ -149,7 +149,7 @@ public class FileDisplayActivity extends SherlockFragmentActivity implements
                                R.layout.sherlock_spinner_dropdown_item);\r
                mDirectories.add("/");\r
                setContentView(R.layout.files);\r
                                R.layout.sherlock_spinner_dropdown_item);\r
                mDirectories.add("/");\r
                setContentView(R.layout.files);\r
-               mStorageManager = new FileDataStorageManager(AuthUtils.getCurrentOwnCloudAccount(this), getContentResolver());\r
+               mStorageManager = new FileDataStorageManager(AccountUtils.getCurrentOwnCloudAccount(this), getContentResolver());\r
                ActionBar action_bar = getSupportActionBar();\r
                action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
                action_bar.setDisplayShowTitleEnabled(false);\r
                ActionBar action_bar = getSupportActionBar();\r
                action_bar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);\r
                action_bar.setDisplayShowTitleEnabled(false);\r
index a374b24..953e1a6 100644 (file)
@@ -43,10 +43,10 @@ import com.actionbarsherlock.view.Menu;
 import com.actionbarsherlock.view.MenuInflater;\r
 import com.actionbarsherlock.view.MenuItem;\r
 \r
 import com.actionbarsherlock.view.MenuInflater;\r
 import com.actionbarsherlock.view.MenuItem;\r
 \r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.OwnCloudSession;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
 import eu.alefzero.owncloud.OwnCloudSession;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.authenticator.AccountAuthenticator;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
 import eu.alefzero.owncloud.db.DbHandler;\r
 \r
 /**\r
 import eu.alefzero.owncloud.db.DbHandler;\r
 \r
 /**\r
@@ -127,7 +127,7 @@ public class Preferences extends SherlockPreferenceActivity implements
                mAccountList.setOnPreferenceChangeListener(this);\r
 \r
                // Display the name of the current account if there is any\r
                mAccountList.setOnPreferenceChangeListener(this);\r
 \r
                // Display the name of the current account if there is any\r
-               Account defaultAccount = AuthUtils.getCurrentOwnCloudAccount(this);\r
+               Account defaultAccount = AccountUtils.getCurrentOwnCloudAccount(this);\r
                if (defaultAccount != null) {\r
                        mAccountList.setSummary(defaultAccount.name);\r
                }\r
                if (defaultAccount != null) {\r
                        mAccountList.setSummary(defaultAccount.name);\r
                }\r
index 3483983..def7a48 100644 (file)
@@ -25,8 +25,8 @@ import android.view.ViewGroup;
 import android.widget.BaseAdapter;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
 import android.widget.BaseAdapter;\r
 import android.widget.ImageView;\r
 import android.widget.TextView;\r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.ui.activity.Preferences;\r
 \r
 import eu.alefzero.owncloud.ui.activity.FileDisplayActivity;\r
 import eu.alefzero.owncloud.ui.activity.Preferences;\r
 \r
@@ -74,7 +74,7 @@ public class LandingScreenAdapter extends BaseAdapter {
                         * We will put in the one that is selected in the preferences\r
                         */\r
                        intent.setClass(mContext, FileDisplayActivity.class);   \r
                         * We will put in the one that is selected in the preferences\r
                         */\r
                        intent.setClass(mContext, FileDisplayActivity.class);   \r
-                       intent.putExtra("ACCOUNT", AuthUtils.getCurrentOwnCloudAccount(mContext));\r
+                       intent.putExtra("ACCOUNT", AccountUtils.getCurrentOwnCloudAccount(mContext));\r
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\r
                        break;\r
                case 5:\r
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\r
                        break;\r
                case 5:\r
index 1fb0c57..7541329 100644 (file)
@@ -27,8 +27,8 @@ import android.util.Log;
 import android.view.View;\r
 import android.widget.AdapterView;\r
 import android.widget.Toast;\r
 import android.view.View;\r
 import android.widget.AdapterView;\r
 import android.widget.Toast;\r
+import eu.alefzero.owncloud.AccountUtils;\r
 import eu.alefzero.owncloud.R;\r
 import eu.alefzero.owncloud.R;\r
-import eu.alefzero.owncloud.authenticator.AuthUtils;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
 import eu.alefzero.owncloud.datamodel.DataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.FileDataStorageManager;\r
 import eu.alefzero.owncloud.datamodel.OCFile;\r
@@ -56,7 +56,7 @@ public class FileListFragment extends FragmentListView {
   public void onCreate(Bundle savedInstanceState) {\r
     super.onCreate(savedInstanceState);\r
 \r
   public void onCreate(Bundle savedInstanceState) {\r
     super.onCreate(savedInstanceState);\r
 \r
-    mAccount = AuthUtils.getCurrentOwnCloudAccount(getActivity());\r
+    mAccount = AccountUtils.getCurrentOwnCloudAccount(getActivity());\r
     populateFileList();\r
   }\r
   \r
     populateFileList();\r
   }\r
   \r
index f03b7a9..1f19629 100644 (file)
@@ -24,13 +24,16 @@ import java.io.IOException;
 
 import org.apache.commons.httpclient.Credentials;\r
 import org.apache.commons.httpclient.HttpClient;\r
 
 import org.apache.commons.httpclient.Credentials;\r
 import org.apache.commons.httpclient.HttpClient;\r
+import org.apache.commons.httpclient.HttpMethod;\r
 import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
 import org.apache.commons.httpclient.auth.AuthScope;\r
 import org.apache.commons.httpclient.UsernamePasswordCredentials;\r
 import org.apache.commons.httpclient.auth.AuthScope;\r
+import org.apache.commons.httpclient.methods.HeadMethod;\r
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.methods.HttpGet;
 import org.apache.http.HttpHost;
 import org.apache.http.HttpResponse;
 import org.apache.http.HttpStatus;
 import org.apache.http.HttpVersion;
 import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpHead;\r
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.params.ConnManagerPNames;
 import org.apache.http.client.methods.HttpPut;
 import org.apache.http.conn.ClientConnectionManager;
 import org.apache.http.conn.params.ConnManagerPNames;
@@ -155,6 +158,17 @@ public class WebdavClient extends HttpClient {
     
     return result;
   }
     
     return result;
   }
+  \r
+  public int tryToLogin() {\r
+    int r = 0; \r
+    HeadMethod head = new HeadMethod(mUri.toString());\r
+    try {\r
+      r = executeMethod(head);\r
+    } catch (Exception e) {\r
+      Log.e(TAG, "Error: " + e.getMessage());\r
+    }\r
+    return r;\r
+  }\r
   
   public boolean createDirectory(String path) {
     HttpMkCol method = new HttpMkCol(mUri.toString() + path + "/");
   
   public boolean createDirectory(String path) {
     HttpMkCol method = new HttpMkCol(mUri.toString() + path + "/");