Set<Entry<Integer, PhotoInfo>> entrySet = photoMap.entrySet();
ArrayList<String> al = new ArrayList<String>();
Iterator<Entry<Integer, PhotoInfo>> iterator = entrySet.iterator();
while (iterator.hasNext()) {
PhotoInfo pi = iterator.next().getValue();
al.add(pi.getPath_absolute());
}
pd.show();
pd.setMax(al.size());
int id = 0;
SharedPreferences sp = getSharedPreferences(CommonUtils.SP_NAME, 0);
id = sp.getInt("id", 0);
if (id == 0) {
return;
}
int folder = 0;
folder = sp.getInt("photos", 0);
if (folder == 0) {
return;
}
String url = CommonUtils.getHost(getApplicationContext()) + "upload";
AsyncHttpClient httpClient = new AsyncHttpClient();
RequestParams p = new RequestParams();
for (int i = 0; i < al.size(); i++) {
String path = al.get(i);
try {
p.put("file", new File(path));
p.put("cloud",cloud_type);
p.put("account", id);
p.put("folder", folder);
httpClient.post(url, p, new AsyncHttpResponseHandler() {
@Override
public void onStart() {
super.onStart();
}
@Override
public void onFailure(int arg0, Header[] arg1, byte[] arg2,
Throwable arg3) {
// TODO Auto-generated method stub
}
@Override
public void onSuccess(int arg0, Header[] arg1, byte[] arg2) {
uploadNum++;
pd.setProgress(uploadNum);
if (uploadNum == pd.getMax())// 达到百分百
{
pd.dismiss();
pd.setProgress(0);
finish();
}
}
});
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mark