Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / android / ContainerObjectsActivity.java @ 6ba04c48

History | View | Annotate | Download (38.6 kB)

1
package com.rackspace.cloud.android;
2

    
3

    
4

    
5
import java.io.File;
6
import java.net.URLEncoder;
7
import java.util.ArrayList;
8
import java.util.Arrays;
9
import java.util.List;
10

    
11
import org.apache.http.HttpResponse;
12

    
13
import android.app.Activity;
14
import android.app.AlertDialog;
15
import android.app.Dialog;
16
import android.content.ActivityNotFoundException;
17
import android.content.DialogInterface;
18
import android.content.Intent;
19
import android.database.Cursor;
20
import android.net.Uri;
21
import android.os.AsyncTask;
22
import android.os.Bundle;
23
import android.util.Log;
24
import android.view.ContextMenu;
25
import android.view.ContextMenu.ContextMenuInfo;
26
import android.view.LayoutInflater;
27
import android.view.Menu;
28
import android.view.MenuInflater;
29
import android.view.MenuItem;
30
import android.view.View;
31
import android.view.ViewGroup;
32
import android.webkit.MimeTypeMap;
33
import android.widget.AdapterView;
34
import android.widget.ArrayAdapter;
35
import android.widget.EditText;
36
import android.widget.ImageView;
37
import android.widget.ListView;
38
import android.widget.TextView;
39
import android.widget.Toast;
40

    
41
import com.rackspace.cloud.files.api.client.Container;
42
import com.rackspace.cloud.files.api.client.ContainerManager;
43
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
44
import com.rackspace.cloud.files.api.client.ContainerObjects;
45
import com.rackspace.cloud.files.api.client.parsers.OthersXmlParser;
46
import com.rackspace.cloud.servers.api.client.CloudServersException;
47
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
48

    
49
/**
50
 * 
51
 * @author Phillip Toohill
52
 * 
53
 */
54

    
55
public class ContainerObjectsActivity extends CloudListActivity {
56

    
57
        private static final int deleteContainer = 0;
58
        private static final int deleteFolder = 1;
59
        private static final int deleteContext = 2;
60
        private static final int toTrashContext = 3;
61
        private static final int fromTrashContext = 4;
62
        private String currentSelectedPath=null;
63
        private ContainerObjects[] files;
64
        private static Container container;
65
        public String LOG = "viewFilesActivity";
66
        private String cdnEnabledIs;
67
        public Object megaBytes;
68
        public Object kiloBytes;
69
        public int bConver = 1048576;
70
        public int kbConver = 1024;
71
        private boolean loadingFiles;
72
        private String currentPath;
73
        private AndroidCloudApplication app;
74
        private AddObjectListenerTask task;
75
        private DeleteObjectListenerTask deleteObjTask;
76
        private DeleteContainerListenerTask deleteContainerTask;
77
        
78

    
79
        @Override
80
        public void onCreate(Bundle savedInstanceState) {
81
                super.onCreate(savedInstanceState);
82
                trackPageView(GoogleAnalytics.PAGE_FOLDER);
83
                container = getContainer();
84
                if (container.isCdnEnabled() == true) {
85
                        cdnEnabledIs = "true";
86
                } else {
87
                        cdnEnabledIs = "false";
88
                }
89
                
90
                restoreState(savedInstanceState);
91
        }
92

    
93
        protected Container getContainer() {
94
                return (Container) this.getIntent().getExtras().get("container");
95
        }
96

    
97
        @Override
98
        protected void onSaveInstanceState(Bundle outState) {
99
                super.onSaveInstanceState(outState);
100

    
101
                // files stores all the files in the container
102
                outState.putSerializable("container", files);
103

    
104
                // current path represents where you have "navigated" to
105
                outState.putString("path", currentPath);
106

    
107
                outState.putBoolean("loadingFiles", loadingFiles);
108
        }
109

    
110
        protected void restoreState(Bundle state) {
111
                super.restoreState(state);
112
                
113
                /*
114
                 * need reference to the app so you can access curDirFiles as well as
115
                 * processing status
116
                 */
117
                app = (AndroidCloudApplication) this.getApplication();
118

    
119
                if (state != null) {
120
                        if (state.containsKey("path")) {
121
                                currentPath = state.getString("path");
122
                        } else {
123
                                currentPath = "";
124
                        }
125

    
126
                        if (state.containsKey("loadingFiles")
127
                                        && state.getBoolean("loadingFiles")) {
128
                                loadFiles();
129
                        } else if (state.containsKey("container")) {
130
                                files = (ContainerObjects[]) state.getSerializable("container");
131
                                if (app.getCurFiles() == null || app.getCurFiles().size() == 0) {
132
                                        displayNoFilesCell();
133
                                } else {
134
                                        getListView().setDividerHeight(1); // restore divider lines
135
                                        setListAdapter(new FileAdapter());
136

    
137
                                }
138

    
139
                        }
140
                } else {
141
                        currentPath = "";
142
                        loadFiles();
143
                }
144

    
145
                /*
146
                 * if the app is process when we enter the activity we must listen for
147
                 * the new curDirFiles list
148
                 */
149
                if (app.isAddingObject()) {
150
                        task = new AddObjectListenerTask();
151
                        task.execute();
152
                }
153

    
154
                if (app.isDeletingObject()) {
155
                        displayNoFilesCell();
156
                        deleteObjTask = new DeleteObjectListenerTask();
157
                        deleteObjTask.execute();
158
                }
159

    
160
                if (app.isDeletingContainer()) {
161
                        displayNoFilesCell();
162
                        deleteContainerTask = new DeleteContainerListenerTask();
163
                        deleteContainerTask.execute();
164
                }
165

    
166
        }
167

    
168
        @Override
169
        protected void onStop() {
170
                super.onStop();
171

    
172
                /*
173
                 * Need to stop running listener task if we exit
174
                 */
175
                if (task != null) {
176
                        task.cancel(true);
177
                }
178

    
179
                if (deleteObjTask != null) {
180
                        deleteObjTask.cancel(true);
181
                }
182

    
183
                if (deleteContainerTask != null) {
184
                        deleteContainerTask.cancel(true);
185
                }
186

    
187
        }
188

    
189
        /*
190
         * overriding back button press, because we are not actually changing
191
         * activities when we navigate the file structure
192
         */
193
        public void onBackPressed() {
194
                
195
                if (currentPath.equals("")) {
196
                        if(container.getName().equals(Container.MYSHARED)){}
197
                        else
198
                                finish();
199
                } else {
200
                        goUpDirectory();
201
                }
202
        }
203
        List<ContainerObjects> previousFiles = new ArrayList<ContainerObjects>();
204
        /*
205
         * go to the current directory's parent and display that data
206
         */
207
        private void goUpDirectory() {
208
                if(currentSelectedPath != null){
209
                        currentSelectedPath=null;
210
                        loadFiles();
211
                        return;
212
                }
213
                currentPath = currentPath.substring(
214
                                0,
215
                                currentPath.substring(0, currentPath.length() - 2).lastIndexOf(
216
                                                "/") + 1);
217
                if(previousFiles!=null&&previousFiles.size()>0){
218
                        files = previousFiles.toArray(new ContainerObjects[]{});
219
                        previousFiles=null;
220
                        loadCurrentDirectoryFiles();
221
                        displayCurrentFiles();
222
                }
223
                else
224
                        loadFiles();
225
                //now executing new call
226
                
227
        }
228

    
229
        /*
230
         * load all file that are in the container
231
         */
232
        private void loadFiles() {
233
                // displayLoadingCell();
234
                new LoadFilesTask().execute(currentPath);
235
        }
236

    
237
        /*
238
         * load only the files that should display for the current directory in the
239
         * curDirFiles[]
240
         */
241
        protected void loadCurrentDirectoryFiles() {
242
                ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>();
243
                Log.i(LOG, "loading files");
244
                if (files != null) {
245
                        for (int i = 0; i < files.length; i++) {
246
                                Log.i(LOG, "loading files" + i);
247
                                if (fileBelongsInDir(files[i])) {
248
                                        curFiles.add(files[i]);
249
                                }
250
                        }
251
                        app.setCurFiles(curFiles);
252
                }
253
        }
254

    
255
        /*
256
         * determines if a file should be displayed in current directory
257
         */
258
        protected Boolean fileBelongsInDir(ContainerObjects obj) {
259
                /*String objPath = obj.getCName();
260

261
                if (!objPath.startsWith(currentPath)) {
262
                        Log.i(LOG, "Path is:" + currentPath + " " + objPath + " " + false);
263
                        return false;
264
                } else {
265
                        objPath = objPath.substring(currentPath.length());
266
                        Log.i(LOG, "Path is:" + currentPath + " " + objPath + " "
267
                                        + !objPath.contains("/"));
268
                        return !objPath.contains("/");
269
                }*/
270
                return true;
271
        }
272

    
273
        /*
274
         * loads all the files that are in the container into one array
275
         */
276
        private void setFileList(List<ContainerObjects> files) {
277
                if (files == null) {
278
                        files = new ArrayList<ContainerObjects>();
279
                }
280
                String[] fileNames = new String[files.size()];
281
                this.files = new ContainerObjects[files.size()];
282

    
283
                if (files != null) {
284
                        for (int i = 0; i < files.size(); i++) {
285
                                ContainerObjects file = files.get(i);
286
                                // Log.i(file.getCName(),file.getCName());
287
                                this.files[i] = file;
288
                                fileNames[i] = file.getName();
289
                        }
290
                }
291
        }
292

    
293
        protected void displayCurrentFiles() {
294
                if(container.getOtherUser()==null)
295
                        setTitle(container.getName()+": /"+currentPath);
296
                else
297
                        setTitle(container.getOtherUser()+":"+container.getName()+"/"+currentPath);
298
                if (app.getCurFiles().size() == 0) {
299
                        displayNoFilesCell();
300
                } else {
301
                        ArrayList<ContainerObjects> tempList = new ArrayList<ContainerObjects>();
302
                        for (int i = 0; i < app.getCurFiles().size(); i++) {
303
                                tempList.add(app.getCurFiles().get(i));
304
                        }
305
                        getListView().setDividerHeight(1); // restore divider lines
306
                        setListAdapter(new FileAdapter());
307
                }
308
        }
309

    
310
        /*
311
         * display a different empty page depending of if you are at top of
312
         * container or in a folder
313
         */
314
        protected void displayNoFilesCell() {
315
                String a[] = new String[1];
316
                if (currentPath.equals("")) {
317
                        a[0] = "Empty Container";
318
                        setListAdapter(new ArrayAdapter<String>(this,
319
                                        R.layout.noobjectscell, R.id.no_files_label, a));
320
                } else {
321
                        a[0] = "No Files";
322
                        setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell,
323
                                        R.id.no_files_label, a));
324
                }
325
                getListView().setTextFilterEnabled(true);
326
                getListView().setDividerHeight(0); // hide the dividers so it won't look
327
                // like a list row
328
                getListView().setItemsCanFocus(false);
329
        }
330

    
331
        /*
332
         * just get the last part of the filename so the entire file path does not
333
         * show
334
         */
335
        private String getShortName(String longName) {
336
                String s = longName;
337
                if (!s.contains("/")) {
338
                        return s;
339
                } else {
340
                        String tmp = s.substring(s.lastIndexOf('/') + 1);
341
                        if (tmp.equals("")) {
342
                                return s;
343
                        }
344
                        return tmp;
345
                }
346
        }
347

    
348
        /*
349
         * removed a specified object from the array of all the files in the
350
         * container
351
         */
352
        private void removeFromList(String path) {
353
                ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>(
354
                                Arrays.asList(files));
355
                for (int i = 0; i < files.length; i++) {
356
                        if (files[i].getCName()
357
                                        .equals(path.substring(0, path.length() - 1))) {
358
                                temp.remove(i);
359
                        }
360
                }
361
                files = new ContainerObjects[temp.size()];
362
                for (int i = 0; i < temp.size(); i++) {
363
                        files[i] = temp.get(i);
364
                }
365
        }
366

    
367
        protected void onListItemClick(ListView l, View v, int position, long id) {
368
                if (app.getCurFiles() != null && app.getCurFiles().size() > 0) {
369
                        Intent viewIntent;
370
                        if (app.getCurFiles().get(position).isFolder()) {
371
                                currentPath = app.getCurFiles().get(position).getCName() + "/";
372
                                /*if(container.getName().equalsIgnoreCase(Container.MYSHARED)){
373
                                        loadCurrentDirectoryFiles();
374
                                        displayCurrentFiles();
375
                                }
376
                                else{*/
377
                                        previousFiles = Arrays.asList(files);
378
                                        loadFiles();
379
                                //}
380
                                //loadCurrentDirectoryFiles();
381
                                //displayCurrentFiles();
382
                        }
383

    
384
                        else {
385
                                viewIntent = new Intent(this, ContainerObjectDetails.class);
386
                                viewIntent.putExtra("container", app.getCurFiles()
387
                                                .get(position));
388
                                viewIntent.putExtra("cdnUrl", container.getCdnUrl());
389
                                if(container.getOtherUser()!=null)
390
                                        viewIntent.putExtra("otherUser", container.getOtherUser());
391
                                viewIntent.putExtra("containerNames", container.getName());
392
                                viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
393
                                startActivityForResult(viewIntent, 55); // arbitrary number;
394
                                                                                                                // never
395
                                // used again
396
                        }
397
                }
398
        }
399

    
400
        @Override
401
        public boolean onCreateOptionsMenu(Menu menu) {
402
                super.onCreateOptionsMenu(menu);
403
                MenuInflater inflater = getMenuInflater();
404
                inflater.inflate(R.menu.view_container_object_list_menu, menu);
405
                menu.findItem(R.id.enable_cdn).setVisible(false);
406
                if(Container.TRASH.equalsIgnoreCase(container.getName())){
407
                        menu.findItem(R.id.delete_container).setVisible(false);
408
                        menu.findItem(R.id.add_folder).setVisible(false);
409
                        menu.findItem(R.id.add_file).setVisible(false);
410
                }
411
                else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){
412
                        menu.findItem(R.id.delete_container).setVisible(false);
413
                        menu.findItem(R.id.add_folder).setVisible(false);
414
                        menu.findItem(R.id.add_file).setVisible(false);
415
                }
416
                return true;
417
        }
418
        @Override
419
        public void onCreateContextMenu(ContextMenu menu, View v,
420
                        ContextMenuInfo menuInfo) {
421
                super.onCreateContextMenu(menu, v, menuInfo);
422
                MenuInflater inflater = getMenuInflater();
423
                inflater.inflate(R.menu.view_container_object_list_context, menu);
424
                menu.findItem(R.id.fromtrash_contextmenu).setVisible(false);
425
                if(Container.TRASH.equalsIgnoreCase(container.getName())){
426
                        menu.findItem(R.id.delete_contextmenu).setVisible(true);
427
                        menu.findItem(R.id.totrash_contextmenu).setVisible(false);
428
                        menu.findItem(R.id.properties_contextmenu).setVisible(false);
429
                        menu.findItem(R.id.fromtrash_contextmenu).setVisible(true);
430
                }
431
                else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){
432
                        menu.findItem(R.id.delete_contextmenu).setVisible(false);
433
                        menu.findItem(R.id.totrash_contextmenu).setVisible(false);
434
                }
435
        }
436
        ContainerObjects currentSelectedObject=null;
437
        @Override
438
        public boolean onContextItemSelected(final MenuItem item) {
439
                final AdapterView.AdapterContextMenuInfo info;
440
                try {
441
                    info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
442
                } catch (ClassCastException e) {
443
                    Log.e(LOG, "bad menuInfo", e);
444
                    return false;
445
                }
446
                long id = getListAdapter().getItemId(info.position);
447
                final ContainerObjects obj = (ContainerObjects) getListAdapter().getItem(info.position);
448
                currentSelectedPath = obj.getCName() + "/";
449
                currentSelectedObject=obj;
450
                switch (item.getItemId()) {
451
                        case R.id.delete_contextmenu:
452
                                showDialog(deleteContext);
453
                                return true;
454
                        case R.id.totrash_contextmenu:
455
                                showDialog(toTrashContext);
456
                                return true;
457
                        case R.id.fromtrash_contextmenu:
458
                                showDialog(fromTrashContext);
459
                                return true;
460
                        case R.id.properties_contextmenu:
461
                                Intent viewIntent;
462
                                viewIntent = new Intent(this, ContainerObjectDetails.class);
463
                                viewIntent.putExtra("container", obj);
464
                                viewIntent.putExtra("cdnUrl", container.getCdnUrl());
465
                                if(container.getOtherUser()!=null)
466
                                        viewIntent.putExtra("otherUser", container.getOtherUser());
467
                                viewIntent.putExtra("containerNames", container.getName());
468
                                viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
469
                                startActivityForResult(viewIntent, 55);
470
                                return true;
471
                        
472
                }
473
                currentSelectedPath=null;
474
                currentSelectedObject=null;
475
                return false;
476
                
477
        }
478
        @Override
479
        /*
480
         * option performed for delete depends on if you are at the top of a
481
         * container or in a folder
482
         */
483
        public boolean onOptionsItemSelected(MenuItem item) {
484
                switch (item.getItemId()) {
485
                case R.id.delete_container:
486
                        if (currentPath.equals("")) {
487
                                showDialog(deleteContainer);
488
                        } else {
489
                                showDialog(deleteFolder);
490
                        }
491
                        return true;
492
                case R.id.enable_cdn:
493
                        Intent viewIntent1 = new Intent(this, EnableCDNActivity.class);
494
                        viewIntent1.putExtra("Cname", container.getName());
495
                        startActivityForResult(viewIntent1, 56);
496
                        return true;
497
                case R.id.refresh:
498
                        loadFiles();
499
                        return true;
500
                case R.id.add_folder:
501
                        showDialog(R.id.add_folder);
502
                        return true;
503
                case R.id.add_file:
504
                        /*
505
                         * Intent viewIntent2 = new Intent(this, AddFileActivity.class);
506
                         * viewIntent2.putExtra("Cname", container.getName());
507
                         * viewIntent2.putExtra("curPath", currentPath);
508
                         * startActivityForResult(viewIntent2, 56);
509
                         */
510

    
511
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
512
                        intent.addCategory(Intent.CATEGORY_OPENABLE);
513
                        intent.setData(Uri.parse("file://"));
514
                        intent.setType("*/*");
515
                        try {
516
                                int i = 1;
517
                                startActivityForResult(intent, i);
518

    
519
                        } catch (ActivityNotFoundException e) {
520
                                Toast.makeText(this, "No File Manager", Toast.LENGTH_SHORT)
521
                                                .show();
522
                        }
523

    
524
                        return true;
525
                }
526
                return false;
527
        }
528

    
529
        @Override
530
        protected Dialog onCreateDialog(int id) {
531
                switch (id) {
532
                case deleteContainer:
533
                        if (app.getCurFiles().size() == 0) {
534
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
535
                                                .setIcon(R.drawable.alert_dialog_icon)
536
                                                .setTitle("Delete Container")
537
                                                .setMessage(
538
                                                                "Are you sure you want to delete this Container?")
539
                                                .setPositiveButton("Delete Container",
540
                                                                new DialogInterface.OnClickListener() {
541
                                                                        public void onClick(DialogInterface dialog,
542
                                                                                        int whichButton) {
543
                                                                                // User clicked OK so do some stuff
544
                                                                                trackEvent(
545
                                                                                                GoogleAnalytics.CATEGORY_CONTAINER,
546
                                                                                                GoogleAnalytics.EVENT_DELETE,
547
                                                                                                "", -1);
548
                                                                                new DeleteContainerTask()
549
                                                                                                .execute(currentPath);
550
                                                                        }
551
                                                                })
552
                                                .setNegativeButton("Cancel",
553
                                                                new DialogInterface.OnClickListener() {
554
                                                                        public void onClick(DialogInterface dialog,
555
                                                                                        int whichButton) {
556
                                                                                // User clicked Cancel so do some stuff
557
                                                                        }
558
                                                                }).create();
559
                        } else {
560
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
561
                                                .setIcon(R.drawable.alert_dialog_icon)
562
                                                .setTitle("Delete Container")
563
                                                .setMessage("Container must be empty to delete")
564
                                                .setNegativeButton("OK",
565
                                                                new DialogInterface.OnClickListener() {
566
                                                                        public void onClick(DialogInterface dialog,
567
                                                                                        int whichButton) {
568
                                                                                // User clicked Cancel so do some stuff
569
                                                                        }
570
                                                                }).create();
571
                        }
572
                case deleteFolder:
573
                        if (app.getCurFiles().size() == 0) {
574
                                return new AlertDialog.Builder(ContainerObjectsActivity.this)
575
                                                .setIcon(R.drawable.alert_dialog_icon)
576
                                                .setTitle("Delete Folder")
577
                                                .setMessage(
578
                                                                "Are you sure you want to delete this Folder?")
579
                                                .setPositiveButton("Delete Folder",
580
                                                                new DialogInterface.OnClickListener() {
581
                                                                        public void onClick(DialogInterface dialog,
582
                                                                                        int whichButton) {
583
                                                                                // User clicked OK so do some stuff
584
                                                                                new DeleteObjectTask().execute(container.getName(), currentPath);
585
                                                                        }
586
                                                                })
587
                                                .setNegativeButton("Cancel",
588
                                                                new DialogInterface.OnClickListener() {
589
                                                                        public void onClick(DialogInterface dialog,
590
                                                                                        int whichButton) {
591
                                                                                // User clicked Cancel so do some stuff
592
                                                                        }
593
                                                                }).create();
594
                        }
595
                case deleteContext:
596
                        return new AlertDialog.Builder(ContainerObjectsActivity.this)
597
                                .setIcon(R.drawable.alert_dialog_icon)
598
                                .setTitle("Delete Object")
599
                                .setMessage(
600
                                                "Are you sure you want to delete this Object?")
601
                                                        .setPositiveButton("Delete Object",
602
                                                                        new DialogInterface.OnClickListener() {
603
                                                                                public void onClick(DialogInterface dialog,
604
                                                                                                int whichButton) {
605
                                                                                        //         User clicked OK so do some stuff
606
                                                                                        new DeleteObjectTask().execute(container.getName(), currentSelectedPath);
607
                                                                                }
608
                                                                        })
609
                                                                        .setNegativeButton("Cancel",
610
                                                                                        new DialogInterface.OnClickListener() {
611
                                                                                public void onClick(DialogInterface dialog,
612
                                                                                                int whichButton) {
613
                                                                                        currentSelectedPath=null;
614
                                                                                        // User clicked Cancel so do some stuff
615
                                                                                }
616
                                                                        }).create();
617
                case toTrashContext:
618
                        return new AlertDialog.Builder(ContainerObjectsActivity.this)
619
                                .setIcon(R.drawable.alert_dialog_icon)
620
                                .setTitle("Move Object To Trash")
621
                                .setMessage(
622
                                                "Are you sure you want to trash this Object?")
623
                                                        .setPositiveButton("Trash Object",
624
                                                                        new DialogInterface.OnClickListener() {
625
                                                                                public void onClick(DialogInterface dialog,
626
                                                                                                int whichButton) {
627
                                                                                        //         User clicked OK so do some stuff
628
                                                                                        new TrashObjectTask().execute(container.getName(), currentSelectedPath);
629
                                                                                }
630
                                                                        })
631
                                                                        .setNegativeButton("Cancel",
632
                                                                                        new DialogInterface.OnClickListener() {
633
                                                                                public void onClick(DialogInterface dialog,
634
                                                                                                int whichButton) {
635
                                                                                        currentSelectedPath=null;
636
                                                                                        // User clicked Cancel so do some stuff
637
                                                                                }
638
                                                                        }).create();
639
                case fromTrashContext:
640
                        return new AlertDialog.Builder(ContainerObjectsActivity.this)
641
                                .setIcon(R.drawable.alert_dialog_icon)
642
                                .setTitle("Restore Object To Pithos")
643
                                .setMessage(
644
                                                "Are you sure you want to restore this Object?")
645
                                                        .setPositiveButton("Restore Object",
646
                                                                        new DialogInterface.OnClickListener() {
647
                                                                                public void onClick(DialogInterface dialog,
648
                                                                                                int whichButton) {
649
                                                                                        //         User clicked OK so do some stuff
650
                                                                                        new RestoreTrashObjectTask().execute(container.getName(), currentSelectedPath);
651
                                                                                }
652
                                                                        })
653
                                                                        .setNegativeButton("Cancel",
654
                                                                                        new DialogInterface.OnClickListener() {
655
                                                                                public void onClick(DialogInterface dialog,
656
                                                                                                int whichButton) {
657
                                                                                        currentSelectedPath=null;
658
                                                                                        // User clicked Cancel so do some stuff
659
                                                                                }
660
                                                                        }).create();
661
                case R.id.add_folder:
662
                        final EditText input = new EditText(this);
663
                        return new AlertDialog.Builder(ContainerObjectsActivity.this)
664
                                        .setIcon(R.drawable.alert_dialog_icon)
665
                                        .setView(input)
666
                                        .setTitle("Add Folder")
667
                                        .setMessage("Enter new name for folder: ")
668
                                        .setPositiveButton("Add",
669
                                                        new DialogInterface.OnClickListener() {
670
                                                                public void onClick(DialogInterface dialog,
671
                                                                                int whichButton) {
672
                                                                        // User clicked OK so do some stuff
673
                                                                        String[] info = {
674
                                                                                        input.getText().toString(),
675
                                                                                        "application/directory" };
676
                                                                        new AddFolderTask().execute(info);
677
                                                                }
678
                                                        })
679
                                        .setNegativeButton("Cancel",
680
                                                        new DialogInterface.OnClickListener() {
681
                                                                public void onClick(DialogInterface dialog,
682
                                                                                int whichButton) {
683
                                                                        // User clicked Cancel so do some stuff
684
                                                                }
685
                                                        }).create();
686
                }
687
                return null;
688
        }
689

    
690
        @Override
691
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
692
                super.onActivityResult(requestCode, resultCode, data);
693

    
694
                if (resultCode == RESULT_OK && requestCode == 56) {
695
                        // a sub-activity kicked back, so we want to refresh the server list
696
                        previousFiles = null;
697
                        loadFiles();
698
                }
699
                
700
                if (resultCode == RESULT_OK && requestCode == 1) {
701
                        String filename = data.getDataString();
702
                        uploadFile(filename, data);
703
                        
704
                }
705

    
706
                // deleted file so need to update the list
707
                if (requestCode == 55 && resultCode == 99) {
708
                        Log.d(LOG,"LOADING FROM DDELETE");
709
                        previousFiles = null;
710
                        loadFiles();
711
                }
712

    
713
        }
714

    
715
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
716
                FileAdapter() {
717
                        super(ContainerObjectsActivity.this,
718
                                        R.layout.listcontainerobjectcell, app.getCurFiles());
719
                }
720

    
721
                public View getView(int position, View convertView, ViewGroup parent) {
722
                        ContainerObjects file = app.getCurFiles().get(position);
723
                        LayoutInflater inflater = getLayoutInflater();
724
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
725
                                        parent, false);
726

    
727
                        TextView label = (TextView) row.findViewById(R.id.label);
728
                        label.setText(getShortName(file.getCName()));
729

    
730
                        ImageView objectImage = (ImageView) row
731
                                        .findViewById(R.id.file_type_image);
732
                        if (file.isFolder()) {
733
                                objectImage.setImageResource(R.drawable.folder);
734
                        } else {
735
                                objectImage.setImageResource(R.drawable.file);
736
                        }
737

    
738
                        if (file.getBytes() >= bConver) {
739
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
740
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
741
                                sublabel.setText(megaBytes + " MB");
742
                        } else if (file.getBytes() >= kbConver) {
743
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
744
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
745
                                sublabel.setText(kiloBytes + " KB");
746
                        } else {
747
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
748
                                sublabel.setText(file.getBytes() + " B");
749
                        }
750

    
751
                        return (row);
752
                }
753
        }
754

    
755
        private class LoadFilesTask extends
756
                        AsyncTask<String, Void, List<ContainerObjects>> {
757

    
758
                private CloudServersException exception;
759

    
760
                protected void onPreExecute() {
761
                        showDialog();
762
                        loadingFiles = true;
763
                }
764

    
765
                @Override
766
                protected List<ContainerObjects> doInBackground(String... path) {
767
                        List<ContainerObjects> files = null;
768
                        try {
769
                                if (container.getName().equals(Container.MYSHARED)) {
770
                                        files = (new ContainerObjectManager(getContext()))
771
                                                        .createListMyShared( container.getName(),
772
                                                                        new ContainerManager(getContext())
773
                                                                                        .createList(true),path[0]);
774
                                } else if (container.getName().equals(Container.OTHERS)) {
775

    
776
                                } else {
777
                                        if (container.getOtherUser() == null)
778
                                                files = (new ContainerObjectManager(getContext()))
779
                                                                .createList(container.getName(), path[0]);
780
                                        else
781
                                                files = (new ContainerObjectManager(getContext()))
782
                                                                .createOtherList(container.getName(), container.getOtherUser(),path[0]);
783
                                }
784
                        } catch (CloudServersException e) {
785
                                exception = e;
786
                                e.printStackTrace();
787
                        }
788
                        return files;
789
                }
790

    
791
                @Override
792
                protected void onPostExecute(List<ContainerObjects> result) {
793
                        loadingFiles = false;
794
                        hideDialog();
795
                        if (exception != null) {
796
                                showAlert("Error", exception.getMessage());
797
                        }
798
                        setFileList(result);
799
                        loadCurrentDirectoryFiles();
800
                        displayCurrentFiles();
801
                }
802

    
803
        }
804

    
805
        private class AddFolderTask extends AsyncTask<String, Void, HttpBundle> {
806

    
807
                private CloudServersException exception;
808

    
809
                @Override
810
                protected void onPreExecute() {
811
                        showDialog();
812
                        app.setAddingObject(true);
813
                        task = new AddObjectListenerTask();
814
                        task.execute();
815
                }
816

    
817
                @Override
818
                protected HttpBundle doInBackground(String... data) {
819
                        HttpBundle bundle = null;
820
                        try {
821

    
822
                                bundle = (new ContainerObjectManager(getContext())).addObject(
823
                                                container.getName(), currentPath, data[0], data[1],container.getOtherUser());
824
                        } catch (CloudServersException e) {
825
                                exception = e;
826
                        }
827
                        return bundle;
828
                }
829

    
830
                @Override
831
                protected void onPostExecute(HttpBundle bundle) {
832
                        app.setAddingObject(false);
833
                        hideDialog();
834
                        HttpResponse response = bundle.getResponse();
835
                        if (response != null) {
836
                                int statusCode = response.getStatusLine().getStatusCode();
837
                                if (statusCode == 201) {
838
                                        setResult(Activity.RESULT_OK);
839
                                        // loading the new files is done by ListenerTask
840
                                } else {
841
                                        CloudServersException cse = parseCloudServersException(response);
842
                                        if ("".equals(cse.getMessage())) {
843
                                                showError("There was a problem deleting your folder.",
844
                                                                bundle);
845
                                        } else {
846
                                                showError("There was a problem deleting your folder: "
847
                                                                + cse.getMessage(), bundle);
848
                                        }
849
                                }
850
                        } else if (exception != null) {
851
                                showError("There was a problem deleting your folder: "
852
                                                + exception.getMessage(), bundle);
853
                        }
854
                }
855
        }
856
        
857
        private class AddFileTask extends AsyncTask<String, Void, HttpBundle> {
858

    
859
                private CloudServersException exception;
860

    
861
                @Override
862
                protected void onPreExecute() {
863
                        showDialog();
864
                        app.setAddingObject(true);
865
                        task = new AddObjectListenerTask();
866
                        task.execute();
867
                }
868

    
869
                @Override
870
                protected HttpBundle doInBackground(String... data) {
871
                        HttpBundle bundle = null;
872
                        try {
873

    
874
                                bundle = (new ContainerObjectManager(getContext())).addFileObject(
875
                                                container.getName(), currentPath, data[0], data[1], data[2], container.getOtherUser());
876
                        } catch (CloudServersException e) {
877
                                exception = e;
878
                        }
879
                        return bundle;
880
                }
881

    
882
                @Override
883
                protected void onPostExecute(HttpBundle bundle) {
884
                        app.setAddingObject(false);
885
                        hideDialog();
886
                        HttpResponse response = bundle.getResponse();
887
                        if (response != null) {
888
                                int statusCode = response.getStatusLine().getStatusCode();
889
                                if (statusCode == 201) {
890
                                        setResult(Activity.RESULT_OK);
891
                                        // loading the new files is done by ListenerTask
892
                                } else {
893
                                        CloudServersException cse = parseCloudServersException(response);
894
                                        if ("".equals(cse.getMessage())) {
895
                                                showError("There was a problem deleting your folder.",
896
                                                                bundle);
897
                                        } else {
898
                                                showError("There was a problem deleting your folder: "
899
                                                                + cse.getMessage(), bundle);
900
                                        }
901
                                }
902
                        } else if (exception != null) {
903
                                showError("There was a problem deleting your folder: "
904
                                                + exception.getMessage(), bundle);
905
                        }
906
                }
907
        }
908

    
909
        private class DeleteObjectTask extends AsyncTask<String, Void, HttpBundle> {
910

    
911
                private CloudServersException exception;
912
                public boolean isInFile=false;
913
                @Override
914
                protected void onPreExecute() {
915
                        showDialog();
916
                        app.setDeleteingObject(true);
917
                        deleteObjTask = new DeleteObjectListenerTask();
918
                        deleteObjTask.execute();
919
                }
920

    
921
                @Override
922
                protected HttpBundle doInBackground(String... args) {
923
                        HttpBundle bundle = null;
924
                        try {
925
                                // subtring because the current directory contains a "/" at the
926
                                // end of the string
927
                                String cname = args[0];
928
                                String cpath = args[1];
929
                                bundle = (new ContainerObjectManager(getContext()))
930
                                                .deleteObject(cname, cpath
931
                                                                .substring(0, cpath.length() - 1),container.getOtherUser());
932
                        } catch (CloudServersException e) {
933
                                exception = e;
934
                        }
935
                        return bundle;
936
                }
937

    
938
                @Override
939
                protected void onPostExecute(HttpBundle bundle) {
940
                        app.setDeleteingObject(false);
941
                        hideDialog();
942
                        HttpResponse response = bundle.getResponse();
943
                        if (response != null) {
944
                                int statusCode = response.getStatusLine().getStatusCode();
945
                                if (statusCode == 409) {
946
                                        showAlert("Error",
947
                                                        "Folder must be empty in order to delete");
948
                                }
949
                                if (statusCode == 204) {
950
                                        setResult(Activity.RESULT_OK);
951
                                } else {
952
                                        CloudServersException cse = parseCloudServersException(response);
953
                                        if ("".equals(cse.getMessage())) {
954
                                                showError("There was a problem deleting your folder.",
955
                                                                bundle);
956
                                        } else {
957
                                                showError("There was a problem deleting your folder: "
958
                                                                + cse.getMessage(), bundle);
959
                                        }
960
                                }
961
                        } else if (exception != null) {
962
                                showError("There was a problem deleting your folder: "
963
                                                + exception.getMessage(), bundle);
964
                        }
965
                }
966
        }
967
        
968
        private class TrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
969

    
970
                private CloudServersException exception;
971
                public boolean isInFile=false;
972
                String[] arguments;
973
                @Override
974
                protected void onPreExecute() {
975
                        showDialog();
976
                        
977
                }
978

    
979
                @Override
980
                protected HttpBundle doInBackground(String... args) {
981
                        HttpBundle bundle = null;
982
                        arguments = args;
983
                        try {
984
                                // subtring because the current directory contains a "/" at the
985
                                // end of the string
986
                                String cname = args[0];
987
                                String cpath = args[1];
988
                                bundle = (new ContainerObjectManager(getContext()))
989
                                                .trashObject(cname, cpath
990
                                                                .substring(0, cpath.length() - 1));
991
                        } catch (CloudServersException e) {
992
                                exception = e;
993
                        }
994
                        return bundle;
995
                }
996

    
997
                @Override
998
                protected void onPostExecute(HttpBundle bundle) {
999
                        hideDialog();
1000
                        HttpResponse response = bundle.getResponse();
1001
                        if (response != null) {
1002
                                int statusCode = response.getStatusLine().getStatusCode();
1003
                                if (statusCode == 409) {
1004
                                        showAlert("Error",
1005
                                                        "Folder must be empty in order to delete");
1006
                                }
1007
                                if (statusCode == 201) {
1008
                                        new DeleteObjectTask().execute(arguments);
1009
                                } else {
1010
                                        CloudServersException cse = parseCloudServersException(response);
1011
                                        if ("".equals(cse.getMessage())) {
1012
                                                showError("There was a problem deleting your folder.",
1013
                                                                bundle);
1014
                                        } else {
1015
                                                showError("There was a problem deleting your folder: "
1016
                                                                + cse.getMessage(), bundle);
1017
                                        }
1018
                                }
1019
                        } else if (exception != null) {
1020
                                showError("There was a problem deleting your folder: "
1021
                                                + exception.getMessage(), bundle);
1022
                        }
1023
                }
1024
        }
1025
        
1026
        private class RestoreTrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
1027

    
1028
                private CloudServersException exception;
1029
                public boolean isInFile=false;
1030
                String[] arguments;
1031
                @Override
1032
                protected void onPreExecute() {
1033
                        showDialog();
1034
                        
1035
                }
1036

    
1037
                @Override
1038
                protected HttpBundle doInBackground(String... args) {
1039
                        HttpBundle bundle = null;
1040
                        arguments = args;
1041
                        try {
1042
                                // subtring because the current directory contains a "/" at the
1043
                                // end of the string
1044
                                String cname = args[0];
1045
                                String cpath = args[1];
1046
                                bundle = (new ContainerObjectManager(getContext()))
1047
                                                .restoreObject(cname, cpath
1048
                                                                .substring(0, cpath.length() - 1));
1049
                        } catch (CloudServersException e) {
1050
                                exception = e;
1051
                        }
1052
                        return bundle;
1053
                }
1054

    
1055
                @Override
1056
                protected void onPostExecute(HttpBundle bundle) {
1057
                        hideDialog();
1058
                        HttpResponse response = bundle.getResponse();
1059
                        if (response != null) {
1060
                                int statusCode = response.getStatusLine().getStatusCode();
1061
                                if (statusCode == 409) {
1062
                                        showAlert("Error",
1063
                                                        "Folder must be empty in order to delete");
1064
                                }
1065
                                if (statusCode == 201) {
1066
                                        new DeleteObjectTask().execute(arguments);
1067
                                } else {
1068
                                        CloudServersException cse = parseCloudServersException(response);
1069
                                        if ("".equals(cse.getMessage())) {
1070
                                                showError("There was a problem deleting your folder.",
1071
                                                                bundle);
1072
                                        } else {
1073
                                                showError("There was a problem deleting your folder: "
1074
                                                                + cse.getMessage(), bundle);
1075
                                        }
1076
                                }
1077
                        } else if (exception != null) {
1078
                                showError("There was a problem deleting your folder: "
1079
                                                + exception.getMessage(), bundle);
1080
                        }
1081
                }
1082
        }
1083

    
1084
        private class DeleteContainerTask extends
1085
                        AsyncTask<String, Void, HttpBundle> {
1086

    
1087
                private CloudServersException exception;
1088

    
1089
                @Override
1090
                protected void onPreExecute() {
1091
                        showDialog();
1092
                        app.setDeletingContainer(true);
1093
                        deleteContainerTask = new DeleteContainerListenerTask();
1094
                        deleteContainerTask.execute();
1095
                }
1096

    
1097
                @Override
1098
                protected HttpBundle doInBackground(String... object) {
1099
                        HttpBundle bundle = null;
1100
                        try {
1101
                                bundle = (new ContainerManager(getContext())).delete(container
1102
                                                .getName());
1103
                        } catch (CloudServersException e) {
1104
                                exception = e;
1105
                        }
1106
                        return bundle;
1107
                }
1108

    
1109
                @Override
1110
                protected void onPostExecute(HttpBundle bundle) {
1111
                        hideDialog();
1112
                        app.setDeletingContainer(false);
1113
                        HttpResponse response = bundle.getResponse();
1114
                        if (response != null) {
1115
                                int statusCode = response.getStatusLine().getStatusCode();
1116
                                if (statusCode == 409) {
1117
                                        showError("Container must be empty in order to delete",
1118
                                                        bundle);
1119
                                }
1120
                                if (statusCode == 204) {
1121
                                        setResult(Activity.RESULT_OK);
1122

    
1123
                                } else {
1124
                                        CloudServersException cse = parseCloudServersException(response);
1125
                                        if ("".equals(cse.getMessage())) {
1126
                                                showError(
1127
                                                                "There was a problem deleting your container.",
1128
                                                                bundle);
1129
                                        } else {
1130
                                                showError(
1131
                                                                "There was a problem deleting your container: "
1132
                                                                                + cse.getMessage(), bundle);
1133
                                        }
1134
                                }
1135
                        } else if (exception != null) {
1136
                                showError("There was a problem deleting your server: "
1137
                                                + exception.getMessage(), bundle);
1138
                        }
1139
                }
1140
        }
1141

    
1142
        /*
1143
         * listens for the application to change isProcessing listens so activity
1144
         * knows when it should display the new curDirFiles
1145
         */
1146
        private class AddObjectListenerTask extends AsyncTask<Void, Void, Void> {
1147

    
1148
                @Override
1149
                protected Void doInBackground(Void... arg1) {
1150

    
1151
                        while (app.isAddingObject()) {
1152
                                // wait for process to finish
1153
                                // or have it be canceled
1154
                                if (task.isCancelled()) {
1155
                                        return null;
1156
                                }
1157
                        }
1158
                        return null;
1159
                }
1160

    
1161
                /*
1162
                 * when no longer processing, time to load the new files
1163
                 */
1164
                @Override
1165
                protected void onPostExecute(Void arg1) {
1166
                        hideDialog();
1167
                        loadFiles();
1168
                }
1169
        }
1170

    
1171
        private class DeleteObjectListenerTask extends AsyncTask<Void, Void, Void> {
1172

    
1173
                @Override
1174
                protected Void doInBackground(Void... arg1) {
1175

    
1176
                        while (app.isDeletingObject()) {
1177
                                // wait for process to finish
1178
                                // or have it be canceled
1179
                                if (deleteObjTask.isCancelled()) {
1180
                                        return null;
1181
                                }
1182
                        }
1183
                        return null;
1184
                }
1185

    
1186
                /*
1187
                 * when no longer processing, time to load the new files
1188
                 */
1189
                @Override
1190
                protected void onPostExecute(Void arg1) {
1191
                        hideDialog();
1192
                        if(currentSelectedPath==null)
1193
                                removeFromList(currentPath);
1194
                        previousFiles=null;
1195
                        goUpDirectory();
1196
                }
1197
        }
1198

    
1199
        private class DeleteContainerListenerTask extends
1200
                        AsyncTask<Void, Void, Void> {
1201

    
1202
                @Override
1203
                protected Void doInBackground(Void... arg1) {
1204

    
1205
                        while (app.isDeletingContainer()) {
1206
                                // wait for process to finish
1207
                                // or have it be canceled
1208
                                if (deleteContainerTask.isCancelled()) {
1209
                                        return null;
1210
                                }
1211
                        }
1212
                        return null;
1213
                }
1214

    
1215
                /*
1216
                 * when no longer processing, time to load the new files
1217
                 */
1218
                @Override
1219
                protected void onPostExecute(Void arg1) {
1220

    
1221
                        hideDialog();
1222
                        setResult(RESULT_OK);
1223
                        finish();
1224
                }
1225
        }
1226

    
1227
        public String getCurrentPath() {
1228
                return currentPath;
1229
        }
1230

    
1231
        public ContainerObjects[] getFiles() {
1232
                return files;
1233
        }
1234
        
1235
        /***** UPLOAD FILE ****/
1236
        protected void uploadFile(String filename, Intent data){
1237
                if (filename.startsWith("file://")) {
1238
                        filename = filename.substring(7);
1239
                }
1240
                // replace %20 and so on
1241
                filename = Uri.decode(filename);
1242

    
1243
                int indx = filename.lastIndexOf("//");
1244
                File file = new File(data.getData().getPath());
1245
                String filenameNew = null;
1246
                Long fileSize = null;
1247
                if (!file.exists()) {
1248
                        Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null);
1249
                        if (cursor != null) {
1250
                                while (cursor.moveToNext()) {
1251
                                        for (int i = 0; i < cursor.getColumnCount(); i++) {
1252
                                                if (cursor.getColumnName(i).equals("_data"))
1253
                                                        filenameNew = cursor.getString(i);
1254
                                                if (cursor.getColumnName(i).equals("_size"))
1255
                                                        fileSize = cursor.getLong(i);
1256
                                        }
1257
                                }
1258
                        }
1259
                } else {
1260
                        filenameNew = data.getData().getPath();
1261
                }
1262
                if (filenameNew != null) {
1263
                        file = new File(filenameNew);
1264
                        String ext = MimeTypeMap.getSingleton().getFileExtensionFromUrl(file.getPath());
1265
                        String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
1266
                        String[] info = {
1267
                                        file.getName(),
1268
                                        mime, filenameNew};
1269
                        new AddFileTask().execute(info);
1270
                        //getTasks().getUploadTask(GssMyFolders.this).execute(getCurrentResource().getUri() + URLEncoder.encode(file.getName()), filenameNew);
1271
                }
1272
        }
1273
        
1274
        protected void uploadFile(List<Uri> uris){
1275
                List<String> strings = new ArrayList<String>();
1276
                String path = "";//getCurrentResource().getUri();
1277
                if(!path.endsWith("/"))
1278
                        path = path+"/";
1279
                
1280
                for(Uri data : uris){
1281
                        String filename = data.getPath();
1282
                        if (filename.startsWith("file://")) {
1283
                                filename = filename.substring(7);
1284
                        }
1285
                        // replace %20 and so on
1286
                        filename = Uri.decode(filename);
1287

    
1288
                        int indx = filename.lastIndexOf("//");
1289
                        File file = new File(filename);
1290
                        String filenameNew = null;
1291
                        Long fileSize = null;
1292
                        if (!file.exists()) {
1293
                                Cursor cursor = getContentResolver().query(data, null, null, null, null);
1294
                                if (cursor != null) {
1295
                                        while (cursor.moveToNext()) {
1296
                                                for (int i = 0; i < cursor.getColumnCount(); i++) {
1297
                                                        if (cursor.getColumnName(i).equals("_data"))
1298
                                                                filenameNew = cursor.getString(i);
1299
                                                        if (cursor.getColumnName(i).equals("_size"))
1300
                                                                fileSize = cursor.getLong(i);
1301
                                                }
1302
                                        }
1303
                                }
1304
                        } else {
1305
                                filenameNew = data.getPath();
1306
                        }
1307
                        if (filenameNew != null) {
1308
                                file = new File(filenameNew);
1309
                                strings.add(path+URLEncoder.encode(file.getName()));
1310
                                strings.add(filenameNew);
1311
                        }
1312
                }
1313
                Log.i("*******",""+strings.size());
1314
                //getTasks().getMultiUploadTask(this).execute(strings.toArray(new String[strings.size()]));
1315
                        
1316
                
1317
        }
1318
        protected void uploadFile(Uri data){
1319
                String filename = data.getPath();
1320
                if (filename.startsWith("file://")) {
1321
                        filename = filename.substring(7);
1322
                }
1323
                // replace %20 and so on
1324
                filename = Uri.decode(filename);
1325

    
1326
                int indx = filename.lastIndexOf("//");
1327
                File file = new File(filename);
1328
                String filenameNew = null;
1329
                Long fileSize = null;
1330
                if (!file.exists()) {
1331
                        Cursor cursor = getContentResolver().query(data, null, null, null, null);
1332
                        if (cursor != null) {
1333
                                while (cursor.moveToNext()) {
1334
                                        for (int i = 0; i < cursor.getColumnCount(); i++) {
1335
                                                if (cursor.getColumnName(i).equals("_data"))
1336
                                                        filenameNew = cursor.getString(i);
1337
                                                if (cursor.getColumnName(i).equals("_size"))
1338
                                                        fileSize = cursor.getLong(i);
1339
                                        }
1340
                                }
1341
                        }
1342
                } else {
1343
                        filenameNew = data.getPath();
1344
                }
1345
                if (filenameNew != null) {
1346
                        file = new File(filenameNew);
1347
                        //String path = getCurrentResource().getUri();
1348
                        //if(!path.endsWith("/"))
1349
                                //path = path+"/";
1350
                        //getTasks().getUploadTask(GssMyFolders.this).execute(path + URLEncoder.encode(file.getName()), filenameNew);
1351
                }
1352
                
1353
        }
1354
}