Search in sources :

Example 1 with PictureSize

use of org.aisen.weibo.sina.support.bean.PictureSize 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)

Example 2 with PictureSize

use of org.aisen.weibo.sina.support.bean.PictureSize in project AisenWeiBo by wangdan.

the class PictureSizeHttpUtility method doGet.

@Override
public <T> T doGet(HttpConfig config, Setting action, Params urlParams, Class<T> responseCls) throws TaskException {
    if (GlobalContext.getInstance() == null || SystemUtils.getNetworkType(GlobalContext.getInstance()) == SystemUtils.NetWorkType.none)
        return null;
    String url = urlParams.getParameter("path");
    PictureSize size = new PictureSize();
    size.setUrl(url);
    Request request = new Request.Builder().url(url).build();
    try {
        Response response = GlobalContext.getOkHttpClient().newCall(request).execute();
        if (!(response.code() == HttpURLConnection.HTTP_OK || response.code() == HttpURLConnection.HTTP_PARTIAL)) {
            throw new TaskException(String.valueOf(TaskException.TaskError.failIOError));
        } else {
            // 图片大小
            String header = response.header("Content-Length");
            int length = Integer.parseInt(header);
            size.setSize(length);
            SinaDB.getDB().insert(null, size);
            Logger.d(TAG, String.format("图片大小 %s", String.valueOf(size.getSize())));
        }
    } catch (Exception e) {
        throw new TaskException(String.valueOf(TaskException.TaskError.failIOError));
    }
    return (T) size;
}
Also used : Response(com.squareup.okhttp.Response) PictureSize(org.aisen.weibo.sina.support.bean.PictureSize) TaskException(org.aisen.android.network.task.TaskException) Request(com.squareup.okhttp.Request) TaskException(org.aisen.android.network.task.TaskException)

Aggregations

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