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
.Bundle
;
13 import android
.accounts
.Account
;
14 import android
.accounts
.AccountManager
;
15 import android
.accounts
.AuthenticatorException
;
16 import android
.accounts
.OperationCanceledException
;
17 import android
.app
.Activity
;
18 import android
.util
.Log
;
19 import android
.view
.Menu
;
22 * Activity to test OC framework
26 public class TestActivity
extends Activity
{
28 private static final String TAG
= "TestActivity";
30 // This account must exists on the simulator / device
31 private static final String mAccountHost
= "beta.owncloud.com";
32 private static final String mAccountUser
= "testandroid";
33 private static final String mAccountName
= mAccountUser
+ "@"+ mAccountHost
;
34 private static final String mAccountPass
= "testandroid";
35 private static final String mAccountType
= "owncloud";
37 private Account mAccount
= null
;
38 private WebdavClient mClient
;
41 protected void onCreate(Bundle savedInstanceState
) {
42 super.onCreate(savedInstanceState
);
43 setContentView(R
.layout
.activity_test
);
45 AccountManager am
= AccountManager
.get(this);
47 Account
[] ocAccounts
= am
.getAccountsByType(mAccountType
);
48 for (Account ac
: ocAccounts
) {
49 if (ac
.name
.equals(mAccountName
)) {
55 // if (mAccount == null) {
56 // mAccount = new Account(accountName, mAccountType);
57 // am.addAccountExplicitly(mAccount, mAccountPass, null);
58 // am.setUserData(mAccount, "oc_version", "5.0.14");
59 // am.setUserData(mAccount, "oc_base_url", "http://beta.owncloud.com/owncloud");
61 Log
.d(TAG
, "oc_version --->"+ am
.getUserData(mAccount
, "oc_version") );
62 Log
.d(TAG
, "oc_base_url --->"+ am
.getUserData(mAccount
, "oc_base_url") );
67 mClient
= OwnCloudClientFactory
.createOwnCloudClient(mAccount
, this.getApplicationContext());
68 } catch (OperationCanceledException e
) {
69 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
71 } catch (AuthenticatorException e
) {
72 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
74 } catch (AccountNotFoundException e
) {
75 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
77 } catch (IOException e
) {
78 Log
.e(TAG
, "Error while trying to access to " + mAccount
.name
, e
);
84 public boolean onCreateOptionsMenu(Menu menu
) {
85 // Inflate the menu; this adds items to the action bar if it is present.
86 getMenuInflater().inflate(R
.menu
.test
, menu
);
91 * Access to the library method to Create a Folder
94 * @param createFullPath
98 public RemoteOperationResult
createFolder(String folderName
, String remotePath
, boolean createFullPath
) {
100 CreateRemoteFolderOperation createOperation
= new CreateRemoteFolderOperation(folderName
, remotePath
, createFullPath
);
101 RemoteOperationResult result
= createOperation
.execute(mClient
);
107 * Access to the library method to Rename a File or Folder
108 * @param oldName Old name of the file.
109 * @param oldRemotePath Old remote path of the file. For folders it starts and ends by "/"
110 * @param newName New name to set as the name of file.
111 * @param newRemotePath New remote path to move the file, for folders it starts and ends by "/"
116 public RemoteOperationResult
renameFile(String oldName
, String oldRemotePath
, String newName
, String newRemotePath
) {
118 RenameRemoteFileOperation renameOperation
= new RenameRemoteFileOperation(oldName
, oldRemotePath
, newName
, newRemotePath
);
119 RemoteOperationResult result
= renameOperation
.execute(mClient
);