use of org.aisen.android.network.task.WorkTask in project AisenWeiBo by wangdan.
the class PictureFragment method downloadImage.
private void downloadImage() {
new IAction(getActivity(), new SdcardPermissionAction((BaseActivity) getActivity(), null)) {
@Override
public void doAction() {
new WorkTask<Void, Void, String>() {
@Override
protected void onPrepare() {
super.onPrepare();
ViewUtils.createProgressDialog(getActivity(), getString(R.string.msg_save_pic_loading), ThemeUtils.getThemeColor()).show();
}
private void notifyFileSys(File file) {
SystemUtils.scanPhoto(getActivity(), file);
}
@Override
public String workInBackground(Void... params) throws TaskException {
File file = origFile;
if (!file.exists())
file = BitmapLoader.getInstance().getCacheFile(getImage());
String path = SystemUtils.getSdcardPath() + File.separator + AppSettings.getImageSavePath() + File.separator + file.getName();
File newFile = new File(path);
if (!newFile.exists()) {
if (!newFile.getParentFile().exists())
newFile.getParentFile().mkdirs();
try {
FileUtils.copyFile(file, newFile);
notifyFileSys(newFile);
return newFile.getParentFile().getAbsolutePath();
} catch (Exception e) {
}
} else {
notifyFileSys(newFile);
return newFile.getParentFile().getAbsolutePath();
}
return null;
}
@Override
protected void onSuccess(String aBoolean) {
super.onSuccess(aBoolean);
if (!TextUtils.isEmpty(aBoolean)) {
showMessage(String.format(getString(R.string.msg_save_pic_success), aBoolean));
} else {
showMessage(R.string.msg_save_pic_faild);
}
}
@Override
protected void onFinished() {
super.onFinished();
ViewUtils.dismissProgressDialog();
}
}.execute();
}
}.run();
}
Aggregations