Search in sources :

Example 1 with PicsActivity

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);
    }
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) PicsActivity(org.aisen.weibo.sina.ui.activity.picture.PicsActivity) Uri(android.net.Uri) PictureSize(org.aisen.weibo.sina.support.bean.PictureSize) TaskException(org.aisen.android.network.task.TaskException) ImageView(android.widget.ImageView) File(java.io.File) PhotosActivity(org.aisen.weibo.sina.ui.activity.picture.PhotosActivity)

Aggregations

Uri (android.net.Uri)1 ImageView (android.widget.ImageView)1 File (java.io.File)1 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)1 TaskException (org.aisen.android.network.task.TaskException)1 PictureSize (org.aisen.weibo.sina.support.bean.PictureSize)1 PhotosActivity (org.aisen.weibo.sina.ui.activity.picture.PhotosActivity)1 PicsActivity (org.aisen.weibo.sina.ui.activity.picture.PicsActivity)1