1 package com
.owncloud
.android
.oc_framework_test_project
;
3 import java
.io
.IOException
;
5 import com
.owncloud
.android
.oc_framework
.accounts
.AccountUtils
.AccountNotFoundException
;
6 import com
.owncloud
.android
.oc_framework
.network
.webdav
.OwnCloudClientFactory
;
7 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
8 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
9 import com
.owncloud
.android
.oc_framework
.operations
.remote
.CreateRemoteFolderOperation
;
10 import com
.owncloud
.android
.oc_framework
.operations
.remote
.RenameRemoteFileOperation
;
12 import android
.os
.AsyncTask
;
13 import android
.os
.Bundle
;
14 import android
.accounts
.Account
;
15 import android
.accounts
.AccountManager
;
16 import android
.accounts
.AuthenticatorException
;
17 import android
.accounts
.OperationCanceledException
;
18 import android
.app
.Activity
;
19 import android
.content
.Context
;
20 import android
.util
.Log
;
21 import android
.view
.Menu
;
24 * Activity to test OC framework
28 public class TestActivity
extends Activity
{
30 private static final String TAG
= "TestActivity";
32 // This account must exists on the simulator / device
33 private static final String mAccountHost
= "beta.owncloud.com";
34 private static final String mAccountUser
= "testandroid";
35 private static final String mAccountName
= mAccountUser
+ "@"+ mAccountHost
;
36 private static final String mAccountPass
= "testandroid";
37 private static final String mAccountType
= "owncloud";
39 private Account mAccount
= null
;
40 private WebdavClient mClient
;
43 protected void onCreate(Bundle savedInstanceState
) {
44 super.onCreate(savedInstanceState
);
45 setContentView(R
.layout
.activity_test
);
47 AccountManager am
= AccountManager
.get(this);
49 Account
[] ocAccounts
= am
.getAccountsByType(mAccountType
);
50 for (Account ac
: ocAccounts
) {
51 if (ac
.name
.equals(mAccountName
)) {
57 // Get the WebDavClient
58 AuthTask task
= new AuthTask();
59 task
.execute(this.getApplicationContext());
64 public boolean onCreateOptionsMenu(Menu menu
) {
65 // Inflate the menu; this adds items to the action bar if it is present.
66 getMenuInflater().inflate(R
.menu
.test
, menu
);
71 * Access to the library method to Create a Folder
73 * @param createFullPath
77 public RemoteOperationResult
createFolder(String remotePath
, boolean createFullPath
) {
79 CreateRemoteFolderOperation createOperation
= new CreateRemoteFolderOperation(remotePath
, createFullPath
);
80 RemoteOperationResult result
= createOperation
.execute(mClient
);
86 * Access to the library method to Rename a File or Folder
87 * @param oldName Old name of the file.
88 * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
89 * @param newName New name to set as the name of file.
90 * @param newRemotePath New remote path to move the file, for folders it starts and ends by "/"
95 public RemoteOperationResult
renameFile(String oldName
, String oldRemotePath
, String newName
, String newRemotePath
) {
97 RenameRemoteFileOperation renameOperation
= new RenameRemoteFileOperation(oldName
, oldRemotePath
, newName
, newRemotePath
);
98 RemoteOperationResult result
= renameOperation
.execute(mClient
);
103 private class AuthTask
extends AsyncTask
<Context
, Void
, WebdavClient
> {
106 protected WebdavClient
doInBackground(Context
... params
) {
107 WebdavClient client
= null
;
109 client
= OwnCloudClientFactory
.createOwnCloudClient(mAccount
, (Context
) params
[0] );
110 } catch (OperationCanceledException e
) {
111 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
113 } catch (AuthenticatorException e
) {
114 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
116 } catch (AccountNotFoundException e
) {
117 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
119 } catch (IOException e
) {
120 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
122 } catch (IllegalStateException e
) {
123 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
130 protected void onPostExecute(WebdavClient result
) {
131 // TODO Auto-generated method stub
132 super.onPostExecute(result
);