Java 类com.facebook.datasource.BaseDataSubscriber 实例源码

项目:H-Viewer    文件:ImageLoader.java   
public static void loadResourceFromUrl(Context context, Uri uri, String cookie, String referer, BaseDataSubscriber dataSubscriber) {
    if (uri.getScheme().startsWith("http")) {
        JsonObject header = new JsonObject();
        header.addProperty("Cookie", cookie);
        header.addProperty("Referer", referer);
        if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
            HProxy proxy = new HProxy(uri.toString());
            header.addProperty(proxy.getHeaderKey(), proxy.getHeaderValue());
        }
        MyOkHttpNetworkFetcher.headers.put(uri, getGson().toJson(header));
    }
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(uri);
    ImageRequest request = builder.build();
    DataSource<CloseableReference<PooledByteBuffer>>
            dataSource = imagePipeline.fetchEncodedImage(request, context);
    dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
项目:materialup    文件:FrescoUtils.java   
private static final void setSubscribe(Context context, ImageRequest request, BaseDataSubscriber subscriber) {
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource =
            imagePipeline.fetchDecodedImage(request, context);
    dataSource.subscribe(subscriber, CallerThreadExecutor.getInstance());
}
项目:materialup    文件:FrescoUtils.java   
public static final void setShotUrl(DraweeView view, String url, String thumbnail, BaseDataSubscriber subscriber, boolean full) {
        if (TextUtils.isEmpty(thumbnail) && TextUtils.isEmpty(url)) {
            return;
        }
        ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url))
//                .setResizeOptions(
//                        new ResizeOptions(300, 400))
                .setProgressiveRenderingEnabled(true)
                .build();
        ImageRequest lowRequest = null;
        if (!TextUtils.isEmpty(thumbnail)) {
            lowRequest = ImageRequest.fromUri(thumbnail);
        }

        if (subscriber != null) {
            if (lowRequest != null && !full) {
                setSubscribe(view.getContext(), lowRequest, subscriber);
            } else if (imageRequest != null) {
                setSubscribe(view.getContext(), imageRequest, subscriber);
            }
        }

        DraweeController draweeController = Fresco.newDraweeControllerBuilder()
                .setImageRequest(imageRequest)
                .setLowResImageRequest(lowRequest)
                .setOldController(view.getController())
                .setAutoPlayAnimations(true)
//                .setControllerListener(listener)
                .build();

//        ImagePipeline imagePipeline = Fresco.getImagePipeline();
//        ImageRequest request = lowRequest == null ? imageRequest : lowRequest;
//        DataSource<CloseableReference<CloseableImage>> dataSource =
//                imagePipeline.fetchDecodedImage(request, view.getContext());
//        dataSource.subscribe(new BaseBitmapDataSubscriber() {
//            @Override
//            protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
//
//            }
//
//            @Override protected void onNewResultImpl(@Nullable Bitmap bitmap) {
//                Palette.from(bitmap).maximumColorCount(3).generate(new Palette.PaletteAsyncListener() {
//                    @Override public void onGenerated(Palette palette) {
//                    }
//                });
//            }
//        }, CallerThreadExecutor.getInstance());

        view.setController(draweeController);
    }
项目:H-Viewer    文件:ImageLoader.java   
public static void loadResourceFromUrl(Context context, String url, String cookie, String referer, BaseDataSubscriber dataSubscriber) {
    if (TextUtils.isEmpty(url))
        return;
    Uri uri = Uri.parse(url);
    loadResourceFromUrl(context, uri, cookie, referer, dataSubscriber);
}