Statistics
| Branch: | Revision:

root / src / com / rackspace / cloud / android / ContainerObjectsActivity.java @ 378fe36a

History | View | Annotate | Download (39.5 kB)

1
package com.rackspace.cloud.android;
2

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

    
9
import org.apache.http.HttpResponse;
10

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

    
40
import com.rackspace.cloud.files.api.client.Container;
41
import com.rackspace.cloud.files.api.client.ContainerManager;
42
import com.rackspace.cloud.files.api.client.ContainerObjectManager;
43
import com.rackspace.cloud.files.api.client.ContainerObjects;
44
import com.rackspace.cloud.servers.api.client.Account;
45
import com.rackspace.cloud.servers.api.client.CloudServersException;
46
import com.rackspace.cloud.servers.api.client.http.HttpBundle;
47
import com.rackspace.cloud.servers.api.client.http.HttpBundleNoNetwork;
48
import com.rackspace.cloud.utils.Utils;
49

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

    
56
public class ContainerObjectsActivity extends CloudListActivity {
57

    
58
        private static final int deleteContainer = 0;
59
        private static final int deleteFolder = 1;
60
        private static final int deleteContext = 2;
61
        private static final int toTrashContext = 3;
62
        private static final int fromTrashContext = 4;
63
        private String currentSelectedPath = null;
64
        private ContainerObjects[] files;
65
        private static Container container;
66
        public String LOG = "viewFilesActivity";
67
        private String cdnEnabledIs;
68
        public Object megaBytes;
69
        public Object kiloBytes;
70
        public int bConver = 1048576;
71
        public int kbConver = 1024;
72
        private boolean loadingFiles;
73
        private String currentPath;
74
        private AndroidCloudApplication app;
75
        private AddObjectListenerTask task;
76
        private DeleteObjectListenerTask deleteObjTask;
77
        private DeleteContainerListenerTask deleteContainerTask;
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
                        Utils.execute(task);
152
                }
153

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

    
160
                if (app.isDeletingContainer()) {
161
                        displayNoFilesCell();
162
                        deleteContainerTask = new DeleteContainerListenerTask();
163
                        Utils.execute(deleteContainerTask);
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

    
204
        List<ContainerObjects> previousFiles = new ArrayList<ContainerObjects>();
205

    
206
        /*
207
         * go to the current directory's parent and display that data
208
         */
209
        private void goUpDirectory() {
210
                if (currentSelectedPath != null) {
211
                        currentSelectedPath = null;
212
                        loadFiles();
213
                        return;
214
                }
215
                currentPath = currentPath.substring(
216
                                0,
217
                                currentPath.substring(0, currentPath.length() - 2).lastIndexOf(
218
                                                "/") + 1);
219
                if (previousFiles != null && previousFiles.size() > 0) {
220
                        files = previousFiles.toArray(new ContainerObjects[] {});
221
                        previousFiles = null;
222
                        loadCurrentDirectoryFiles();
223
                        displayCurrentFiles();
224
                } else
225
                        loadFiles();
226
                // now executing new call
227

    
228
        }
229

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

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

    
256
        /*
257
         * determines if a file should be displayed in current directory
258
         */
259
        protected Boolean fileBelongsInDir(ContainerObjects obj) {
260
                /*
261
                 * String objPath = obj.getCName();
262
                 * 
263
                 * if (!objPath.startsWith(currentPath)) { Log.i(LOG, "Path is:" +
264
                 * currentPath + " " + objPath + " " + false); return false; } else {
265
                 * objPath = objPath.substring(currentPath.length()); Log.i(LOG,
266
                 * "Path is:" + currentPath + " " + objPath + " " +
267
                 * !objPath.contains("/")); return !objPath.contains("/"); }
268
                 */
269
                return true;
270
        }
271

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

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

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

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

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

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

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

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

    
405
        @Override
406
        public boolean onCreateOptionsMenu(Menu menu) {
407
                super.onCreateOptionsMenu(menu);
408
                MenuInflater inflater = getMenuInflater();
409
                inflater.inflate(R.menu.view_container_object_list_menu, menu);
410
                menu.findItem(R.id.enable_cdn).setVisible(false);
411
                if (Container.TRASH.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
                } else if (Container.MYSHARED.equalsIgnoreCase(container.getName())) {
416
                        menu.findItem(R.id.delete_container).setVisible(false);
417
                        menu.findItem(R.id.add_folder).setVisible(false);
418
                        menu.findItem(R.id.add_file).setVisible(false);
419
                }
420
                return true;
421
        }
422

    
423
        @Override
424
        public void onCreateContextMenu(ContextMenu menu, View v,
425
                        ContextMenuInfo menuInfo) {
426
                super.onCreateContextMenu(menu, v, menuInfo);
427
                MenuInflater inflater = getMenuInflater();
428
                inflater.inflate(R.menu.view_container_object_list_context, menu);
429
                menu.findItem(R.id.fromtrash_contextmenu).setVisible(false);
430
                if (Container.TRASH.equalsIgnoreCase(container.getName())) {
431
                        menu.findItem(R.id.delete_contextmenu).setVisible(true);
432
                        menu.findItem(R.id.totrash_contextmenu).setVisible(false);
433
                        menu.findItem(R.id.properties_contextmenu).setVisible(false);
434
                        menu.findItem(R.id.fromtrash_contextmenu).setVisible(true);
435
                } else if (Container.MYSHARED.equalsIgnoreCase(container.getName())) {
436
                        menu.findItem(R.id.delete_contextmenu).setVisible(false);
437
                        menu.findItem(R.id.totrash_contextmenu).setVisible(false);
438
                }
439
        }
440

    
441
        ContainerObjects currentSelectedObject = null;
442

    
443
        @Override
444
        public boolean onContextItemSelected(final MenuItem item) {
445
                final AdapterView.AdapterContextMenuInfo info;
446
                try {
447
                        info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
448
                } catch (ClassCastException e) {
449
                        Log.e(LOG, "bad menuInfo", e);
450
                        return false;
451
                }
452
                long id = getListAdapter().getItemId(info.position);
453
                final ContainerObjects obj = (ContainerObjects) getListAdapter()
454
                                .getItem(info.position);
455
                currentSelectedPath = obj.getCName() + "/";
456
                currentSelectedObject = obj;
457
                switch (item.getItemId()) {
458
                case R.id.delete_contextmenu:
459
                        showDialog(deleteContext);
460
                        return true;
461
                case R.id.totrash_contextmenu:
462
                        showDialog(toTrashContext);
463
                        return true;
464
                case R.id.fromtrash_contextmenu:
465
                        showDialog(fromTrashContext);
466
                        return true;
467
                case R.id.properties_contextmenu:
468
                        Intent viewIntent;
469
                        viewIntent = new Intent(this, ContainerObjectDetails.class);
470
                        viewIntent.putExtra("container", obj);
471
                        viewIntent.putExtra("cdnUrl", container.getCdnUrl());
472
                        if (container.getOtherUser() != null)
473
                                viewIntent.putExtra("otherUser", container.getOtherUser());
474
                        viewIntent.putExtra("containerNames", container.getName());
475
                        viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
476
                        startActivityForResult(viewIntent, 55);
477
                        return true;
478

    
479
                }
480
                currentSelectedPath = null;
481
                currentSelectedObject = null;
482
                return false;
483

    
484
        }
485

    
486
        @Override
487
        /*
488
         * option performed for delete depends on if you are at the top of a
489
         * container or in a folder
490
         */
491
        public boolean onOptionsItemSelected(MenuItem item) {
492
                switch (item.getItemId()) {
493
                case R.id.delete_container:
494
                        if (currentPath.equals("")) {
495
                                showDialog(deleteContainer);
496
                        } else {
497
                                showDialog(deleteFolder);
498
                        }
499
                        return true;
500
                case R.id.enable_cdn:
501
                        Intent viewIntent1 = new Intent(this, EnableCDNActivity.class);
502
                        viewIntent1.putExtra("Cname", container.getName());
503
                        startActivityForResult(viewIntent1, 56);
504
                        return true;
505
                case R.id.refresh:
506
                        loadFiles();
507
                        return true;
508
                case R.id.add_folder:
509
                        showDialog(R.id.add_folder);
510
                        return true;
511
                case R.id.add_file:
512
                        /*
513
                         * Intent viewIntent2 = new Intent(this, AddFileActivity.class);
514
                         * viewIntent2.putExtra("Cname", container.getName());
515
                         * viewIntent2.putExtra("curPath", currentPath);
516
                         * startActivityForResult(viewIntent2, 56);
517
                         */
518

    
519
                        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
520
                        intent.addCategory(Intent.CATEGORY_OPENABLE);
521
                        intent.setData(Uri.parse("file://"));
522
                        intent.setType("*/*");
523
                        try {
524
                                int i = 1;
525
                                startActivityForResult(intent, i);
526

    
527
                        } catch (ActivityNotFoundException e) {
528
                                Toast.makeText(this, "No File Manager", Toast.LENGTH_SHORT)
529
                                                .show();
530
                        }
531

    
532
                        return true;
533
                }
534
                return false;
535
        }
536

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

    
703
        @Override
704
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
705
                super.onActivityResult(requestCode, resultCode, data);
706

    
707
                if (resultCode == RESULT_OK && requestCode == 56) {
708
                        // a sub-activity kicked back, so we want to refresh the server list
709
                        previousFiles = null;
710
                        loadFiles();
711
                }
712

    
713
                if (resultCode == RESULT_OK && requestCode == 1) {
714
                        String filename = data.getDataString();
715
                        uploadFile(filename, data);
716

    
717
                }
718

    
719
                // deleted file so need to update the list
720
                if (requestCode == 55 && resultCode == 99) {
721
                        Log.d(LOG, "LOADING FROM DDELETE");
722
                        previousFiles = null;
723
                        loadFiles();
724
                }
725

    
726
        }
727

    
728
        class FileAdapter extends ArrayAdapter<ContainerObjects> {
729
                FileAdapter() {
730
                        super(ContainerObjectsActivity.this,
731
                                        R.layout.listcontainerobjectcell, app.getCurFiles());
732
                }
733

    
734
                public View getView(int position, View convertView, ViewGroup parent) {
735
                        ContainerObjects file = app.getCurFiles().get(position);
736
                        LayoutInflater inflater = getLayoutInflater();
737
                        View row = inflater.inflate(R.layout.listcontainerobjectcell,
738
                                        parent, false);
739

    
740
                        TextView label = (TextView) row.findViewById(R.id.label);
741
                        label.setText(getShortName(file.getCName()));
742

    
743
                        ImageView objectImage = (ImageView) row
744
                                        .findViewById(R.id.file_type_image);
745
                        if (file.isFolder()) {
746
                                objectImage.setImageResource(R.drawable.folder);
747
                        } else {
748
                                objectImage.setImageResource(R.drawable.file);
749
                        }
750

    
751
                        if (file.getBytes() >= bConver) {
752
                                megaBytes = Math.abs(file.getBytes() / bConver + 0.2);
753
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
754
                                sublabel.setText(megaBytes + " MB");
755
                        } else if (file.getBytes() >= kbConver) {
756
                                kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2);
757
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
758
                                sublabel.setText(kiloBytes + " KB");
759
                        } else {
760
                                TextView sublabel = (TextView) row.findViewById(R.id.sublabel);
761
                                if(file.getBytes()>0)
762
                                        sublabel.setText(file.getBytes() + " B");
763
                                else{
764
                                        sublabel.setText(" ");
765
                                }
766
                        }
767

    
768
                        return (row);
769
                }
770
        }
771

    
772
        private class LoadFilesTask extends
773
                        AsyncTask<String, Void, List<ContainerObjects>> {
774

    
775
                private CloudServersException exception;
776

    
777
                protected void onPreExecute() {
778
                        showDialog();
779
                        loadingFiles = true;
780
                }
781

    
782
                @Override
783
                protected List<ContainerObjects> doInBackground(String... path) {
784
                        List<ContainerObjects> files = null;
785
                        try {
786
                                if (container.getName().equals(Container.MYSHARED)) {
787
                                        files = (new ContainerObjectManager(getContext()))
788
                                                        .createListMyShared(container.getName(),
789
                                                                        new ContainerManager(getContext())
790
                                                                                        .createList(true), path[0]);
791
                                } else if (container.getName().equals(Container.OTHERS)) {
792

    
793
                                } else {
794
                                        if (container.getOtherUser() == null)
795
                                                files = (new ContainerObjectManager(getContext()))
796
                                                                .createList(container.getName(), path[0]);
797
                                        else
798
                                                files = (new ContainerObjectManager(getContext()))
799
                                                                .createOtherList(container.getName(),
800
                                                                                container.getOtherUser(), path[0]);
801
                                }
802
                        } catch (CloudServersException e) {
803
                                exception = e;
804
                                e.printStackTrace();
805
                        }
806
                        return files;
807
                }
808

    
809
                @Override
810
                protected void onPostExecute(List<ContainerObjects> result) {
811
                        loadingFiles = false;
812
                        hideDialog();
813
                        if (exception != null) {
814
                                showAlert("Error", exception.getMessage());
815
                        }
816
                        setFileList(result);
817
                        loadCurrentDirectoryFiles();
818
                        displayCurrentFiles();
819
                }
820

    
821
        }
822

    
823
        private class AddFolderTask extends AsyncTask<String, Void, HttpBundle> {
824

    
825
                private CloudServersException exception;
826

    
827
                @Override
828
                protected void onPreExecute() {
829
                        showDialog();
830
                        app.setAddingObject(true);
831
                        task = new AddObjectListenerTask();
832
                        Utils.execute(task);
833
                }
834

    
835
                @Override
836
                protected HttpBundle doInBackground(String... data) {
837
                        HttpBundle bundle = null;
838
                        try {
839

    
840
                                bundle = (new ContainerObjectManager(getContext())).addObject(
841
                                                container.getName(), currentPath, data[0], data[1],
842
                                                container.getOtherUser());
843
                        } catch (CloudServersException e) {
844
                                exception = e;
845
                        }
846
                        return bundle;
847
                }
848

    
849
                @Override
850
                protected void onPostExecute(HttpBundle bundle) {
851
                        app.setAddingObject(false);
852
                        hideDialog();
853
                        HttpResponse response = bundle.getResponse();
854
                        if (response != null) {
855
                                int statusCode = response.getStatusLine().getStatusCode();
856
                                if (statusCode == 201) {
857
                                        setResult(Activity.RESULT_OK);
858
                                        // loading the new files is done by ListenerTask
859
                                } else {
860
                                        CloudServersException cse = parseCloudServersException(response);
861
                                        if ("".equals(cse.getMessage())) {
862
                                                showError("There was a problem deleting your folder.",
863
                                                                bundle);
864
                                        } else {
865
                                                showError("There was a problem deleting your folder: "
866
                                                                + cse.getMessage(), bundle);
867
                                        }
868
                                }
869
                        } else if (exception != null) {
870
                                showError("There was a problem deleting your folder: "
871
                                                + exception.getMessage(), bundle);
872
                        }
873
                }
874
        }
875

    
876
        private class AddFileTask extends AsyncTask<String, Void, HttpBundle> {
877

    
878
                private CloudServersException exception;
879

    
880
                @Override
881
                protected void onPreExecute() {
882
                        showDialog();
883
                        app.setAddingObject(true);
884
                        task = new AddObjectListenerTask();
885
                        Utils.execute(task);
886
                }
887

    
888
                @Override
889
                protected HttpBundle doInBackground(String... data) {
890
                        HttpBundle bundle = null;
891
                        try {
892

    
893
                                bundle = (new ContainerObjectManager(getContext()))
894
                                                .addFileObject(container.getName(), currentPath,
895
                                                                data[0], data[1], data[2],
896
                                                                container.getOtherUser());
897
                        } catch (CloudServersException e) {
898
                                exception = e;
899
                        }
900
                        return bundle;
901
                }
902

    
903
                @Override
904
                protected void onPostExecute(HttpBundle bundle) {
905
                        app.setAddingObject(false);
906
                        hideDialog();
907
                        HttpResponse response = bundle.getResponse();
908
                        if (response != null) {
909
                                int statusCode = response.getStatusLine().getStatusCode();
910
                                if (statusCode == 201) {
911
                                        setResult(Activity.RESULT_OK);
912
                                        // loading the new files is done by ListenerTask
913
                                } else {
914
                                        CloudServersException cse = parseCloudServersException(response);
915
                                        if ("".equals(cse.getMessage())) {
916
                                                showError("There was a problem adding your file.",
917
                                                                bundle);
918
                                        } else {
919
                                                showError("There was a problem adding your file: "
920
                                                                + cse.getMessage(), bundle);
921
                                        }
922
                                }
923
                        } else if (exception != null) {
924
                                showError(
925
                                                "There was a problem adding your file: "
926
                                                                + exception.getMessage(), bundle);
927
                        }
928
                }
929
        }
930

    
931
        private class DeleteObjectTask extends AsyncTask<String, Void, HttpBundle> {
932

    
933
                private CloudServersException exception;
934
                public boolean isInFile = false;
935

    
936
                @Override
937
                protected void onPreExecute() {
938
                        showDialog();
939
                        app.setDeleteingObject(true);
940
                        deleteObjTask = new DeleteObjectListenerTask();
941
                        Utils.execute(deleteObjTask);
942
                }
943

    
944
                @Override
945
                protected HttpBundle doInBackground(String... args) {
946
                        HttpBundle bundle = null;
947
                        try {
948
                                // subtring because the current directory contains a "/" at the
949
                                // end of the string
950
                                String cname = args[0];
951
                                String cpath = args[1];
952
                                bundle = (new ContainerObjectManager(getContext()))
953
                                                .deleteObject(cname,
954
                                                                cpath.substring(0, cpath.length() - 1),
955
                                                                container.getOtherUser());
956
                        } catch (CloudServersException e) {
957
                                exception = e;
958
                        }
959
                        return bundle;
960
                }
961

    
962
                @Override
963
                protected void onPostExecute(HttpBundle bundle) {
964
                        app.setDeleteingObject(false);
965
                        hideDialog();
966
                        HttpResponse response = bundle.getResponse();
967
                        if (response != null) {
968
                                int statusCode = response.getStatusLine().getStatusCode();
969
                                if (statusCode == 409) {
970
                                        showAlert("Error",
971
                                                        "Folder must be empty in order to delete");
972
                                }
973
                                if (statusCode == 204) {
974
                                        setResult(Activity.RESULT_OK);
975
                                } else {
976
                                        CloudServersException cse = parseCloudServersException(response);
977
                                        if ("".equals(cse.getMessage())) {
978
                                                showError("There was a problem deleting your folder.",
979
                                                                bundle);
980
                                        } else {
981
                                                showError("There was a problem deleting your folder: "
982
                                                                + cse.getMessage(), bundle);
983
                                        }
984
                                }
985
                        } else if (exception != null) {
986
                                showError("There was a problem deleting your folder: "
987
                                                + exception.getMessage(), bundle);
988
                        }
989
                }
990
        }
991

    
992
        private class TrashObjectTask extends AsyncTask<String, Void, HttpBundle> {
993

    
994
                private CloudServersException exception;
995
                public boolean isInFile = false;
996
                String[] arguments;
997

    
998
                @Override
999
                protected void onPreExecute() {
1000
                        showDialog();
1001

    
1002
                }
1003

    
1004
                @Override
1005
                protected HttpBundle doInBackground(String... args) {
1006
                        HttpBundle bundle = null;
1007
                        arguments = args;
1008
                        try {
1009
                                // subtring because the current directory contains a "/" at the
1010
                                // end of the string
1011
                                String cname = args[0];
1012
                                String cpath = args[1];
1013
                                bundle = (new ContainerObjectManager(getContext()))
1014
                                                .trashObject(cname,
1015
                                                                cpath.substring(0, cpath.length() - 1));
1016
                        } catch (CloudServersException e) {
1017
                                exception = e;
1018
                        }
1019
                        return bundle;
1020
                }
1021

    
1022
                @Override
1023
                protected void onPostExecute(HttpBundle bundle) {
1024
                        hideDialog();
1025
                        HttpResponse response = bundle.getResponse();
1026
                        if (response != null) {
1027
                                int statusCode = response.getStatusLine().getStatusCode();
1028
                                if (statusCode == 409) {
1029
                                        showAlert("Error",
1030
                                                        "Folder must be empty in order to delete");
1031
                                }
1032
                                if (statusCode == 201) {
1033
                                        new DeleteObjectTask().execute(arguments);
1034
                                } else {
1035
                                        CloudServersException cse = parseCloudServersException(response);
1036
                                        if ("".equals(cse.getMessage())) {
1037
                                                showError("There was a problem trashing your folder.",
1038
                                                                bundle);
1039
                                        } else {
1040
                                                showError("There was a problem trashing your folder: "
1041
                                                                + cse.getMessage(), bundle);
1042
                                        }
1043
                                }
1044
                        } else if (exception != null) {
1045
                                showError("There was a problem trashing your folder: "
1046
                                                + exception.getMessage(), bundle);
1047
                        }
1048
                }
1049
        }
1050

    
1051
        private class RestoreTrashObjectTask extends
1052
                        AsyncTask<String, Void, HttpBundle> {
1053

    
1054
                private CloudServersException exception;
1055
                public boolean isInFile = false;
1056
                String[] arguments;
1057

    
1058
                @Override
1059
                protected void onPreExecute() {
1060
                        showDialog();
1061

    
1062
                }
1063

    
1064
                @Override
1065
                protected HttpBundle doInBackground(String... args) {
1066
                        HttpBundle bundle = null;
1067
                        arguments = args;
1068
                        try {
1069
                                // subtring because the current directory contains a "/" at the
1070
                                // end of the string
1071
                                String cname = args[0];
1072
                                String cpath = args[1];
1073
                                bundle = (new ContainerObjectManager(getContext()))
1074
                                                .restoreObject(cname,
1075
                                                                cpath.substring(0, cpath.length() - 1));
1076
                        } catch (CloudServersException e) {
1077
                                exception = e;
1078
                        }
1079
                        return bundle;
1080
                }
1081

    
1082
                @Override
1083
                protected void onPostExecute(HttpBundle bundle) {
1084
                        hideDialog();
1085
                        HttpResponse response = bundle.getResponse();
1086
                        if (response != null) {
1087
                                int statusCode = response.getStatusLine().getStatusCode();
1088
                                if (statusCode == 409) {
1089
                                        showAlert("Error",
1090
                                                        "Folder must be empty in order to delete");
1091
                                }
1092
                                if (statusCode == 201) {
1093
                                        new DeleteObjectTask().execute(arguments);
1094
                                } else {
1095
                                        CloudServersException cse = parseCloudServersException(response);
1096
                                        if ("".equals(cse.getMessage())) {
1097
                                                showError("There was a problem restoring your folder.",
1098
                                                                bundle);
1099
                                        } else {
1100
                                                showError("There was a problem restoring your folder: "
1101
                                                                + cse.getMessage(), bundle);
1102
                                        }
1103
                                }
1104
                        } else if (exception != null) {
1105
                                showError("There was a problem restoring your folder: "
1106
                                                + exception.getMessage(), bundle);
1107
                        }
1108
                }
1109
        }
1110

    
1111
        private class DeleteContainerTask extends
1112
                        AsyncTask<String, Void, Pair<Integer, Throwable>> {
1113

    
1114
                private CloudServersException exception;
1115

    
1116
                @Override
1117
                protected void onPreExecute() {
1118
                        showDialog();
1119
                        app.setDeletingContainer(true);
1120
                        deleteContainerTask = new DeleteContainerListenerTask();
1121
                        Utils.execute(task);
1122
                }
1123

    
1124
                @Override
1125
                protected Pair<Integer, Throwable> doInBackground(String... object) {
1126
                        HttpBundle bundle = null;
1127
                        try {
1128
                                bundle = (new ContainerManager(getContext())).delete(container
1129
                                                .getName());
1130
                                HttpResponse response = bundle.getResponse();
1131

    
1132
                                if (response != null) {
1133
                                        int statusCode = response.getStatusLine().getStatusCode();
1134
                                        if (statusCode == 409 || statusCode == 204) {
1135
                                                return new Pair<Integer, Throwable>(statusCode, null);
1136
                                        }
1137
                                        return new Pair<Integer, Throwable>(-1,
1138
                                                        parseCloudServersException(response));
1139
                                }
1140
                                return new Pair<Integer, Throwable>(-1, null);
1141
                        } catch (CloudServersException e) {
1142
                                exception = e;
1143
                                return new Pair<Integer, Throwable>(-1, e);
1144
                        }
1145

    
1146
                }
1147

    
1148
                @Override
1149
                protected void onPostExecute(Pair<Integer, Throwable> bundle) {
1150
                        hideDialog();
1151
                        app.setDeletingContainer(false);
1152
                        int statusCode = bundle.first;
1153
                        if (statusCode == 409) {
1154
                                showError("Container must be empty in order to delete", null);
1155
                        } else if (statusCode == 204) {
1156
                                setResult(Activity.RESULT_OK);
1157
                        } else {
1158
                                Throwable e = bundle.second;
1159
                                if (e instanceof CloudServersException) {
1160
                                        CloudServersException cse = (CloudServersException) e;
1161
                                        if ("".equals(cse.getMessage())) {
1162
                                                showError(
1163
                                                                "There was a problem deleting your container.",
1164
                                                                null);
1165
                                        } else {
1166
                                                showError(
1167
                                                                "There was a problem deleting your container: "
1168
                                                                                + cse.getMessage(), null);
1169
                                        }
1170
                                } else if (e != null) {
1171
                                        showError(
1172
                                                        "There was a problem deleting your server: "
1173
                                                                        + e.getMessage(), null);
1174
                                }
1175
                        }
1176
                }
1177
        }
1178

    
1179
        /*
1180
         * listens for the application to change isProcessing listens so activity
1181
         * knows when it should display the new curDirFiles
1182
         */
1183
        private class AddObjectListenerTask extends AsyncTask<Void, Void, Void> {
1184

    
1185
                @Override
1186
                protected Void doInBackground(Void... arg1) {
1187

    
1188
                        while (app.isAddingObject()) {
1189
                                // wait for process to finish
1190
                                // or have it be canceled
1191
                                if (task.isCancelled()) {
1192
                                        return null;
1193
                                }
1194
                        }
1195
                        return null;
1196
                }
1197

    
1198
                /*
1199
                 * when no longer processing, time to load the new files
1200
                 */
1201
                @Override
1202
                protected void onPostExecute(Void arg1) {
1203
                        hideDialog();
1204
                        loadFiles();
1205
                }
1206
        }
1207

    
1208
        private class DeleteObjectListenerTask extends AsyncTask<Void, Void, Void> {
1209

    
1210
                @Override
1211
                protected Void doInBackground(Void... arg1) {
1212

    
1213
                        while (app.isDeletingObject()) {
1214
                                // wait for process to finish
1215
                                // or have it be canceled
1216
                                if (deleteObjTask.isCancelled()) {
1217
                                        return null;
1218
                                }
1219
                        }
1220
                        return null;
1221
                }
1222

    
1223
                /*
1224
                 * when no longer processing, time to load the new files
1225
                 */
1226
                @Override
1227
                protected void onPostExecute(Void arg1) {
1228
                        hideDialog();
1229
                        if (currentSelectedPath == null)
1230
                                removeFromList(currentPath);
1231
                        previousFiles = null;
1232
                        goUpDirectory();
1233
                }
1234
        }
1235

    
1236
        private class DeleteContainerListenerTask extends
1237
                        AsyncTask<Void, Void, Void> {
1238

    
1239
                @Override
1240
                protected Void doInBackground(Void... arg1) {
1241

    
1242
                        while (app.isDeletingContainer()) {
1243
                                // wait for process to finish
1244
                                // or have it be canceled
1245
                                if (deleteContainerTask.isCancelled()) {
1246
                                        return null;
1247
                                }
1248
                        }
1249
                        return null;
1250
                }
1251

    
1252
                /*
1253
                 * when no longer processing, time to load the new files
1254
                 */
1255
                @Override
1256
                protected void onPostExecute(Void arg1) {
1257

    
1258
                        hideDialog();
1259
                        setResult(RESULT_OK);
1260
                        finish();
1261
                }
1262
        }
1263

    
1264
        public String getCurrentPath() {
1265
                return currentPath;
1266
        }
1267

    
1268
        public ContainerObjects[] getFiles() {
1269
                return files;
1270
        }
1271

    
1272
        /***** UPLOAD FILE ****/
1273
        protected void uploadFile(String filename, Intent data) {
1274
                if (filename.startsWith("file://")) {
1275
                        filename = filename.substring(7);
1276
                }
1277
                // replace %20 and so on
1278
                filename = Uri.decode(filename);
1279

    
1280
                int indx = filename.lastIndexOf("//");
1281
                File file = new File(data.getData().getPath());
1282
                String filenameNew = null;
1283
                Long fileSize = null;
1284
                if (!file.exists()) {
1285
                        Cursor cursor = getContentResolver().query(data.getData(), null,
1286
                                        null, null, null);
1287
                        if (cursor != null) {
1288
                                while (cursor.moveToNext()) {
1289
                                        for (int i = 0; i < cursor.getColumnCount(); i++) {
1290
                                                if (cursor.getColumnName(i).equals("_data"))
1291
                                                        filenameNew = cursor.getString(i);
1292
                                                if (cursor.getColumnName(i).equals("_size"))
1293
                                                        fileSize = cursor.getLong(i);
1294
                                        }
1295
                                }
1296
                        }
1297
                } else {
1298
                        filenameNew = data.getData().getPath();
1299
                }
1300
                if (filenameNew != null) {
1301
                        file = new File(filenameNew);
1302
                        String ext = MimeTypeMap.getSingleton().getFileExtensionFromUrl(
1303
                                        file.getPath());
1304
                        String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
1305
                                        ext);
1306
                        String[] info = { file.getName(), mime, filenameNew };
1307
                        new AddFileTask().execute(info);
1308
                        // getTasks().getUploadTask(GssMyFolders.this).execute(getCurrentResource().getUri()
1309
                        // + URLEncoder.encode(file.getName()), filenameNew);
1310
                }
1311
        }
1312

    
1313
        protected void uploadFile(List<Uri> uris) {
1314
                List<String> strings = new ArrayList<String>();
1315
                String path = "";// getCurrentResource().getUri();
1316
                if (!path.endsWith("/"))
1317
                        path = path + "/";
1318

    
1319
                for (Uri data : uris) {
1320
                        String filename = data.getPath();
1321
                        if (filename.startsWith("file://")) {
1322
                                filename = filename.substring(7);
1323
                        }
1324
                        // replace %20 and so on
1325
                        filename = Uri.decode(filename);
1326

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

    
1357
        }
1358

    
1359
        protected void uploadFile(Uri data) {
1360
                String filename = data.getPath();
1361
                if (filename.startsWith("file://")) {
1362
                        filename = filename.substring(7);
1363
                }
1364
                // replace %20 and so on
1365
                filename = Uri.decode(filename);
1366

    
1367
                int indx = filename.lastIndexOf("//");
1368
                File file = new File(filename);
1369
                String filenameNew = null;
1370
                Long fileSize = null;
1371
                if (!file.exists()) {
1372
                        Cursor cursor = getContentResolver().query(data, null, null, null,
1373
                                        null);
1374
                        if (cursor != null) {
1375
                                while (cursor.moveToNext()) {
1376
                                        for (int i = 0; i < cursor.getColumnCount(); i++) {
1377
                                                if (cursor.getColumnName(i).equals("_data"))
1378
                                                        filenameNew = cursor.getString(i);
1379
                                                if (cursor.getColumnName(i).equals("_size"))
1380
                                                        fileSize = cursor.getLong(i);
1381
                                        }
1382
                                }
1383
                        }
1384
                } else {
1385
                        filenameNew = data.getPath();
1386
                }
1387
                if (filenameNew != null) {
1388
                        file = new File(filenameNew);
1389
                        // String path = getCurrentResource().getUri();
1390
                        // if(!path.endsWith("/"))
1391
                        // path = path+"/";
1392
                        // getTasks().getUploadTask(GssMyFolders.this).execute(path +
1393
                        // URLEncoder.encode(file.getName()), filenameNew);
1394
                }
1395

    
1396
        }
1397
}