My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/**
* g2android
* Copyright (c) 2009 Anthony Dahanne
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package net.dahanne.android.g2android.tasks;

import java.io.File;
import java.util.ArrayList;

import net.dahanne.android.g2android.activity.Settings;
import net.dahanne.android.g2android.utils.G2ConnectionUtils;
import net.dahanne.android.g2android.utils.GalleryConnectionException;
import net.dahanne.android.g2android.utils.ShowUtils;
import net.dahanne.android.g2android.utils.UriUtils;
import android.app.Activity;
import android.app.ProgressDialog;
import android.net.Uri;
import android.os.AsyncTask;
import android.view.Window;

public class AddPhotosTask extends AsyncTask<Object, Integer, Void> {
private String exceptionMessage = null;
Activity activity;
private String galleryUrl;
private final ProgressDialog progressDialog;

public AddPhotosTask(Activity context, ProgressDialog progressDialog) {
super();
activity = context;
this.progressDialog = progressDialog;
}

@SuppressWarnings("unchecked")
@Override
protected Void doInBackground(Object... parameters) {
String galleryUrl = (String) parameters[0];
Integer albumName = (Integer) parameters[1];
ArrayList<Uri> photoUris = (ArrayList<Uri>) parameters[2];
boolean mustLogIn = (Boolean) parameters[3];

try {
if (mustLogIn) {
G2ConnectionUtils.getInstance().loginToGallery(galleryUrl,
Settings.getUsername(activity),
Settings.getPassword(activity));
}

for (Uri photoUri : photoUris) {
File imageFile = UriUtils.getFileFromUri(photoUri, activity);
String imageName = UriUtils.getFileNameFromUri(photoUri,
activity);
G2ConnectionUtils.getInstance().sendImageToGallery(galleryUrl,
albumName, imageFile, imageName,
Settings.getDefaultSummary(activity),
Settings.getDefaultDescription(activity));
publishProgress((int) (((photoUris.indexOf(photoUri) + 1) / (float) photoUris
.size()) * 10000));
}
} catch (GalleryConnectionException e) {
exceptionMessage = e.getMessage();
}
return null;
}

@Override
protected void onPostExecute(Void useless) {

progressDialog.dismiss();
if (exceptionMessage != null) {
// Something went wrong
ShowUtils.getInstance().alertConnectionProblem(exceptionMessage,
galleryUrl, activity);
} else {
ShowUtils.getInstance().toastImagesSuccessfullyAdded(activity);
}

}

@Override
protected void onPreExecute() {
super.onPreExecute();
activity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, 0);
}

@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
activity.getWindow().setFeatureInt(Window.FEATURE_PROGRESS, values[0]);
}

}

Change log

r90 by anthony.dahanne on Aug 25, 2010   Diff
g2android  release 1.6.0 : fixed issues
#19, #45, #46, #48, #49, #57
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 3380 bytes, 104 lines

File properties

svn:mime-type
text/plain
Powered by Google Project Hosting