package com.owncloud.android.oc_framework_test_project;
-import java.io.IOException;
-
-import com.owncloud.android.oc_framework.accounts.AccountUtils.AccountNotFoundException;
import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;
import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
import com.owncloud.android.oc_framework.operations.remote.RenameRemoteFileOperation;
-import android.os.AsyncTask;
+import android.net.Uri;
import android.os.Bundle;
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
import android.app.Activity;
-import android.content.Context;
-import android.util.Log;
import android.view.Menu;
/**
* Activity to test OC framework
* @author masensio
- *
+ * @author David A. Velasco
*/
public class TestActivity extends Activity {
- private static final String TAG = "TestActivity";
-
// This account must exists on the simulator / device
- private static final String mAccountHost = "beta.owncloud.com";
- private static final String mAccountUser = "testandroid";
- private static final String mAccountName = mAccountUser + "@"+ mAccountHost;
- private static final String mAccountPass = "testandroid";
- private static final String mAccountType = "owncloud";
+ private static final String mServerUri = "https://beta.owncloud.com/owncloud/remote.php/webdav";
+ private static final String mUser = "testandroid";
+ private static final String mPass = "testandroid";
- private Account mAccount = null;
+ //private Account mAccount = null;
private WebdavClient mClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
-
- AccountManager am = AccountManager.get(this);
-
- Account[] ocAccounts = am.getAccountsByType(mAccountType);
- for (Account ac : ocAccounts) {
- if (ac.name.equals(mAccountName)) {
- mAccount = ac;
- break;
- }
- }
-
- // Get the WebDavClient
- AuthTask task = new AuthTask();
- task.execute(this.getApplicationContext());
-
+ Uri uri = Uri.parse(mServerUri);
+ mClient = OwnCloudClientFactory.createOwnCloudClient(uri ,getApplicationContext(), true);
+ mClient.setBasicCredentials(mUser, mPass);
}
@Override
return result;
}
- private class AuthTask extends AsyncTask<Context, Void, WebdavClient> {
-
- @Override
- protected WebdavClient doInBackground(Context... params) {
- WebdavClient client = null;
- try {
- client = OwnCloudClientFactory.createOwnCloudClient(mAccount, (Context) params[0] );
- } catch (OperationCanceledException e) {
- Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
- e.printStackTrace();
- } catch (AuthenticatorException e) {
- Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
- e.printStackTrace();
- } catch (AccountNotFoundException e) {
- Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
- e.printStackTrace();
- } catch (IOException e) {
- Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
- e.printStackTrace();
- } catch (IllegalStateException e) {
- Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
- e.printStackTrace();
- }
- return client;
- }
-
- @Override
- protected void onPostExecute(WebdavClient result) {
- // TODO Auto-generated method stub
- super.onPostExecute(result);
- mClient = result;
- }
-
- }
}