1 package com
.owncloud
.android
.oc_framework
.sampleclient
;
3 import com
.owncloud
.android
.oc_framework
.accounts
.AccountUtils
;
4 import com
.owncloud
.android
.oc_framework
.network
.webdav
.OwnCloudClientFactory
;
5 import com
.owncloud
.android
.oc_framework
.network
.webdav
.WebdavClient
;
6 import com
.owncloud
.android
.oc_framework
.operations
.OnRemoteOperationListener
;
7 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperation
;
8 import com
.owncloud
.android
.oc_framework
.operations
.RemoteOperationResult
;
9 import com
.owncloud
.android
.oc_framework
.operations
.remote
.ReadRemoteFolderOperation
;
10 import com
.owncloud
.android
.oc_framework
.utils
.FileUtils
;
12 import android
.app
.Activity
;
13 import android
.net
.Uri
;
14 import android
.os
.Bundle
;
15 import android
.os
.Handler
;
16 import android
.view
.View
;
17 import android
.widget
.Toast
;
19 public class MainActivity
extends Activity
implements OnRemoteOperationListener
{
21 private Handler mHandler
;
23 /** Called when the activity is first created. */
25 public void onCreate(Bundle savedInstanceState
) {
26 super.onCreate(savedInstanceState
);
27 setContentView(R
.layout
.main
);
28 mHandler
= new Handler();
31 public void onClickHandler(View button
) {
32 switch (button
.getId()) {
33 case R
.id
.button_refresh
:
36 case R
.id
.button_upload
:
39 case R
.id
.button_delete_remote
:
40 startRemoteDeletion();
42 case R
.id
.button_download
:
45 case R
.id
.button_delete_local
:
49 Toast
.makeText(this, R
.string
.youre_doing_it_wrong
, Toast
.LENGTH_SHORT
).show();
53 private void startRefresh() {
54 RemoteOperation refreshOperation
= new ReadRemoteFolderOperation(FileUtils
.PATH_SEPARATOR
);
55 Uri serverUri
= Uri
.parse(getString(R
.string
.server_base_url
) + AccountUtils
.WEBDAV_PATH_4_0
);
56 WebdavClient client
= OwnCloudClientFactory
.createOwnCloudClient(serverUri
, this, true
);
57 client
.setBasicCredentials(getString(R
.string
.username
), getString(R
.string
.password
));
58 refreshOperation
.execute(client
, this, mHandler
);
61 private void startUpload() {
62 Toast
.makeText(this, R
.string
.todo_start_upload
, Toast
.LENGTH_SHORT
).show();
65 private void startRemoteDeletion() {
66 Toast
.makeText(this, R
.string
.todo_start_remote_deletion
, Toast
.LENGTH_SHORT
).show();
69 private void startDownload() {
70 Toast
.makeText(this, R
.string
.todo_start_download
, Toast
.LENGTH_SHORT
).show();
73 private void startLocalDeletion() {
74 Toast
.makeText(this, R
.string
.todo_start_local_deletion
, Toast
.LENGTH_SHORT
).show();
78 public void onRemoteOperationFinish(RemoteOperation operation
, RemoteOperationResult result
) {
79 if (result
.isSuccess()) {
80 Toast
.makeText(this, R
.string
.todo_operation_finished_in_success
, Toast
.LENGTH_SHORT
).show();
82 Toast
.makeText(this, R
.string
.todo_operation_finished_in_fail
, Toast
.LENGTH_SHORT
).show();