Reputation: 1
So as the name says I am having a problem with loading the same Image into multiple ImageViews, The problem I am running into is that for each of the image views, i want to provide a slightly different transformation on each. However, the problem is that only the first transform is applied to both images.
here is the code for the actual picasso part of it
RequestCreator request;
ImageView background = getTarget();
if (background != null) {
if (file != null && file.exists()) {
request = Picasso.with(background.getContext()).load(file);
} else {
request = Picasso.with(background.getContext()).load(R.drawable.stock_living_room);
}
if (mBlurType == BLUR_NORMAL) {
request.fit();
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.centerCrop();
request.transform(new BlurTransformation(background.getContext(), 20));
} else {
request.resize(128, 128);
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.transform(new BlurTransformation(background.getContext(), 10));
}
if(applyGradient)
request.memoryPolicy(MemoryPolicy.NO_CACHE, MemoryPolicy.NO_STORE);
request.transform(new LinearGradientTransformation(mGradient));
request.into(background);
}
I realize that i have the memoryPolicy in there 3 times i just wanted to see if it would work. The problem I am having is with the last part: if(applyGradient)
here is the code where I call this class that has the above code
mBackgroundImageViewTwo = new ImageView(getActivity());
mBackgroundImageViewTwo.setVisibility(View.VISIBLE);
mBackgroundImageViewTwo.getHeight();
Shader Gradient = new LinearGradient(0, 0, 1, 1,
new int[]{
ContextCompat.getColor(getActivity(), R.color.hot00Overlay),
ContextCompat.getColor(getActivity(), R.color.hot90Overlay)
},
new float[]{0f, 1f},
Shader.TileMode.CLAMP);
mImageHelper2 = new HomeGradientImageHelper(Gradient);
mImageHelper2.setImageTarget(mBackgroundImageViewTwo, true);
mBackgroundImageView = new ImageView(getActivity());
mBackgroundImageView.getHeight();
Shader mGradient = new LinearGradient(0, 0, 1, 1,
new int[]{
ContextCompat.getColor(getActivity(), R.color.cool00Overlay),
ContextCompat.getColor(getActivity(), R.color.cool90Overlay)
},
new float[]{0f, 1f},
Shader.TileMode.CLAMP);
mImageHelper = new HomeGradientImageHelper(mGradient);
mImageHelper.setImageTarget(mBackgroundImageView, true);
interestingly enough these two image views come out looking exactly the same with the exact same coloring even though, if i only do them 1 at a time the coloring is much different.
the other interesting part about this is that if target picasso at something that is found by going view.findViewById(reference) the call FoundImageView.setVisibility(GONE) will not have any effect.
Any thoughts on this subject would be greatly appreciated.
Upvotes: 0
Views: 1052
Reputation: 8574
Make sure to put an appropriately unique key in your Transformation.
Picasso uses the key to cache Bitmaps in its Cache
. If you have perhaps an empty key for all your Transformations, then Picasso thinks that you have the same image and returns the image from the Cache
. The cache's key is based on factors like the url, resource id, Transformation key, Bitmap decoding options, etc.
Upvotes: 2