Java 类com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber 实例源码

项目:H-Viewer    文件:ImageLoader.java   
public static void loadBitmapFromUrl(Context context, String url, String cookie, String referer, BaseBitmapDataSubscriber dataSubscriber) {
    if (TextUtils.isEmpty(url))
        return;
    Uri uri = Uri.parse(url);
    JsonObject header = new JsonObject();
    header.addProperty("Cookie", cookie);
    header.addProperty("Referer", referer);
    if (HProxy.isEnabled() && HProxy.isAllowPicture()) {
        HProxy proxy = new HProxy(url);
        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<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(request, context);
    dataSource.subscribe(dataSubscriber, CallerThreadExecutor.getInstance());
}
项目:nono-android    文件:FrescoImageloadHelper.java   
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
项目:nono-android    文件:FrescoImageloadHelper.java   
public static void LoadImageFromURIAndCallBack(SimpleDraweeView destImageView , Uri uri,Context context,BaseBitmapDataSubscriber bbds)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequest imageRequest =
            ImageRequestBuilder.newBuilderWithSource(uri)
                    .setResizeOptions(new ResizeOptions(w,h))
                    .setProgressiveRenderingEnabled(true)
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
项目:fastDev    文件:FrescoImageloadHelper.java   
public static void loadOriginalBitmap(String URL, Context context, BaseBitmapDataSubscriber bbds)
{

    loadBitmap(URL,context,0,0,null,bbds);
 /*   DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);*/
}
项目:H-Viewer    文件:URLImageParser.java   
@Override
public Drawable getDrawable(String source) {
    Logger.d("URLImageParser", "source:" + source);
    final LevelListDrawable mDrawable = new LevelListDrawable();
    Drawable empty = new BitmapDrawable();
    mDrawable.addLevel(0, 0, empty);
    mDrawable.setBounds(0, 0, empty.getIntrinsicWidth(), empty.getIntrinsicHeight());
    // get the actual source
    ImageLoader.loadBitmapFromUrl(context, source, cookie, referer, new BaseBitmapDataSubscriber() {
        @Override
        protected void onNewResultImpl(Bitmap bitmap) {
            if (bitmap != null) {
                Bitmap copy = bitmap.copy(Bitmap.Config.ARGB_8888, true);
                Drawable drawable = new BitmapDrawable(context.getResources(), copy);
                mDrawable.addLevel(1, 1, drawable);
                mDrawable.setBounds(0, 0, copy.getWidth(), copy.getHeight());
                mDrawable.setLevel(1);
                new Handler(context.getMainLooper()).post(new Runnable() {
                    @Override
                    public void run() {
                        CharSequence t = textView.getText();
                        textView.setText(t);
                    }
                });
            }
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {
        }
    });

    // return reference to URLDrawable where I will change with actual image from
    // the src tag
    return mDrawable;
}
项目:witchpot    文件:MediaUtil.java   
public static void getBitmapWithFresco(Context context, String url, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
    ImageRequest imageRequest = ImageRequestBuilder
            .newBuilderWithSource(Uri.parse(url))
            .setProgressiveRenderingEnabled(true)
            .build();

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(baseBitmapDataSubscriber,
            CallerThreadExecutor.getInstance());
}
项目:nono-android    文件:FrescoImageloadHelper.java   
public static void LoadImageFromURLAndCallBack(SimpleDraweeView destImageView , String URL, Context context, BaseBitmapDataSubscriber bbds
, BasePostprocessor postprocessor)
{
    int w = destImageView.getWidth();
    int h  =destImageView.getHeight();
    if(w<1){
        w = destImageView.getLayoutParams().width;
    }
    if(h<1){
        h  =destImageView.getLayoutParams().height;
    }
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(Uri.parse(URL))
            .setResizeOptions(new ResizeOptions(w,h))
            .setProgressiveRenderingEnabled(true);
    if(postprocessor!=null){
        builder.setPostprocessor(postprocessor);
    }
    ImageRequest imageRequest =
            builder
                    .build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);
    dataSource.subscribe(bbds, CallerThreadExecutor.getInstance());
    DraweeController draweeController = Fresco.newDraweeControllerBuilder()
            .setImageRequest(imageRequest)
            .setOldController(destImageView.getController())
            .setAutoPlayAnimations(true)
            .build();
    destImageView.setController(draweeController);
}
项目:Fishing    文件:ImageViewActivity.java   
@Override
public View instantiateItem(ViewGroup container, int position) {
    View view = LayoutInflater.from(ImageViewActivity.this).inflate(R.layout.item_imagepage, container, false);
    final PhotoView photoView = (PhotoView) view.findViewById(R.id.photoview);
    final View wheel = view.findViewById(R.id.wheel);
    photoView.setOnPhotoTapListener((view1, v, v1) -> finish());

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    ImageRequest request = ImageRequestBuilder.newBuilderWithSource(urls.get(position))
            .setResizeOptions(new ResizeOptions(768, 768))
            .build();
    DataSource<CloseableReference<CloseableImage>>
            dataSource = imagePipeline.fetchDecodedImage(request,this);
    DataSubscriber dataSubscriber = new BaseBitmapDataSubscriber() {
        @Override
        protected void onNewResultImpl(Bitmap bitmap) {
              photoView.setImageBitmap(bitmap);
              wheel.setVisibility(View.GONE);
        }

        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> closeableReferenceDataSource) {

        }
    };
    dataSource.subscribe(dataSubscriber, new Executor() {
        @Override
        public void execute(Runnable command) {
            handler.post(command);
        }
    });
    container.addView(view);
    return view;
}
项目:fastDev    文件:MyImageUtils.java   
public static void getBitmapByFresco(String url,BaseBitmapDataSubscriber dataSubscriber){
    if (TextUtils.isEmpty(url)){
        return;
    }
    FrescoImageloadHelper.loadOriginalBitmap(url, BaseUtils.getContext(), dataSubscriber);
}
项目:materialup    文件:PostActivity.java   
private void handleContent(Post content) {
        shot = content;
//        loaderUpvoters();
        if (mNeedUpdateConent) {
            BaseBitmapDataSubscriber subscriber = new BaseBitmapDataSubscriber() {
                @Override
                protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

                }

                @Override
                protected void onNewResultImpl(@Nullable Bitmap bitmap) {
                    if (bitmap != null && UI.isLollipop()) {
                        processPalette(bitmap);
                    }
                }
            };
            FrescoUtils.setShotUrl(imageView, shot.getImageUrl(), shot.getTeaserUrl(), subscriber, false);
            source.setImageResource(shot.getSourceIcon());
        }
        checkLiked();
        updateVoteCount();
        if (shot.isHasComments()) {
            loadComments();
        } else {
            commentsList.setAdapter(getNoCommentsAdapter());
        }

        setupUserInfo();
        if (!TextUtils.isEmpty(shot.description)) {
            final Spanned descText = shot.getParsedDescription(
                    ContextCompat.getColorStateList(this, R.color.dribbble_links),
                    ContextCompat.getColor(this, R.color.dribbble_link_highlight));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                ((FabOverlapTextView) description).setText(descText);
            } else {
                HtmlUtils.setTextWithNiceLinks((TextView) description, descText);
            }
            description.setVisibility(View.VISIBLE);
        } else {
            description.setVisibility(View.GONE);
        }
    }
项目:materialup    文件:PhotoActivity.java   
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photo);
    Intent intent = getIntent();
    String url = intent.getStringExtra(Launcher.EXTRA_URL);
    String preUrl = intent.getStringExtra(Launcher.EXTRA_PRE_URL);
    mTitle = intent.getStringExtra(Launcher.EXTRA_TITLE);
    if (mTitle != null) {
        mTitle = mTitle.replaceAll(" ","_");
        if (mTitle.length() > 15) {
            mTitle = mTitle.substring(0, 15);
        }
    }
    mUrl = url;
    ButterKnife.bind(this);

    FrescoUtils.setShotHierarchy(this, mDraweeView, 0);
    BaseBitmapDataSubscriber subscriber = new BaseBitmapDataSubscriber() {
        @Override
        protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

        }

        @Override
        protected void onNewResultImpl(@Nullable Bitmap bitmap) {
            enableSaveButton();
        }
    };
    FrescoUtils.setShotUrl(mDraweeView, url, preUrl, subscriber, true);

    back.setOnClickListener(this);
    source.setOnClickListener(this);

    if (UI.isLollipop()) {
        supportPostponeEnterTransition();
        source.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver
                .OnPreDrawListener() {
            @Override
            public boolean onPreDraw() {
                source.getViewTreeObserver().removeOnPreDrawListener(this);
                enterAnimation();
                supportStartPostponedEnterTransition();
                return true;
            }
        });
    }

    Nammu.init(getApplicationContext());
}
项目:android-jungle-framework    文件:FrescoImageLoaderEngine.java   
/**
 * Internal helper method for load Bitmap.
 *
 * @param maxSize 0 or less than 0 if want original bitmap.
 */
@Override
public void loadImageInternal(
        final Uri uri,
        final int maxSize,
        final ImageLoaderUtils.ImageLoadListener listener) {

    if (uri == null) {
        listener.onFailed(-1);
        return;
    }

    ImageRequestBuilder builder = ImageRequestBuilder
            .newBuilderWithSource(uri)
            .setAutoRotateEnabled(true);
    if (maxSize > 0) {
        builder.setResizeOptions(new ResizeOptions(maxSize, maxSize));
    }

    ImagePipeline pipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> data =
            pipeline.fetchDecodedImage(builder.build(), null);

    Executor executor = new Executor() {
        @Override
        public void execute(@NonNull Runnable command) {
            ThreadManager.getInstance().postOnUIHandler(command);
        }
    };

    data.subscribe(new BaseBitmapDataSubscriber() {
        @Override
        protected void onNewResultImpl(Bitmap bitmap) {
            if (bitmap == null) {
                listener.onFailed(ImageLoaderUtils.ERROR_LOAD_EMPTY_IMAGE);
                return;
            }

            final int width = bitmap.getWidth();
            final int height = bitmap.getHeight();
            try {
                if (maxSize <= 0 || (width <= maxSize && height <= maxSize)) {
                    listener.onSuccess(uri, Bitmap.createBitmap(bitmap));
                } else {
                    JungleSize size = ImageUtils.getMaxScaleSize(
                            bitmap.getWidth(), bitmap.getHeight(), maxSize);
                    listener.onSuccess(uri, Bitmap.createScaledBitmap(
                            bitmap, size.getWidth(), size.getHeight(), true));
                }
            } catch (Throwable e) {
                e.printStackTrace();
                listener.onSuccess(uri, bitmap);
            }
        }

        @Override
        protected void onFailureImpl(
                DataSource<CloseableReference<CloseableImage>> dataSource) {
            listener.onFailed(ImageLoaderUtils.ERROR_LOAD_FAILED);
        }
    }, executor);
}
项目:nono-android    文件:ReelNoteActivity.java   
@Override
    protected void registerWidget() {
        note_add_fab=$(R.id.group_note_fab_add);
        fab_op_pannel=$(R.id.fab_op_pannel);
        btn_md = $(R.id.btn_md);
        btn_text = $(R.id.btn_text);
        btn_md.setOnClickListener(this);
        btn_text.setOnClickListener(this);
        overlay=$(R.id.overlay);
        bg_image=$(R.id.bg_image);
        collapse_layout=$(R.id.collapse_layout);
        bindViewsToOnClickListenerById(R.id.group_note_fab_add,R.id.fab_op_pannel,R.id.overlay);
        if(findViewById(R.id.recycle_view_refresher)!= null){
            ((SwipeRefreshLayout)findViewById(R.id.recycle_view_refresher))
                    .setEnabled(false);
        }
        if(
                MyApp.getCache().reelImageCache !=null
            &&
                MyApp.getCache().reelImageCache.get() !=null){
            bg_image.setImageBitmap(MyApp.getCache().reelImageCache.get());
        }
        bg_image.post(new Runnable() {
            @Override
            public void run() {
                reelImagePath = NoteReelArray.getUriString(reelImagePath);
                FrescoImageloadHelper.LoadImageFromURLAndCallBack(bg_image,
                        reelImagePath,
                        ReelNoteActivity.this, new BaseBitmapDataSubscriber() {
                            @Override
                            protected void onNewResultImpl(@Nullable Bitmap bitmap) {
//                              Palette.Builder b =  Palette.from(bitmap);
//                              Palette p =  b.generate();
//                              final Palette.Swatch swatch = p.getVibrantSwatch();
//                               mutedColor = p.getMutedColor(ThemeController.getCurrentColor().getMainColor());
//                              runOnUiThread(new Runnable() {
//                                  @Override
//                                  public void run() {
//                                      collapse_layout.setContentScrimColor(mutedColor);
//                                      ((NoteGroupItemAdapter)recycleViewAdapter).setThemeMain(mutedColor);
//                                      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
//                                          getWindow().setStatusBarColor(mutedColor);
//                                      }
//                                      collapse_layout.setExpandedTitleColor(swatch.getTitleTextColor());
//                                  }
//                              });

                            }

                            @Override
                            protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

                            }
                        });
            }
        });
    }
项目:nono-android    文件:UserInfoActivity.java   
@Override
protected void onResume() {
    super.onResume();
    $(R.id.toolbar).setBackgroundColor(Color.TRANSPARENT);
    if("true".equals(isme)){
        inspectUserInfo();
    }
    if(userInfo.data == null){
        return;
    }
    if(userInfo.data.user_info_headimg == null){
        return;
    }
    FrescoImageloadHelper.LoadImageFromURLAndCallBack(activityUserInfoHeadimg, userInfo.data.user_info_headimg, this,
            new BaseBitmapDataSubscriber() {
                @Override
                protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

                }

                @Override
                protected void onNewResultImpl(Bitmap bitmap) {
                    headImgBitmap = bitmap;
                    bgColor = autoColor(headImgBitmap);
                    collapsingToolbarLayout.setBackgroundColor(bgColor);
                    collapsingToolbarLayout.setContentScrimColor(bgColor);
                    collapsingToolbarLayout.setStatusBarScrimColor(colorBurn(bgColor));
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                        getWindow().setStatusBarColor(colorBurn(bgColor));
                    }
                    //setColor(bgColor);
                }
            });
    if(userInfo.data.user_info_real_name == null){
        return;
    }
    activityUserInfoRealName.setText(userInfo.data.user_info_real_name);
    getSupportActionBar().setTitle(userInfo.data.user_info_real_name);
    if(userInfo.data.user_info_abstract == null){
        return;
    }
    activityUserInfoAbstract.setText(userInfo.data.user_info_abstract);
}
项目:nono-android    文件:UserInfoActivity.java   
private void UpdateUI(UserInfo userInfo) {
    FrescoImageloadHelper.LoadImageFromURLAndCallBack(activityUserInfoHeadimg, userInfo.data.user_info_headimg, this,
            new BaseBitmapDataSubscriber() {
                @Override
                protected void onFailureImpl(DataSource<CloseableReference<CloseableImage>> dataSource) {

                }

                @Override
                protected void onNewResultImpl(final Bitmap bitmap) {
                    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            headImgBitmap = bitmap;
                            bgColor = autoColor(headImgBitmap);
                            collapsingToolbarLayout.setBackgroundColor(bgColor);
                            collapsingToolbarLayout.setContentScrimColor(bgColor);
                            collapsingToolbarLayout.setStatusBarScrimColor(colorBurn(bgColor));
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                                getWindow().setStatusBarColor(colorBurn(bgColor));
                            }
                        }
                    });
                    //setColor(bgColor);
                }
            });
    activityUserInfoRealName.setText(userInfo.data.user_info_real_name);
    ActionBar actionBar =  getSupportActionBar();
    if(actionBar !=null){
        actionBar.setTitle(userInfo.data.user_info_real_name);
    }

    activityUserInfoAbstract.setText(userInfo.data.user_info_abstract);
    activityUserInfoNoticedNum.setText(String.valueOf(userInfo.data.user_info_noticed_num));
    ((TextView)findView(R.id.activity_user_info_voted_on_num)).setText(String.valueOf(userInfo.data.user_info_voted_up_num));
    if(userInfo.data.user_id == Integer.valueOf(MyApp.getInstance().userInfo.userId)){
        activityUserInfoNotice.setText(R.string.edit);
    }else{
        switch(userInfo.data.user_info_friend_relation){
            case  1:
                activityUserInfoNotice.setText(R.string.unnotice);
                break;
            case 0:
                activityUserInfoNotice.setText(R.string.notice);
                break;
        }
    }

    Bundle args = new Bundle();
    args.putString("University", userInfo.data.user_info_university);
    args.putString("School", userInfo.data.user_info_school);
    args.putString("sex", userInfo.data.user_info_sex);
    updateInfoFrag(args);
}