8c5ed05b4a3a01c32f280e4b39ade42cf96732cc
[pub/Android/ownCloud.git] / oc_framework-test-project / src / com / owncloud / android / oc_framework_test_project / TestActivity.java
1 package com.owncloud.android.oc_framework_test_project;
2
3 import java.io.IOException;
4 import com.owncloud.android.oc_framework.authentication.AccountUtils.AccountNotFoundException;
5 import com.owncloud.android.oc_framework.network.OwnCloudClientUtils;
6 import com.owncloud.android.oc_framework.network.webdav.WebdavClient;
7 import com.owncloud.android.oc_framework.operations.RemoteOperationResult;
8 import com.owncloud.android.oc_framework.operations.remote.CreateRemoteFolderOperation;
9
10 import android.os.Bundle;
11 import android.accounts.Account;
12 import android.accounts.AccountManager;
13 import android.accounts.AuthenticatorException;
14 import android.accounts.OperationCanceledException;
15 import android.app.Activity;
16 import android.util.Log;
17 import android.view.Menu;
18
19 public class TestActivity extends Activity {
20
21 private static final String TAG = "TestActivity";
22
23 private Account mAccount;
24 private WebdavClient mClient;
25
26 @Override
27 protected void onCreate(Bundle savedInstanceState) {
28 super.onCreate(savedInstanceState);
29 setContentView(R.layout.activity_test);
30
31 String accountName = "admin@beta.owncloud.com";
32 String accountHost = "beta.owncloud.com";
33 String accountUser = "admin";
34 String accountPass = "owncloud42";
35 String accountType = "owncloud";
36 String accountTypePass = "owncloud.password";
37 String authorities = "org.owncloud";
38
39 mAccount = new Account(accountName, accountType);
40 AccountManager am = AccountManager.get(this);
41 am.addAccountExplicitly(mAccount, accountPass, null);
42
43
44 try {
45 mClient = OwnCloudClientUtils.createOwnCloudClient(mAccount, this.getApplicationContext(), authorities);
46 } catch (OperationCanceledException e) {
47 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
48 e.printStackTrace();
49 } catch (AuthenticatorException e) {
50 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
51 e.printStackTrace();
52 } catch (AccountNotFoundException e) {
53 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
54 e.printStackTrace();
55 } catch (IOException e) {
56 Log.e(TAG, "Error while trying to access to " + mAccount.name, e);
57 e.printStackTrace();
58 }
59 }
60
61 @Override
62 public boolean onCreateOptionsMenu(Menu menu) {
63 // Inflate the menu; this adds items to the action bar if it is present.
64 getMenuInflater().inflate(R.menu.test, menu);
65 return true;
66 }
67
68 public RemoteOperationResult createFolder(String remotePath, boolean createFullPath) {
69
70 CreateRemoteFolderOperation createOperation = new CreateRemoteFolderOperation(remotePath, createFullPath);
71 RemoteOperationResult result = createOperation.execute(mClient);
72
73 return result;
74 }
75 }