Java Code Examples for com.squareup.picasso.RequestCreator#networkPolicy()

The following examples show how to use com.squareup.picasso.RequestCreator#networkPolicy() . 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: Images.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
public RequestCreator loadBeer(long beerId, boolean highResolution) {
	RequestCreator request =
			Picasso.with(context).load(highResolution ? ImageUrls.getBeerPhotoHighResUrl(beerId) : ImageUrls.getBeerPhotoUrl(beerId));
	if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi)
		request.networkPolicy(NetworkPolicy.OFFLINE);
	return request;
}
 
Example 2
Source File: Images.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
public RequestCreator loadBrewery(long breweryId, boolean highResolution) {
	RequestCreator request = Picasso.with(context).load(highResolution ? ImageUrls.getBreweryPhotoHighResUrl(breweryId) : ImageUrls
			.getBreweryPhotoUrl(breweryId));
	if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi)
		request.networkPolicy(NetworkPolicy.OFFLINE);
	return request;
}
 
Example 3
Source File: Images.java    From ratebeer with GNU General Public License v3.0 5 votes vote down vote up
public RequestCreator loadUser(String username, boolean highResolution) {
	RequestCreator request =
			Picasso.with(context).load(highResolution ? ImageUrls.getUserPhotoHighResUrl(username) : ImageUrls.getUserPhotoUrl(username));
	if (Session.get().inDataSaverMode() && ConnectivityHelper.current(context) != ConnectivityHelper.ConnectivityType.Wifi)
		request.networkPolicy(NetworkPolicy.OFFLINE);
	return request;
}
 
Example 4
Source File: PicturePresenter.java    From AndroidDemo with MIT License 4 votes vote down vote up
public void loadImageView() {

        iPictureView.clearImageView();

        boolean cache = iPictureView.getCache();
        boolean disk = iPictureView.getDisk();
        boolean transformation = iPictureView.getTransformation();

        Picasso picasso = Picasso.with(context.get());
        picasso.setIndicatorsEnabled(true);
        picasso.setLoggingEnabled(true);

        String path = "https://avatars2.githubusercontent.com/u/9563634?s=400&u=6c9844a5ee91e0385888cbd5708af59f4062d651&v=4";
        RequestCreator requestCreator = picasso.load(path)
                .config(Bitmap.Config.RGB_565)
                .placeholder(R.drawable.ic_empty_zhihu)
                .error(R.drawable.ic_failed)
                .fit();

        if (!cache) {
            requestCreator.memoryPolicy(MemoryPolicy.NO_CACHE);
        }
        if (!disk) {
            requestCreator.networkPolicy(NetworkPolicy.NO_CACHE, NetworkPolicy.NO_STORE);
        }

        if (transformation) {
            final Paint paint = new Paint();
            paint.setAntiAlias(true);
            paint.setColor(0xffcccccc);
            paint.setStyle(Paint.Style.FILL);
            final float round = Tools.dip2pxf(context.get(), 8);
            requestCreator.transform(new Transformation() {
                @Override
                public Bitmap transform(Bitmap source) {

                    Bitmap src = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight());
                    Canvas canvas = new Canvas(src);
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
                        float r = source.getWidth() / 4 * 3;
                        canvas.drawCircle(source.getWidth() / 2, source.getHeight() / 2, r, paint);
                    } else {
                        canvas.drawRoundRect(round, round, source.getWidth() - round, source.getHeight() - round,
                                round, round, paint);
                    }
                    canvas.drawBitmap(source, 0, 0, paint);
                    if (!source.isRecycled()) {
                        source.recycle();
                    }
                    return src;
                }

                @Override
                public String key() {
                    return "PicassoTransformation";
                }
            });
        }
        requestCreator.into(iPictureView.getTarget(), new Callback() {
            @Override
            public void onSuccess() {
                iPictureView.showToast("success");
            }

            @Override
            public void onError() {
                iPictureView.showToast("error");
            }
        });
    }