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