use of org.aisen.weibo.sina.ui.activity.picture.PicsActivity in project AisenWeiBo by wangdan.
the class PictureFragment method loadPicture.
void loadPicture(View v) {
// 下载路径
String url = null;
Uri uri = Uri.parse(image.getThumbnail_pic());
ImageConfig config = new ImageConfig();
File file = origFile;
// 原图存在,就下载原图
if (file.exists()) {
url = getOrigImage();
} else // 原图不存在,就下载中图
{
file = BitmapLoader.getInstance().getCacheFile(getImage());
config.setId("Picture");
url = getImage();
pictureSize = SinaDB.getDB().selectById(null, PictureSize.class, getOrigImage());
if (pictureSize == null)
new LoadPictureSizeTask().execute();
}
if (!file.exists()) {
progressView.setVisibility(View.VISIBLE);
// 如果网络不是WIFI,且原图和中图都没缓存,那么只加载当前看的那个图片
if (SystemUtils.NetWorkType.wifi != SystemUtils.getNetworkType(getActivity())) {
if (getActivity() instanceof PicsActivity) {
PicsActivity picsActivity = (PicsActivity) getActivity();
if (!picsActivity.getCurrent().getThumbnail_pic().equalsIgnoreCase(image.getThumbnail_pic()))
return;
} else if (getActivity() instanceof PhotosActivity) {
PhotosActivity picsActivity = (PhotosActivity) getActivity();
if (!picsActivity.getCurrent().getThumbnail_pic().equalsIgnoreCase(image.getThumbnail_pic()))
return;
}
}
}
viewFailure.setVisibility(View.GONE);
if ("file".equals(uri.getScheme().toLowerCase())) {
url = uri.getPath();
final File origF = new File(url);
new WorkTask<Void, Void, byte[]>() {
@Override
public byte[] workInBackground(Void... params) throws TaskException {
return FileUtils.readFileToBytes(origF);
}
@Override
protected void onSuccess(byte[] bytes) {
super.onSuccess(bytes);
onDownloadPicture(bytes, origF);
mStatus = PictureStatus.success;
}
}.execute();
} else {
ImageView imgView = new ImageView(getActivity());
config.setProgress(new PictureDownloadProgress(file));
BitmapLoader.getInstance().display(null, url, imgView, config);
}
}
Aggregations