com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber Java Examples

The following examples show how to use com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example #3
Source File: FrescoController.java    From base-module with Apache License 2.0 5 votes vote down vote up
/**
 * 加载图片获取 Bitmap 对象
 * @param subscriber
 */
public void intoTarget(BaseBitmapDataSubscriber subscriber) {
    ImageRequestBuilder builder = ImageRequestBuilder.newBuilderWithSource(mUri)
            .setProgressiveRenderingEnabled(true);

    if (mWidth > 0 && mHeight > 0) {
        builder.setResizeOptions(new ResizeOptions(mWidth, mHeight));
    }

    ImageRequest imageRequest = builder.build();
    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, this);
    dataSource.subscribe(subscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example #4
Source File: ApplicationActivity.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private void setToolbarOverFlowIcon(Bundle icon, final Toolbar toolBar) {
    bitmapFor(icon, getApplicationContext(), new BaseBitmapDataSubscriber() {
        @Override
        public void onNewResultImpl(@Nullable Bitmap bitmap) {
            toolBar.setOverflowIcon(new BitmapDrawable(getApplicationContext().getResources(), bitmap));
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
            Log.e(ApplicationActivity.class.getName(), "Invalid bitmap: ", dataSource.getFailureCause());
        }
    });
}
 
Example #5
Source File: ApplicationActivity.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private void setMenuItemIcon(Bundle icon, final MenuItem menuItem) {
    bitmapFor(icon, getApplicationContext(), new BaseBitmapDataSubscriber() {
        @Override
        public void onNewResultImpl(@Nullable Bitmap bitmap) {
            menuItem.setIcon(new BitmapDrawable(getApplicationContext().getResources(), bitmap));
        }

        @Override
        public void onFailureImpl(DataSource dataSource) {
            Log.e(ApplicationActivity.class.getName(), "Invalid bitmap: ", dataSource.getFailureCause());
        }
    });
}
 
Example #6
Source File: ApplicationActivity.java    From react-native-turbolinks with MIT License 5 votes vote down vote up
private void bitmapFor(Bundle image, Context context, BaseBitmapDataSubscriber baseBitmapDataSubscriber) {
    ImageSource source = new ImageSource(context, image.getString("uri"));
    ImageRequest imageRequest = ImageRequestBuilder.newBuilderWithSource(source.getUri()).build();

    ImagePipeline imagePipeline = Fresco.getImagePipeline();
    DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, context);

    dataSource.subscribe(baseBitmapDataSubscriber, UiThreadImmediateExecutorService.getInstance());
}
 
Example #7
Source File: FrescoImageloadHelper.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: ImageViewActivity.java    From Fishing with GNU General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #9
Source File: FrescoController.java    From base-module with Apache License 2.0 4 votes vote down vote up
@Override
public void intoTarget(BaseBitmapDataSubscriber subscriber) {
    super.intoTarget(subscriber);
}
 
Example #10
Source File: PostActivity.java    From materialup with Apache License 2.0 4 votes vote down vote up
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);
        }
    }
 
Example #11
Source File: PhotoActivity.java    From materialup with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example #12
Source File: ReelNoteActivity.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
@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) {

							}
						});
			}
		});
	}
 
Example #13
Source File: UserInfoActivity.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
@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);
}
 
Example #14
Source File: UserInfoActivity.java    From nono-android with GNU General Public License v3.0 4 votes vote down vote up
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);
}