root / src / com / rackspace / cloud / android / ContainerObjectsActivity.java @ 94abc2c7
History | View | Annotate | Download (38.5 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.servers.api.client.CloudServersException; |
46 |
import com.rackspace.cloud.servers.api.client.http.HttpBundle; |
47 |
|
48 |
/**
|
49 |
*
|
50 |
* @author Phillip Toohill
|
51 |
*
|
52 |
*/
|
53 |
|
54 |
public class ContainerObjectsActivity extends CloudListActivity { |
55 |
|
56 |
private static final int deleteContainer = 0; |
57 |
private static final int deleteFolder = 1; |
58 |
private static final int deleteContext = 2; |
59 |
private static final int toTrashContext = 3; |
60 |
private static final int fromTrashContext = 4; |
61 |
private String currentSelectedPath=null; |
62 |
private ContainerObjects[] files; |
63 |
private static Container container; |
64 |
public String LOG = "viewFilesActivity"; |
65 |
private String cdnEnabledIs; |
66 |
public Object megaBytes; |
67 |
public Object kiloBytes; |
68 |
public int bConver = 1048576; |
69 |
public int kbConver = 1024; |
70 |
private boolean loadingFiles; |
71 |
private String currentPath; |
72 |
private AndroidCloudApplication app;
|
73 |
private AddObjectListenerTask task;
|
74 |
private DeleteObjectListenerTask deleteObjTask;
|
75 |
private DeleteContainerListenerTask deleteContainerTask;
|
76 |
|
77 |
|
78 |
@Override
|
79 |
public void onCreate(Bundle savedInstanceState) { |
80 |
super.onCreate(savedInstanceState);
|
81 |
trackPageView(GoogleAnalytics.PAGE_FOLDER); |
82 |
container = getContainer(); |
83 |
if (container.isCdnEnabled() == true) { |
84 |
cdnEnabledIs = "true";
|
85 |
} else {
|
86 |
cdnEnabledIs = "false";
|
87 |
} |
88 |
|
89 |
restoreState(savedInstanceState); |
90 |
} |
91 |
|
92 |
protected Container getContainer() { |
93 |
return (Container) this.getIntent().getExtras().get("container"); |
94 |
} |
95 |
|
96 |
@Override
|
97 |
protected void onSaveInstanceState(Bundle outState) { |
98 |
super.onSaveInstanceState(outState);
|
99 |
|
100 |
// files stores all the files in the container
|
101 |
outState.putSerializable("container", files);
|
102 |
|
103 |
// current path represents where you have "navigated" to
|
104 |
outState.putString("path", currentPath);
|
105 |
|
106 |
outState.putBoolean("loadingFiles", loadingFiles);
|
107 |
} |
108 |
|
109 |
protected void restoreState(Bundle state) { |
110 |
super.restoreState(state);
|
111 |
|
112 |
/*
|
113 |
* need reference to the app so you can access curDirFiles as well as
|
114 |
* processing status
|
115 |
*/
|
116 |
app = (AndroidCloudApplication) this.getApplication();
|
117 |
|
118 |
if (state != null) { |
119 |
if (state.containsKey("path")) { |
120 |
currentPath = state.getString("path");
|
121 |
} else {
|
122 |
currentPath = "";
|
123 |
} |
124 |
|
125 |
if (state.containsKey("loadingFiles") |
126 |
&& state.getBoolean("loadingFiles")) {
|
127 |
loadFiles(); |
128 |
} else if (state.containsKey("container")) { |
129 |
files = (ContainerObjects[]) state.getSerializable("container"); |
130 |
if (app.getCurFiles() == null || app.getCurFiles().size() == 0) { |
131 |
displayNoFilesCell(); |
132 |
} else {
|
133 |
getListView().setDividerHeight(1); // restore divider lines |
134 |
setListAdapter(new FileAdapter());
|
135 |
|
136 |
} |
137 |
|
138 |
} |
139 |
} else {
|
140 |
currentPath = "";
|
141 |
loadFiles(); |
142 |
} |
143 |
|
144 |
/*
|
145 |
* if the app is process when we enter the activity we must listen for
|
146 |
* the new curDirFiles list
|
147 |
*/
|
148 |
if (app.isAddingObject()) {
|
149 |
task = new AddObjectListenerTask();
|
150 |
task.execute(); |
151 |
} |
152 |
|
153 |
if (app.isDeletingObject()) {
|
154 |
displayNoFilesCell(); |
155 |
deleteObjTask = new DeleteObjectListenerTask();
|
156 |
deleteObjTask.execute(); |
157 |
} |
158 |
|
159 |
if (app.isDeletingContainer()) {
|
160 |
displayNoFilesCell(); |
161 |
deleteContainerTask = new DeleteContainerListenerTask();
|
162 |
deleteContainerTask.execute(); |
163 |
} |
164 |
|
165 |
} |
166 |
|
167 |
@Override
|
168 |
protected void onStop() { |
169 |
super.onStop();
|
170 |
|
171 |
/*
|
172 |
* Need to stop running listener task if we exit
|
173 |
*/
|
174 |
if (task != null) { |
175 |
task.cancel(true);
|
176 |
} |
177 |
|
178 |
if (deleteObjTask != null) { |
179 |
deleteObjTask.cancel(true);
|
180 |
} |
181 |
|
182 |
if (deleteContainerTask != null) { |
183 |
deleteContainerTask.cancel(true);
|
184 |
} |
185 |
|
186 |
} |
187 |
|
188 |
/*
|
189 |
* overriding back button press, because we are not actually changing
|
190 |
* activities when we navigate the file structure
|
191 |
*/
|
192 |
public void onBackPressed() { |
193 |
|
194 |
if (currentPath.equals("")) { |
195 |
if(container.getName().equals(Container.MYSHARED)){} |
196 |
else
|
197 |
finish(); |
198 |
} else {
|
199 |
goUpDirectory(); |
200 |
} |
201 |
} |
202 |
List<ContainerObjects> previousFiles = new ArrayList<ContainerObjects>(); |
203 |
/*
|
204 |
* go to the current directory's parent and display that data
|
205 |
*/
|
206 |
private void goUpDirectory() { |
207 |
if(currentSelectedPath != null){ |
208 |
currentSelectedPath=null;
|
209 |
loadFiles(); |
210 |
return;
|
211 |
} |
212 |
currentPath = currentPath.substring( |
213 |
0,
|
214 |
currentPath.substring(0, currentPath.length() - 2).lastIndexOf( |
215 |
"/") + 1); |
216 |
if(previousFiles!=null&&previousFiles.size()>0){ |
217 |
files = previousFiles.toArray(new ContainerObjects[]{}); |
218 |
previousFiles=null;
|
219 |
loadCurrentDirectoryFiles(); |
220 |
displayCurrentFiles(); |
221 |
} |
222 |
else
|
223 |
loadFiles(); |
224 |
//now executing new call
|
225 |
|
226 |
} |
227 |
|
228 |
/*
|
229 |
* load all file that are in the container
|
230 |
*/
|
231 |
private void loadFiles() { |
232 |
// displayLoadingCell();
|
233 |
new LoadFilesTask().execute(currentPath);
|
234 |
} |
235 |
|
236 |
/*
|
237 |
* load only the files that should display for the current directory in the
|
238 |
* curDirFiles[]
|
239 |
*/
|
240 |
protected void loadCurrentDirectoryFiles() { |
241 |
ArrayList<ContainerObjects> curFiles = new ArrayList<ContainerObjects>(); |
242 |
Log.i(LOG, "loading files");
|
243 |
if (files != null) { |
244 |
for (int i = 0; i < files.length; i++) { |
245 |
Log.i(LOG, "loading files" + i);
|
246 |
if (fileBelongsInDir(files[i])) {
|
247 |
curFiles.add(files[i]); |
248 |
} |
249 |
} |
250 |
app.setCurFiles(curFiles); |
251 |
} |
252 |
} |
253 |
|
254 |
/*
|
255 |
* determines if a file should be displayed in current directory
|
256 |
*/
|
257 |
protected Boolean fileBelongsInDir(ContainerObjects obj) { |
258 |
/*String objPath = obj.getCName();
|
259 |
|
260 |
if (!objPath.startsWith(currentPath)) {
|
261 |
Log.i(LOG, "Path is:" + currentPath + " " + objPath + " " + false);
|
262 |
return false;
|
263 |
} else {
|
264 |
objPath = objPath.substring(currentPath.length());
|
265 |
Log.i(LOG, "Path is:" + currentPath + " " + objPath + " "
|
266 |
+ !objPath.contains("/"));
|
267 |
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 |
setTitle(container.getOtherUser()+":"+container.getName()+"/"+currentPath); |
297 |
if (app.getCurFiles().size() == 0) { |
298 |
displayNoFilesCell(); |
299 |
} else {
|
300 |
ArrayList<ContainerObjects> tempList = new ArrayList<ContainerObjects>(); |
301 |
for (int i = 0; i < app.getCurFiles().size(); i++) { |
302 |
tempList.add(app.getCurFiles().get(i)); |
303 |
} |
304 |
getListView().setDividerHeight(1); // restore divider lines |
305 |
setListAdapter(new FileAdapter());
|
306 |
} |
307 |
} |
308 |
|
309 |
/*
|
310 |
* display a different empty page depending of if you are at top of
|
311 |
* container or in a folder
|
312 |
*/
|
313 |
protected void displayNoFilesCell() { |
314 |
String a[] = new String[1]; |
315 |
if (currentPath.equals("")) { |
316 |
a[0] = "Empty Container"; |
317 |
setListAdapter(new ArrayAdapter<String>(this, |
318 |
R.layout.noobjectscell, R.id.no_files_label, a)); |
319 |
} else {
|
320 |
a[0] = "No Files"; |
321 |
setListAdapter(new ArrayAdapter<String>(this, R.layout.nofilescell, |
322 |
R.id.no_files_label, a)); |
323 |
} |
324 |
getListView().setTextFilterEnabled(true);
|
325 |
getListView().setDividerHeight(0); // hide the dividers so it won't look |
326 |
// like a list row
|
327 |
getListView().setItemsCanFocus(false);
|
328 |
} |
329 |
|
330 |
/*
|
331 |
* just get the last part of the filename so the entire file path does not
|
332 |
* show
|
333 |
*/
|
334 |
private String getShortName(String longName) { |
335 |
String s = longName;
|
336 |
if (!s.contains("/")) { |
337 |
return s;
|
338 |
} else {
|
339 |
String tmp = s.substring(s.lastIndexOf('/') + 1); |
340 |
if (tmp.equals("")) { |
341 |
return s;
|
342 |
} |
343 |
return tmp;
|
344 |
} |
345 |
} |
346 |
|
347 |
/*
|
348 |
* removed a specified object from the array of all the files in the
|
349 |
* container
|
350 |
*/
|
351 |
private void removeFromList(String path) { |
352 |
ArrayList<ContainerObjects> temp = new ArrayList<ContainerObjects>( |
353 |
Arrays.asList(files));
|
354 |
for (int i = 0; i < files.length; i++) { |
355 |
if (files[i].getCName()
|
356 |
.equals(path.substring(0, path.length() - 1))) { |
357 |
temp.remove(i); |
358 |
} |
359 |
} |
360 |
files = new ContainerObjects[temp.size()];
|
361 |
for (int i = 0; i < temp.size(); i++) { |
362 |
files[i] = temp.get(i); |
363 |
} |
364 |
} |
365 |
|
366 |
protected void onListItemClick(ListView l, View v, int position, long id) { |
367 |
if (app.getCurFiles() != null && app.getCurFiles().size() > 0) { |
368 |
Intent viewIntent; |
369 |
if (app.getCurFiles().get(position).isFolder()) {
|
370 |
currentPath = app.getCurFiles().get(position).getCName() + "/";
|
371 |
/*if(container.getName().equalsIgnoreCase(Container.MYSHARED)){
|
372 |
loadCurrentDirectoryFiles();
|
373 |
displayCurrentFiles();
|
374 |
}
|
375 |
else{*/
|
376 |
previousFiles = Arrays.asList(files);
|
377 |
loadFiles(); |
378 |
//}
|
379 |
//loadCurrentDirectoryFiles();
|
380 |
//displayCurrentFiles();
|
381 |
} |
382 |
|
383 |
else {
|
384 |
viewIntent = new Intent(this, ContainerObjectDetails.class); |
385 |
viewIntent.putExtra("container", app.getCurFiles()
|
386 |
.get(position)); |
387 |
viewIntent.putExtra("cdnUrl", container.getCdnUrl());
|
388 |
if(container.getOtherUser()!=null) |
389 |
viewIntent.putExtra("otherUser", container.getOtherUser());
|
390 |
viewIntent.putExtra("containerNames", container.getName());
|
391 |
viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
|
392 |
startActivityForResult(viewIntent, 55); // arbitrary number; |
393 |
// never
|
394 |
// used again
|
395 |
} |
396 |
} |
397 |
} |
398 |
|
399 |
@Override
|
400 |
public boolean onCreateOptionsMenu(Menu menu) { |
401 |
super.onCreateOptionsMenu(menu);
|
402 |
MenuInflater inflater = getMenuInflater(); |
403 |
inflater.inflate(R.menu.view_container_object_list_menu, menu); |
404 |
menu.findItem(R.id.enable_cdn).setVisible(false);
|
405 |
if(Container.TRASH.equalsIgnoreCase(container.getName())){ |
406 |
menu.findItem(R.id.delete_container).setVisible(false);
|
407 |
menu.findItem(R.id.add_folder).setVisible(false);
|
408 |
menu.findItem(R.id.add_file).setVisible(false);
|
409 |
} |
410 |
else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){ |
411 |
menu.findItem(R.id.delete_container).setVisible(false);
|
412 |
menu.findItem(R.id.add_folder).setVisible(false);
|
413 |
menu.findItem(R.id.add_file).setVisible(false);
|
414 |
} |
415 |
return true; |
416 |
} |
417 |
@Override
|
418 |
public void onCreateContextMenu(ContextMenu menu, View v, |
419 |
ContextMenuInfo menuInfo) { |
420 |
super.onCreateContextMenu(menu, v, menuInfo);
|
421 |
MenuInflater inflater = getMenuInflater(); |
422 |
inflater.inflate(R.menu.view_container_object_list_context, menu); |
423 |
menu.findItem(R.id.fromtrash_contextmenu).setVisible(false);
|
424 |
if(Container.TRASH.equalsIgnoreCase(container.getName())){ |
425 |
menu.findItem(R.id.delete_contextmenu).setVisible(true);
|
426 |
menu.findItem(R.id.totrash_contextmenu).setVisible(false);
|
427 |
menu.findItem(R.id.properties_contextmenu).setVisible(false);
|
428 |
menu.findItem(R.id.fromtrash_contextmenu).setVisible(true);
|
429 |
} |
430 |
else if(Container.MYSHARED.equalsIgnoreCase(container.getName())){ |
431 |
menu.findItem(R.id.delete_contextmenu).setVisible(false);
|
432 |
menu.findItem(R.id.totrash_contextmenu).setVisible(false);
|
433 |
} |
434 |
} |
435 |
ContainerObjects currentSelectedObject=null;
|
436 |
@Override
|
437 |
public boolean onContextItemSelected(final MenuItem item) { |
438 |
final AdapterView.AdapterContextMenuInfo info;
|
439 |
try {
|
440 |
info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); |
441 |
} catch (ClassCastException e) { |
442 |
Log.e(LOG, "bad menuInfo", e);
|
443 |
return false; |
444 |
} |
445 |
long id = getListAdapter().getItemId(info.position);
|
446 |
final ContainerObjects obj = (ContainerObjects) getListAdapter().getItem(info.position);
|
447 |
currentSelectedPath = obj.getCName() + "/";
|
448 |
currentSelectedObject=obj; |
449 |
switch (item.getItemId()) {
|
450 |
case R.id.delete_contextmenu:
|
451 |
showDialog(deleteContext); |
452 |
return true; |
453 |
case R.id.totrash_contextmenu:
|
454 |
showDialog(toTrashContext); |
455 |
return true; |
456 |
case R.id.fromtrash_contextmenu:
|
457 |
showDialog(fromTrashContext); |
458 |
return true; |
459 |
case R.id.properties_contextmenu:
|
460 |
Intent viewIntent; |
461 |
viewIntent = new Intent(this, ContainerObjectDetails.class); |
462 |
viewIntent.putExtra("container", obj);
|
463 |
viewIntent.putExtra("cdnUrl", container.getCdnUrl());
|
464 |
if(container.getOtherUser()!=null) |
465 |
viewIntent.putExtra("otherUser", container.getOtherUser());
|
466 |
viewIntent.putExtra("containerNames", container.getName());
|
467 |
viewIntent.putExtra("isCdnEnabled", cdnEnabledIs);
|
468 |
startActivityForResult(viewIntent, 55);
|
469 |
return true; |
470 |
|
471 |
} |
472 |
currentSelectedPath=null;
|
473 |
currentSelectedObject=null;
|
474 |
return false; |
475 |
|
476 |
} |
477 |
@Override
|
478 |
/*
|
479 |
* option performed for delete depends on if you are at the top of a
|
480 |
* container or in a folder
|
481 |
*/
|
482 |
public boolean onOptionsItemSelected(MenuItem item) { |
483 |
switch (item.getItemId()) {
|
484 |
case R.id.delete_container:
|
485 |
if (currentPath.equals("")) { |
486 |
showDialog(deleteContainer); |
487 |
} else {
|
488 |
showDialog(deleteFolder); |
489 |
} |
490 |
return true; |
491 |
case R.id.enable_cdn:
|
492 |
Intent viewIntent1 = new Intent(this, EnableCDNActivity.class); |
493 |
viewIntent1.putExtra("Cname", container.getName());
|
494 |
startActivityForResult(viewIntent1, 56);
|
495 |
return true; |
496 |
case R.id.refresh:
|
497 |
loadFiles(); |
498 |
return true; |
499 |
case R.id.add_folder:
|
500 |
showDialog(R.id.add_folder); |
501 |
return true; |
502 |
case R.id.add_file:
|
503 |
/*
|
504 |
* Intent viewIntent2 = new Intent(this, AddFileActivity.class);
|
505 |
* viewIntent2.putExtra("Cname", container.getName());
|
506 |
* viewIntent2.putExtra("curPath", currentPath);
|
507 |
* startActivityForResult(viewIntent2, 56);
|
508 |
*/
|
509 |
|
510 |
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
|
511 |
intent.addCategory(Intent.CATEGORY_OPENABLE); |
512 |
intent.setData(Uri.parse("file://"));
|
513 |
intent.setType("*/*");
|
514 |
try {
|
515 |
int i = 1; |
516 |
startActivityForResult(intent, i); |
517 |
|
518 |
} catch (ActivityNotFoundException e) {
|
519 |
Toast.makeText(this, "No File Manager", Toast.LENGTH_SHORT) |
520 |
.show(); |
521 |
} |
522 |
|
523 |
return true; |
524 |
} |
525 |
return false; |
526 |
} |
527 |
|
528 |
@Override
|
529 |
protected Dialog onCreateDialog(int id) { |
530 |
switch (id) {
|
531 |
case deleteContainer:
|
532 |
if (app.getCurFiles().size() == 0) { |
533 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
534 |
.setIcon(R.drawable.alert_dialog_icon) |
535 |
.setTitle("Delete Container")
|
536 |
.setMessage( |
537 |
"Are you sure you want to delete this Container?")
|
538 |
.setPositiveButton("Delete Container",
|
539 |
new DialogInterface.OnClickListener() {
|
540 |
public void onClick(DialogInterface dialog, |
541 |
int whichButton) {
|
542 |
// User clicked OK so do some stuff
|
543 |
trackEvent( |
544 |
GoogleAnalytics.CATEGORY_CONTAINER, |
545 |
GoogleAnalytics.EVENT_DELETE, |
546 |
"", -1); |
547 |
new DeleteContainerTask()
|
548 |
.execute(currentPath); |
549 |
} |
550 |
}) |
551 |
.setNegativeButton("Cancel",
|
552 |
new DialogInterface.OnClickListener() {
|
553 |
public void onClick(DialogInterface dialog, |
554 |
int whichButton) {
|
555 |
// User clicked Cancel so do some stuff
|
556 |
} |
557 |
}).create(); |
558 |
} else {
|
559 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
560 |
.setIcon(R.drawable.alert_dialog_icon) |
561 |
.setTitle("Delete Container")
|
562 |
.setMessage("Container must be empty to delete")
|
563 |
.setNegativeButton("OK",
|
564 |
new DialogInterface.OnClickListener() {
|
565 |
public void onClick(DialogInterface dialog, |
566 |
int whichButton) {
|
567 |
// User clicked Cancel so do some stuff
|
568 |
} |
569 |
}).create(); |
570 |
} |
571 |
case deleteFolder:
|
572 |
if (app.getCurFiles().size() == 0) { |
573 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
574 |
.setIcon(R.drawable.alert_dialog_icon) |
575 |
.setTitle("Delete Folder")
|
576 |
.setMessage( |
577 |
"Are you sure you want to delete this Folder?")
|
578 |
.setPositiveButton("Delete Folder",
|
579 |
new DialogInterface.OnClickListener() {
|
580 |
public void onClick(DialogInterface dialog, |
581 |
int whichButton) {
|
582 |
// User clicked OK so do some stuff
|
583 |
new DeleteObjectTask().execute(container.getName(), currentPath);
|
584 |
} |
585 |
}) |
586 |
.setNegativeButton("Cancel",
|
587 |
new DialogInterface.OnClickListener() {
|
588 |
public void onClick(DialogInterface dialog, |
589 |
int whichButton) {
|
590 |
// User clicked Cancel so do some stuff
|
591 |
} |
592 |
}).create(); |
593 |
} |
594 |
case deleteContext:
|
595 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
596 |
.setIcon(R.drawable.alert_dialog_icon) |
597 |
.setTitle("Delete Object")
|
598 |
.setMessage( |
599 |
"Are you sure you want to delete this Object?")
|
600 |
.setPositiveButton("Delete Object",
|
601 |
new DialogInterface.OnClickListener() {
|
602 |
public void onClick(DialogInterface dialog, |
603 |
int whichButton) {
|
604 |
// User clicked OK so do some stuff
|
605 |
new DeleteObjectTask().execute(container.getName(), currentSelectedPath);
|
606 |
} |
607 |
}) |
608 |
.setNegativeButton("Cancel",
|
609 |
new DialogInterface.OnClickListener() {
|
610 |
public void onClick(DialogInterface dialog, |
611 |
int whichButton) {
|
612 |
currentSelectedPath=null;
|
613 |
// User clicked Cancel so do some stuff
|
614 |
} |
615 |
}).create(); |
616 |
case toTrashContext:
|
617 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
618 |
.setIcon(R.drawable.alert_dialog_icon) |
619 |
.setTitle("Move Object To Trash")
|
620 |
.setMessage( |
621 |
"Are you sure you want to trash this Object?")
|
622 |
.setPositiveButton("Trash Object",
|
623 |
new DialogInterface.OnClickListener() {
|
624 |
public void onClick(DialogInterface dialog, |
625 |
int whichButton) {
|
626 |
// User clicked OK so do some stuff
|
627 |
new TrashObjectTask().execute(container.getName(), currentSelectedPath);
|
628 |
} |
629 |
}) |
630 |
.setNegativeButton("Cancel",
|
631 |
new DialogInterface.OnClickListener() {
|
632 |
public void onClick(DialogInterface dialog, |
633 |
int whichButton) {
|
634 |
currentSelectedPath=null;
|
635 |
// User clicked Cancel so do some stuff
|
636 |
} |
637 |
}).create(); |
638 |
case fromTrashContext:
|
639 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
640 |
.setIcon(R.drawable.alert_dialog_icon) |
641 |
.setTitle("Restore Object To Pithos")
|
642 |
.setMessage( |
643 |
"Are you sure you want to restore this Object?")
|
644 |
.setPositiveButton("Restore Object",
|
645 |
new DialogInterface.OnClickListener() {
|
646 |
public void onClick(DialogInterface dialog, |
647 |
int whichButton) {
|
648 |
// User clicked OK so do some stuff
|
649 |
new RestoreTrashObjectTask().execute(container.getName(), currentSelectedPath);
|
650 |
} |
651 |
}) |
652 |
.setNegativeButton("Cancel",
|
653 |
new DialogInterface.OnClickListener() {
|
654 |
public void onClick(DialogInterface dialog, |
655 |
int whichButton) {
|
656 |
currentSelectedPath=null;
|
657 |
// User clicked Cancel so do some stuff
|
658 |
} |
659 |
}).create(); |
660 |
case R.id.add_folder:
|
661 |
final EditText input = new EditText(this); |
662 |
return new AlertDialog.Builder(ContainerObjectsActivity.this) |
663 |
.setIcon(R.drawable.alert_dialog_icon) |
664 |
.setView(input) |
665 |
.setTitle("Add Folder")
|
666 |
.setMessage("Enter new name for folder: ")
|
667 |
.setPositiveButton("Add",
|
668 |
new DialogInterface.OnClickListener() {
|
669 |
public void onClick(DialogInterface dialog, |
670 |
int whichButton) {
|
671 |
// User clicked OK so do some stuff
|
672 |
String[] info = { |
673 |
input.getText().toString(), |
674 |
"application/directory" };
|
675 |
new AddFolderTask().execute(info);
|
676 |
} |
677 |
}) |
678 |
.setNegativeButton("Cancel",
|
679 |
new DialogInterface.OnClickListener() {
|
680 |
public void onClick(DialogInterface dialog, |
681 |
int whichButton) {
|
682 |
// User clicked Cancel so do some stuff
|
683 |
} |
684 |
}).create(); |
685 |
} |
686 |
return null; |
687 |
} |
688 |
|
689 |
@Override
|
690 |
public void onActivityResult(int requestCode, int resultCode, Intent data) { |
691 |
super.onActivityResult(requestCode, resultCode, data);
|
692 |
|
693 |
if (resultCode == RESULT_OK && requestCode == 56) { |
694 |
// a sub-activity kicked back, so we want to refresh the server list
|
695 |
previousFiles = null;
|
696 |
loadFiles(); |
697 |
} |
698 |
|
699 |
if (resultCode == RESULT_OK && requestCode == 1) { |
700 |
String filename = data.getDataString();
|
701 |
uploadFile(filename, data); |
702 |
|
703 |
} |
704 |
|
705 |
// deleted file so need to update the list
|
706 |
if (requestCode == 55 && resultCode == 99) { |
707 |
Log.d(LOG,"LOADING FROM DDELETE");
|
708 |
previousFiles = null;
|
709 |
loadFiles(); |
710 |
} |
711 |
|
712 |
} |
713 |
|
714 |
class FileAdapter extends ArrayAdapter<ContainerObjects> { |
715 |
FileAdapter() { |
716 |
super(ContainerObjectsActivity.this,
|
717 |
R.layout.listcontainerobjectcell, app.getCurFiles()); |
718 |
} |
719 |
|
720 |
public View getView(int position, View convertView, ViewGroup parent) { |
721 |
ContainerObjects file = app.getCurFiles().get(position); |
722 |
LayoutInflater inflater = getLayoutInflater(); |
723 |
View row = inflater.inflate(R.layout.listcontainerobjectcell,
|
724 |
parent, false);
|
725 |
|
726 |
TextView label = (TextView) row.findViewById(R.id.label); |
727 |
label.setText(getShortName(file.getCName())); |
728 |
|
729 |
ImageView objectImage = (ImageView) row |
730 |
.findViewById(R.id.file_type_image); |
731 |
if (file.isFolder()) {
|
732 |
objectImage.setImageResource(R.drawable.folder); |
733 |
} else {
|
734 |
objectImage.setImageResource(R.drawable.file); |
735 |
} |
736 |
|
737 |
if (file.getBytes() >= bConver) {
|
738 |
megaBytes = Math.abs(file.getBytes() / bConver + 0.2); |
739 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
740 |
sublabel.setText(megaBytes + " MB");
|
741 |
} else if (file.getBytes() >= kbConver) { |
742 |
kiloBytes = Math.abs(file.getBytes() / kbConver + 0.2); |
743 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
744 |
sublabel.setText(kiloBytes + " KB");
|
745 |
} else {
|
746 |
TextView sublabel = (TextView) row.findViewById(R.id.sublabel); |
747 |
sublabel.setText(file.getBytes() + " B");
|
748 |
} |
749 |
|
750 |
return (row);
|
751 |
} |
752 |
} |
753 |
|
754 |
private class LoadFilesTask extends |
755 |
AsyncTask<String, Void, List<ContainerObjects>> { |
756 |
|
757 |
private CloudServersException exception;
|
758 |
|
759 |
protected void onPreExecute() { |
760 |
showDialog(); |
761 |
loadingFiles = true;
|
762 |
} |
763 |
|
764 |
@Override
|
765 |
protected List<ContainerObjects> doInBackground(String... path) { |
766 |
List<ContainerObjects> files = null; |
767 |
try {
|
768 |
if (container.getName().equals(Container.MYSHARED)) { |
769 |
files = (new ContainerObjectManager(getContext()))
|
770 |
.createListMyShared( container.getName(), |
771 |
new ContainerManager(getContext())
|
772 |
.createList(true),path[0]); |
773 |
} else if (container.getName().equals(Container.OTHERS)) { |
774 |
|
775 |
} else {
|
776 |
if (container.getOtherUser() == null) |
777 |
files = (new ContainerObjectManager(getContext()))
|
778 |
.createList(container.getName(), path[0]);
|
779 |
else
|
780 |
files = (new ContainerObjectManager(getContext()))
|
781 |
.createOtherList(container.getName(), container.getOtherUser(),path[0]);
|
782 |
} |
783 |
} catch (CloudServersException e) {
|
784 |
exception = e; |
785 |
e.printStackTrace(); |
786 |
} |
787 |
return files;
|
788 |
} |
789 |
|
790 |
@Override
|
791 |
protected void onPostExecute(List<ContainerObjects> result) { |
792 |
loadingFiles = false;
|
793 |
hideDialog(); |
794 |
if (exception != null) { |
795 |
showAlert("Error", exception.getMessage());
|
796 |
} |
797 |
setFileList(result); |
798 |
loadCurrentDirectoryFiles(); |
799 |
displayCurrentFiles(); |
800 |
} |
801 |
|
802 |
} |
803 |
|
804 |
private class AddFolderTask extends AsyncTask<String, Void, HttpBundle> { |
805 |
|
806 |
private CloudServersException exception;
|
807 |
|
808 |
@Override
|
809 |
protected void onPreExecute() { |
810 |
showDialog(); |
811 |
app.setAddingObject(true);
|
812 |
task = new AddObjectListenerTask();
|
813 |
task.execute(); |
814 |
} |
815 |
|
816 |
@Override
|
817 |
protected HttpBundle doInBackground(String... data) { |
818 |
HttpBundle bundle = null;
|
819 |
try {
|
820 |
|
821 |
bundle = (new ContainerObjectManager(getContext())).addObject(
|
822 |
container.getName(), currentPath, data[0], data[1]); |
823 |
} catch (CloudServersException e) {
|
824 |
exception = e; |
825 |
} |
826 |
return bundle;
|
827 |
} |
828 |
|
829 |
@Override
|
830 |
protected void onPostExecute(HttpBundle bundle) { |
831 |
app.setAddingObject(false);
|
832 |
hideDialog(); |
833 |
HttpResponse response = bundle.getResponse(); |
834 |
if (response != null) { |
835 |
int statusCode = response.getStatusLine().getStatusCode();
|
836 |
if (statusCode == 201) { |
837 |
setResult(Activity.RESULT_OK); |
838 |
// loading the new files is done by ListenerTask
|
839 |
} else {
|
840 |
CloudServersException cse = parseCloudServersException(response); |
841 |
if ("".equals(cse.getMessage())) { |
842 |
showError("There was a problem deleting your folder.",
|
843 |
bundle); |
844 |
} else {
|
845 |
showError("There was a problem deleting your folder: "
|
846 |
+ cse.getMessage(), bundle); |
847 |
} |
848 |
} |
849 |
} else if (exception != null) { |
850 |
showError("There was a problem deleting your folder: "
|
851 |
+ exception.getMessage(), bundle); |
852 |
} |
853 |
} |
854 |
} |
855 |
|
856 |
private class AddFileTask extends AsyncTask<String, Void, HttpBundle> { |
857 |
|
858 |
private CloudServersException exception;
|
859 |
|
860 |
@Override
|
861 |
protected void onPreExecute() { |
862 |
showDialog(); |
863 |
app.setAddingObject(true);
|
864 |
task = new AddObjectListenerTask();
|
865 |
task.execute(); |
866 |
} |
867 |
|
868 |
@Override
|
869 |
protected HttpBundle doInBackground(String... data) { |
870 |
HttpBundle bundle = null;
|
871 |
try {
|
872 |
|
873 |
bundle = (new ContainerObjectManager(getContext())).addFileObject(
|
874 |
container.getName(), currentPath, data[0], data[1], data[2]); |
875 |
} catch (CloudServersException e) {
|
876 |
exception = e; |
877 |
} |
878 |
return bundle;
|
879 |
} |
880 |
|
881 |
@Override
|
882 |
protected void onPostExecute(HttpBundle bundle) { |
883 |
app.setAddingObject(false);
|
884 |
hideDialog(); |
885 |
HttpResponse response = bundle.getResponse(); |
886 |
if (response != null) { |
887 |
int statusCode = response.getStatusLine().getStatusCode();
|
888 |
if (statusCode == 201) { |
889 |
setResult(Activity.RESULT_OK); |
890 |
// loading the new files is done by ListenerTask
|
891 |
} else {
|
892 |
CloudServersException cse = parseCloudServersException(response); |
893 |
if ("".equals(cse.getMessage())) { |
894 |
showError("There was a problem deleting your folder.",
|
895 |
bundle); |
896 |
} else {
|
897 |
showError("There was a problem deleting your folder: "
|
898 |
+ cse.getMessage(), bundle); |
899 |
} |
900 |
} |
901 |
} else if (exception != null) { |
902 |
showError("There was a problem deleting your folder: "
|
903 |
+ exception.getMessage(), bundle); |
904 |
} |
905 |
} |
906 |
} |
907 |
|
908 |
private class DeleteObjectTask extends AsyncTask<String, Void, HttpBundle> { |
909 |
|
910 |
private CloudServersException exception;
|
911 |
public boolean isInFile=false; |
912 |
@Override
|
913 |
protected void onPreExecute() { |
914 |
showDialog(); |
915 |
app.setDeleteingObject(true);
|
916 |
deleteObjTask = new DeleteObjectListenerTask();
|
917 |
deleteObjTask.execute(); |
918 |
} |
919 |
|
920 |
@Override
|
921 |
protected HttpBundle doInBackground(String... args) { |
922 |
HttpBundle bundle = null;
|
923 |
try {
|
924 |
// subtring because the current directory contains a "/" at the
|
925 |
// end of the string
|
926 |
String cname = args[0]; |
927 |
String cpath = args[1]; |
928 |
bundle = (new ContainerObjectManager(getContext()))
|
929 |
.deleteObject(cname, cpath |
930 |
.substring(0, cpath.length() - 1)); |
931 |
} catch (CloudServersException e) {
|
932 |
exception = e; |
933 |
} |
934 |
return bundle;
|
935 |
} |
936 |
|
937 |
@Override
|
938 |
protected void onPostExecute(HttpBundle bundle) { |
939 |
app.setDeleteingObject(false);
|
940 |
hideDialog(); |
941 |
HttpResponse response = bundle.getResponse(); |
942 |
if (response != null) { |
943 |
int statusCode = response.getStatusLine().getStatusCode();
|
944 |
if (statusCode == 409) { |
945 |
showAlert("Error",
|
946 |
"Folder must be empty in order to delete");
|
947 |
} |
948 |
if (statusCode == 204) { |
949 |
setResult(Activity.RESULT_OK); |
950 |
} else {
|
951 |
CloudServersException cse = parseCloudServersException(response); |
952 |
if ("".equals(cse.getMessage())) { |
953 |
showError("There was a problem deleting your folder.",
|
954 |
bundle); |
955 |
} else {
|
956 |
showError("There was a problem deleting your folder: "
|
957 |
+ cse.getMessage(), bundle); |
958 |
} |
959 |
} |
960 |
} else if (exception != null) { |
961 |
showError("There was a problem deleting your folder: "
|
962 |
+ exception.getMessage(), bundle); |
963 |
} |
964 |
} |
965 |
} |
966 |
|
967 |
private class TrashObjectTask extends AsyncTask<String, Void, HttpBundle> { |
968 |
|
969 |
private CloudServersException exception;
|
970 |
public boolean isInFile=false; |
971 |
String[] arguments; |
972 |
@Override
|
973 |
protected void onPreExecute() { |
974 |
showDialog(); |
975 |
|
976 |
} |
977 |
|
978 |
@Override
|
979 |
protected HttpBundle doInBackground(String... args) { |
980 |
HttpBundle bundle = null;
|
981 |
arguments = args; |
982 |
try {
|
983 |
// subtring because the current directory contains a "/" at the
|
984 |
// end of the string
|
985 |
String cname = args[0]; |
986 |
String cpath = args[1]; |
987 |
bundle = (new ContainerObjectManager(getContext()))
|
988 |
.trashObject(cname, cpath |
989 |
.substring(0, cpath.length() - 1)); |
990 |
} catch (CloudServersException e) {
|
991 |
exception = e; |
992 |
} |
993 |
return bundle;
|
994 |
} |
995 |
|
996 |
@Override
|
997 |
protected void onPostExecute(HttpBundle bundle) { |
998 |
hideDialog(); |
999 |
HttpResponse response = bundle.getResponse(); |
1000 |
if (response != null) { |
1001 |
int statusCode = response.getStatusLine().getStatusCode();
|
1002 |
if (statusCode == 409) { |
1003 |
showAlert("Error",
|
1004 |
"Folder must be empty in order to delete");
|
1005 |
} |
1006 |
if (statusCode == 201) { |
1007 |
new DeleteObjectTask().execute(arguments);
|
1008 |
} else {
|
1009 |
CloudServersException cse = parseCloudServersException(response); |
1010 |
if ("".equals(cse.getMessage())) { |
1011 |
showError("There was a problem deleting your folder.",
|
1012 |
bundle); |
1013 |
} else {
|
1014 |
showError("There was a problem deleting your folder: "
|
1015 |
+ cse.getMessage(), bundle); |
1016 |
} |
1017 |
} |
1018 |
} else if (exception != null) { |
1019 |
showError("There was a problem deleting your folder: "
|
1020 |
+ exception.getMessage(), bundle); |
1021 |
} |
1022 |
} |
1023 |
} |
1024 |
|
1025 |
private class RestoreTrashObjectTask extends AsyncTask<String, Void, HttpBundle> { |
1026 |
|
1027 |
private CloudServersException exception;
|
1028 |
public boolean isInFile=false; |
1029 |
String[] arguments; |
1030 |
@Override
|
1031 |
protected void onPreExecute() { |
1032 |
showDialog(); |
1033 |
|
1034 |
} |
1035 |
|
1036 |
@Override
|
1037 |
protected HttpBundle doInBackground(String... args) { |
1038 |
HttpBundle bundle = null;
|
1039 |
arguments = args; |
1040 |
try {
|
1041 |
// subtring because the current directory contains a "/" at the
|
1042 |
// end of the string
|
1043 |
String cname = args[0]; |
1044 |
String cpath = args[1]; |
1045 |
bundle = (new ContainerObjectManager(getContext()))
|
1046 |
.restoreObject(cname, cpath |
1047 |
.substring(0, cpath.length() - 1)); |
1048 |
} catch (CloudServersException e) {
|
1049 |
exception = e; |
1050 |
} |
1051 |
return bundle;
|
1052 |
} |
1053 |
|
1054 |
@Override
|
1055 |
protected void onPostExecute(HttpBundle bundle) { |
1056 |
hideDialog(); |
1057 |
HttpResponse response = bundle.getResponse(); |
1058 |
if (response != null) { |
1059 |
int statusCode = response.getStatusLine().getStatusCode();
|
1060 |
if (statusCode == 409) { |
1061 |
showAlert("Error",
|
1062 |
"Folder must be empty in order to delete");
|
1063 |
} |
1064 |
if (statusCode == 201) { |
1065 |
new DeleteObjectTask().execute(arguments);
|
1066 |
} else {
|
1067 |
CloudServersException cse = parseCloudServersException(response); |
1068 |
if ("".equals(cse.getMessage())) { |
1069 |
showError("There was a problem deleting your folder.",
|
1070 |
bundle); |
1071 |
} else {
|
1072 |
showError("There was a problem deleting your folder: "
|
1073 |
+ cse.getMessage(), bundle); |
1074 |
} |
1075 |
} |
1076 |
} else if (exception != null) { |
1077 |
showError("There was a problem deleting your folder: "
|
1078 |
+ exception.getMessage(), bundle); |
1079 |
} |
1080 |
} |
1081 |
} |
1082 |
|
1083 |
private class DeleteContainerTask extends |
1084 |
AsyncTask<String, Void, HttpBundle> { |
1085 |
|
1086 |
private CloudServersException exception;
|
1087 |
|
1088 |
@Override
|
1089 |
protected void onPreExecute() { |
1090 |
showDialog(); |
1091 |
app.setDeletingContainer(true);
|
1092 |
deleteContainerTask = new DeleteContainerListenerTask();
|
1093 |
deleteContainerTask.execute(); |
1094 |
} |
1095 |
|
1096 |
@Override
|
1097 |
protected HttpBundle doInBackground(String... object) { |
1098 |
HttpBundle bundle = null;
|
1099 |
try {
|
1100 |
bundle = (new ContainerManager(getContext())).delete(container
|
1101 |
.getName()); |
1102 |
} catch (CloudServersException e) {
|
1103 |
exception = e; |
1104 |
} |
1105 |
return bundle;
|
1106 |
} |
1107 |
|
1108 |
@Override
|
1109 |
protected void onPostExecute(HttpBundle bundle) { |
1110 |
hideDialog(); |
1111 |
app.setDeletingContainer(false);
|
1112 |
HttpResponse response = bundle.getResponse(); |
1113 |
if (response != null) { |
1114 |
int statusCode = response.getStatusLine().getStatusCode();
|
1115 |
if (statusCode == 409) { |
1116 |
showError("Container must be empty in order to delete",
|
1117 |
bundle); |
1118 |
} |
1119 |
if (statusCode == 204) { |
1120 |
setResult(Activity.RESULT_OK); |
1121 |
|
1122 |
} else {
|
1123 |
CloudServersException cse = parseCloudServersException(response); |
1124 |
if ("".equals(cse.getMessage())) { |
1125 |
showError( |
1126 |
"There was a problem deleting your container.",
|
1127 |
bundle); |
1128 |
} else {
|
1129 |
showError( |
1130 |
"There was a problem deleting your container: "
|
1131 |
+ cse.getMessage(), bundle); |
1132 |
} |
1133 |
} |
1134 |
} else if (exception != null) { |
1135 |
showError("There was a problem deleting your server: "
|
1136 |
+ exception.getMessage(), bundle); |
1137 |
} |
1138 |
} |
1139 |
} |
1140 |
|
1141 |
/*
|
1142 |
* listens for the application to change isProcessing listens so activity
|
1143 |
* knows when it should display the new curDirFiles
|
1144 |
*/
|
1145 |
private class AddObjectListenerTask extends AsyncTask<Void, Void, Void> { |
1146 |
|
1147 |
@Override
|
1148 |
protected Void doInBackground(Void... arg1) { |
1149 |
|
1150 |
while (app.isAddingObject()) {
|
1151 |
// wait for process to finish
|
1152 |
// or have it be canceled
|
1153 |
if (task.isCancelled()) {
|
1154 |
return null; |
1155 |
} |
1156 |
} |
1157 |
return null; |
1158 |
} |
1159 |
|
1160 |
/*
|
1161 |
* when no longer processing, time to load the new files
|
1162 |
*/
|
1163 |
@Override
|
1164 |
protected void onPostExecute(Void arg1) { |
1165 |
hideDialog(); |
1166 |
loadFiles(); |
1167 |
} |
1168 |
} |
1169 |
|
1170 |
private class DeleteObjectListenerTask extends AsyncTask<Void, Void, Void> { |
1171 |
|
1172 |
@Override
|
1173 |
protected Void doInBackground(Void... arg1) { |
1174 |
|
1175 |
while (app.isDeletingObject()) {
|
1176 |
// wait for process to finish
|
1177 |
// or have it be canceled
|
1178 |
if (deleteObjTask.isCancelled()) {
|
1179 |
return null; |
1180 |
} |
1181 |
} |
1182 |
return null; |
1183 |
} |
1184 |
|
1185 |
/*
|
1186 |
* when no longer processing, time to load the new files
|
1187 |
*/
|
1188 |
@Override
|
1189 |
protected void onPostExecute(Void arg1) { |
1190 |
hideDialog(); |
1191 |
if(currentSelectedPath==null) |
1192 |
removeFromList(currentPath); |
1193 |
previousFiles=null;
|
1194 |
goUpDirectory(); |
1195 |
} |
1196 |
} |
1197 |
|
1198 |
private class DeleteContainerListenerTask extends |
1199 |
AsyncTask<Void, Void, Void> { |
1200 |
|
1201 |
@Override
|
1202 |
protected Void doInBackground(Void... arg1) { |
1203 |
|
1204 |
while (app.isDeletingContainer()) {
|
1205 |
// wait for process to finish
|
1206 |
// or have it be canceled
|
1207 |
if (deleteContainerTask.isCancelled()) {
|
1208 |
return null; |
1209 |
} |
1210 |
} |
1211 |
return null; |
1212 |
} |
1213 |
|
1214 |
/*
|
1215 |
* when no longer processing, time to load the new files
|
1216 |
*/
|
1217 |
@Override
|
1218 |
protected void onPostExecute(Void arg1) { |
1219 |
|
1220 |
hideDialog(); |
1221 |
setResult(RESULT_OK); |
1222 |
finish(); |
1223 |
} |
1224 |
} |
1225 |
|
1226 |
public String getCurrentPath() { |
1227 |
return currentPath;
|
1228 |
} |
1229 |
|
1230 |
public ContainerObjects[] getFiles() { |
1231 |
return files;
|
1232 |
} |
1233 |
|
1234 |
/***** UPLOAD FILE ****/
|
1235 |
protected void uploadFile(String filename, Intent data){ |
1236 |
if (filename.startsWith("file://")) { |
1237 |
filename = filename.substring(7);
|
1238 |
} |
1239 |
// replace %20 and so on
|
1240 |
filename = Uri.decode(filename); |
1241 |
|
1242 |
int indx = filename.lastIndexOf("//"); |
1243 |
File file = new File(data.getData().getPath()); |
1244 |
String filenameNew = null; |
1245 |
Long fileSize = null; |
1246 |
if (!file.exists()) {
|
1247 |
Cursor cursor = getContentResolver().query(data.getData(), null, null, null, null); |
1248 |
if (cursor != null) { |
1249 |
while (cursor.moveToNext()) {
|
1250 |
for (int i = 0; i < cursor.getColumnCount(); i++) { |
1251 |
if (cursor.getColumnName(i).equals("_data")) |
1252 |
filenameNew = cursor.getString(i); |
1253 |
if (cursor.getColumnName(i).equals("_size")) |
1254 |
fileSize = cursor.getLong(i); |
1255 |
} |
1256 |
} |
1257 |
} |
1258 |
} else {
|
1259 |
filenameNew = data.getData().getPath(); |
1260 |
} |
1261 |
if (filenameNew != null) { |
1262 |
file = new File(filenameNew); |
1263 |
String ext = MimeTypeMap.getSingleton().getFileExtensionFromUrl(file.getPath());
|
1264 |
String mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
|
1265 |
String[] info = { |
1266 |
file.getName(), |
1267 |
mime, filenameNew}; |
1268 |
new AddFileTask().execute(info);
|
1269 |
//getTasks().getUploadTask(GssMyFolders.this).execute(getCurrentResource().getUri() + URLEncoder.encode(file.getName()), filenameNew);
|
1270 |
} |
1271 |
} |
1272 |
|
1273 |
protected void uploadFile(List<Uri> uris){ |
1274 |
List<String> strings = new ArrayList<String>(); |
1275 |
String path = "";//getCurrentResource().getUri(); |
1276 |
if(!path.endsWith("/")) |
1277 |
path = path+"/";
|
1278 |
|
1279 |
for(Uri data : uris){
|
1280 |
String filename = data.getPath();
|
1281 |
if (filename.startsWith("file://")) { |
1282 |
filename = filename.substring(7);
|
1283 |
} |
1284 |
// replace %20 and so on
|
1285 |
filename = Uri.decode(filename); |
1286 |
|
1287 |
int indx = filename.lastIndexOf("//"); |
1288 |
File file = new File(filename); |
1289 |
String filenameNew = null; |
1290 |
Long fileSize = null; |
1291 |
if (!file.exists()) {
|
1292 |
Cursor cursor = getContentResolver().query(data, null, null, null, null); |
1293 |
if (cursor != null) { |
1294 |
while (cursor.moveToNext()) {
|
1295 |
for (int i = 0; i < cursor.getColumnCount(); i++) { |
1296 |
if (cursor.getColumnName(i).equals("_data")) |
1297 |
filenameNew = cursor.getString(i); |
1298 |
if (cursor.getColumnName(i).equals("_size")) |
1299 |
fileSize = cursor.getLong(i); |
1300 |
} |
1301 |
} |
1302 |
} |
1303 |
} else {
|
1304 |
filenameNew = data.getPath(); |
1305 |
} |
1306 |
if (filenameNew != null) { |
1307 |
file = new File(filenameNew); |
1308 |
strings.add(path+URLEncoder.encode(file.getName()));
|
1309 |
strings.add(filenameNew); |
1310 |
} |
1311 |
} |
1312 |
Log.i("*******",""+strings.size()); |
1313 |
//getTasks().getMultiUploadTask(this).execute(strings.toArray(new String[strings.size()]));
|
1314 |
|
1315 |
|
1316 |
} |
1317 |
protected void uploadFile(Uri data){ |
1318 |
String filename = data.getPath();
|
1319 |
if (filename.startsWith("file://")) { |
1320 |
filename = filename.substring(7);
|
1321 |
} |
1322 |
// replace %20 and so on
|
1323 |
filename = Uri.decode(filename); |
1324 |
|
1325 |
int indx = filename.lastIndexOf("//"); |
1326 |
File file = new File(filename); |
1327 |
String filenameNew = null; |
1328 |
Long fileSize = null; |
1329 |
if (!file.exists()) {
|
1330 |
Cursor cursor = getContentResolver().query(data, null, null, null, null); |
1331 |
if (cursor != null) { |
1332 |
while (cursor.moveToNext()) {
|
1333 |
for (int i = 0; i < cursor.getColumnCount(); i++) { |
1334 |
if (cursor.getColumnName(i).equals("_data")) |
1335 |
filenameNew = cursor.getString(i); |
1336 |
if (cursor.getColumnName(i).equals("_size")) |
1337 |
fileSize = cursor.getLong(i); |
1338 |
} |
1339 |
} |
1340 |
} |
1341 |
} else {
|
1342 |
filenameNew = data.getPath(); |
1343 |
} |
1344 |
if (filenameNew != null) { |
1345 |
file = new File(filenameNew); |
1346 |
//String path = getCurrentResource().getUri();
|
1347 |
//if(!path.endsWith("/"))
|
1348 |
//path = path+"/";
|
1349 |
//getTasks().getUploadTask(GssMyFolders.this).execute(path + URLEncoder.encode(file.getName()), filenameNew);
|
1350 |
} |
1351 |
|
1352 |
} |
1353 |
} |