Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: daimajia/AndroidImageSlider
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: travijuu/AndroidImageSlider
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 1 commit
  • 2 files changed
  • 1 contributor

Commits on Aug 27, 2015

  1. Adding image rounding with Picasso Transformation

    Erkin Çakar committed Aug 27, 2015
    Copy the full SHA
    51d6d3d View commit details
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.RequestCreator;
import com.squareup.picasso.Transformation;

import java.io.File;

@@ -49,6 +50,8 @@ public abstract class BaseSliderView {

private Picasso mPicasso;

private Transformation mTransformation;

/**
* Scale type of the image.
*/
@@ -219,6 +222,10 @@ public void onClick(View v) {
return;
}

if (mTransformation != null) {
rq.transform(mTransformation);
}

if(rq == null){
return;
}
@@ -325,4 +332,9 @@ public Picasso getPicasso() {
public void setPicasso(Picasso picasso) {
mPicasso = picasso;
}

public BaseSliderView setTransformation(Transformation transformation) {
mTransformation = transformation;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.daimajia.slider.library.Transformations;

import android.graphics.Bitmap;
import android.graphics.BitmapShader;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Shader;

public class RoundedTransformation implements com.squareup.picasso.Transformation {
private final int radius;
private final int margin;

public RoundedTransformation(int margin, int radius) {
this.margin = margin;
this.radius = radius;
}

@Override
public Bitmap transform(Bitmap source) {
final Paint paint = new Paint();

paint.setAntiAlias(true);
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));

Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);

if (source != output) {
source.recycle();
}

return output;
}

@Override
public String key() {
return "rounded";
}
}