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

The following examples show how to use com.squareup.picasso.RequestCreator#transform() . 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: BoxingPicassoLoader.java    From kcanotify_h5-master with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, final IBoxingCallback callback) {
    String path = "file://" + absPath;
    RequestCreator creator = Picasso.with(img.getContext())
            .load(path);
    if (width > 0 && height > 0) {
        creator.transform(new BitmapTransform(width, height));
    }
    creator.into(img, new Callback() {
        @Override
        public void onSuccess() {
            if (callback != null) {
                callback.onSuccess();
            }
        }

        @Override
        public void onError() {
            if (callback != null) {
                callback.onFail(null);
            }
        }
    });
}
 
Example 2
Source File: PicassoLoaderProcessor.java    From ImageLoaderProcessor with Apache License 2.0 6 votes vote down vote up
private RequestCreator loadOptions(RequestCreator requestCreator) {
    if (options == null) {
        return requestCreator;
    }
    if (options.targetHeight > 0 && options.targetWidth > 0) {
        requestCreator.resize(options.targetWidth, options.targetHeight);
    }
    if (options.isCenterInside) {
        requestCreator.centerInside();
    } else if (options.isCenterCrop) {
        requestCreator.centerCrop();
    }
    if (options.config != null) {
        requestCreator.config(options.config);
    }
    if (options.errorResId != 0) {
        requestCreator.error(options.errorResId);
    }
    if (options.placeholderResId != 0) {
        requestCreator.placeholder(options.placeholderResId);
    }
    if (options.bitmapAngle != 0) {
        requestCreator.transform(new PicassoTransformation(options.bitmapAngle));
    }
    return requestCreator;
}
 
Example 3
Source File: BoxingPicassoLoader.java    From boxing with Apache License 2.0 6 votes vote down vote up
@Override
public void displayRaw(@NonNull ImageView img, @NonNull String absPath, int width, int height, final IBoxingCallback callback) {
    String path = "file://" + absPath;
    RequestCreator creator = Picasso.with(img.getContext())
            .load(path);
    if (width > 0 && height > 0) {
        creator.transform(new BitmapTransform(width, height));
    }
    creator.into(img, new Callback() {
        @Override
        public void onSuccess() {
            if (callback != null) {
                callback.onSuccess();
            }
        }

        @Override
        public void onError() {
            if (callback != null) {
                callback.onFail(null);
            }
        }
    });
}
 
Example 4
Source File: BrowseFragment.java    From Amphitheatre with Apache License 2.0 6 votes vote down vote up
private void updateBackground(String url) {
    SharedPreferences sharedPrefs = PreferenceManager
            .getDefaultSharedPreferences(getActivity().getApplicationContext());

    RequestCreator requestCreator = Picasso.with(getActivity())
            .load(url)
            .placeholder(R.drawable.placeholder)
            .resize(mMetrics.widthPixels, mMetrics.heightPixels)
            .centerCrop()
            .skipMemoryCache();

    switch(Enums.BlurState.valueOf(sharedPrefs.getString(Constants.BACKGROUND_BLUR, ""))) {
        case ON:
            requestCreator = requestCreator.transform(mBlurTransformation);
            break;
    }

    requestCreator.into(mBackgroundTarget);
}
 
Example 5
Source File: UserImage.java    From intra42 with Apache License 2.0 5 votes vote down vote up
public static RequestCreator getPicassoCorned(RequestCreator request) {
    final int radius = 5;
    final int margin = 5;
    final Transformation transformation = new RoundedCornersTransformation(radius, margin);
    request.transform(transformation);
    return request;
}
 
Example 6
Source File: PicassoImageLoader.java    From Game-of-Thrones with Apache License 2.0 5 votes vote down vote up
@Override
public void show() {
  RequestCreator creator = Picasso.with(imageView != null ? imageView.getContext() : context)
      .load(url);

  if (transformation != null) {
    creator.transform(transformation);
  }

  if (placeholder != null) {
    creator.placeholder(placeholder);
  }

  if (with > 0 && height > 0) {
    creator.resize(with, height);
  }

  if (centerCrop) {
    creator.centerCrop();
  }

  if (fit) {
    creator.fit();
  }

  if (target != null) {
    creator.into(target);
  } else {
    creator.into(imageView);
  }
}
 
Example 7
Source File: RemoteImageView.java    From cathode with Apache License 2.0 5 votes vote down vote up
private void loadBitmap(boolean animate) {
  fraction = 0.0f;
  image = null;
  final int width = getWidth() - getPaddingStart() - getPaddingEnd();
  final int height = getHeight() - getPaddingTop() - getPaddingBottom();

  RequestCreator creator = null;
  if (imageUrl != null) {
    creator = picasso.load(imageUrl);
  } else if (imageResource > 0) {
    creator = picasso.load(imageResource);
  }

  if (creator != null) {
    creator.resize(width - resizeInsetX, height - resizeInsetY).centerCrop();

    if (PaletteTransformation.shouldTransform) {
      creator.transform(new PaletteTransformation());
    }

    for (Transformation transformation : transformations) {
      creator.transform(transformation);
    }
    creator.into(this);
  }

  if (!animate && image != null) {
    animating = false;
    startTimeMillis = 0;
    fraction = 1.0f;
  }
}
 
Example 8
Source File: PicassoLoader.java    From ImageLoader with Apache License 2.0 4 votes vote down vote up
private void setShapeModeAndBlur(SingleConfig config, RequestCreator request) {
    int shapeMode = config.getShapeMode();
    List<Transformation> transformations = new ArrayList<>();

    if(config.isCropFace()){
         //transformations.add(new FaceCenterCrop(config.getWidth(), config.getHeight()));//脸部识别
    }

    if(config.isNeedBlur()){
        transformations.add(new BlurTransformation(GlobalConfig.context,config.getBlurRadius()));
    }


    switch (shapeMode){
        case ShapeMode.RECT:

            if(config.getBorderWidth()>0){

            }
            break;
        case ShapeMode.RECT_ROUND:
            transformations.add(new RoundedCornersTransformation( config.getRectRoundRadius(), 0, RoundedCornersTransformation.CornerType.ALL));

            if(config.getBorderWidth()>0){

            }
            if(config.isGif() && config.getRoundOverlayColor()>0){

            }
            break;
        case ShapeMode.OVAL:
            transformations.add(new CropCircleTransformation());
            if(config.getBorderWidth()>0){

            }
            if(config.isGif() && config.getRoundOverlayColor()>0){

            }
            break;
    }
    if(transformations.size()>0){
        request.transform(transformations);
    }


}
 
Example 9
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");
            }
        });
    }
 
Example 10
Source File: MainActivityAdapter.java    From Pocket-Plays-for-Twitch with GNU General Public License v3.0 4 votes vote down vote up
protected void loadImagePreview(String previewURL, E element, final ElementsViewHolder viewHolder) {
	if(previewURL != null && !previewURL.isEmpty()) {

		RequestCreator creator =
				Picasso.with(context)
						.load(previewURL)
						.placeholder(ContextCompat.getDrawable(context, element.getPlaceHolder(getContext())));

		if(isBelowLollipop) {
			creator.transform(new RoundedTopTransformation(context.getResources().getDimension(getCornerRadiusRessource())));
		}

		if(mTargets.get(viewHolder.getTargetsKey()) != null) {
			viewHolder.getPreviewView().setImageBitmap(mTargets.get(viewHolder.getTargetsKey()).getPreview());
		} else {
			PreviewTarget mTarget = new PreviewTarget() {
				private boolean loaded = false;

				@Override
				public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
					if(!loaded) {
						loaded = true;

						if (removeBlackbars) {
							bitmap = Service.removeBlackBars(bitmap);
						}

						AnimationService.setPicassoShowImageAnimationTwo(viewHolder.getPreviewView(), bitmap, context);
						setPreview(bitmap);
					}
				}

				@Override
				public void onBitmapFailed(Drawable errorDrawable) {

				}

				@Override
				public void onPrepareLoad(Drawable placeHolderDrawable) {
					viewHolder.getPreviewView().setImageDrawable(placeHolderDrawable);
				}
			};

			creator.into(mTarget);
			mTargets.put(viewHolder.getTargetsKey(), mTarget);
		}

	} else {
		viewHolder.getPreviewView().setImageDrawable(ContextCompat.getDrawable(context, element.getPlaceHolder(getContext())));
	}
}
 
Example 11
Source File: UserImage.java    From intra42 with Apache License 2.0 4 votes vote down vote up
public static RequestCreator getPicassoRounded(RequestCreator request) {
    final Transformation transformation = new CropCircleTransformation();
    request.transform(transformation);
    return request;
}