Skip to content

Commit

Permalink
Merge pull request #3 from sergio91pt/picasso
Browse files Browse the repository at this point in the history
Return a "complete" transformation key.
  • Loading branch information
ignasi committed May 24, 2014
2 parents 974b0f3 + 902cf4b commit 9d10ad5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public void setFaceMarginPx(int faceMarginPx) {
mSizeMode = SizeMode.FaceMarginPx;
}

public SizeMode getSizeMode() {
return mSizeMode;
}

public float getEyeDistanceFactorMargin() {
return mEyeDistanceFactorMargin;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import android.widget.ImageView;
import android.widget.SeekBar;

import com.squareup.picasso.LruCache;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Transformation;

Expand All @@ -21,7 +20,7 @@ public class MainActivity extends ActionBarActivity {
private Picasso mPicasso;
private FaceCropper mFaceCropper;
private ViewPager mViewPager;
private LruCache mCache;

private Transformation mCropTransformation = new Transformation() {

@Override
Expand All @@ -31,7 +30,20 @@ public Bitmap transform(Bitmap source) {

@Override
public String key() {
return "crop()";
StringBuilder builder = new StringBuilder(48);

builder.append("faceCrop(");
builder.append("minSize=").append(mFaceCropper.getFaceMinSize());
builder.append(",maxFaces=").append(mFaceCropper.getMaxFaces());

FaceCropper.SizeMode mode = mFaceCropper.getSizeMode();
if (FaceCropper.SizeMode.EyeDistanceFactorMargin.equals(mode)) {
builder.append(",distFactor=").append(mFaceCropper.getEyeDistanceFactorMargin());
} else if (FaceCropper.SizeMode.FaceMarginPx.equals(mode)) {
builder.append(",margin=").append(mFaceCropper.getFaceMarginPx());
}

return builder.append(")").toString();
}
};

Expand All @@ -42,8 +54,7 @@ protected void onCreate(Bundle savedInstanceState) {

mFaceCropper = new FaceCropper(1f);
mFaceCropper.setFaceMinSize(0);
mCache = new LruCache(this);
mPicasso = new Picasso.Builder(this).memoryCache(mCache).build();
mPicasso = Picasso.with(this);

final ImageAdapter adapter = new ImageAdapter();
mViewPager = (ViewPager) findViewById(R.id.viewPager);
Expand All @@ -68,7 +79,6 @@ public void onPageScrollStateChanged(int state) {
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
mCache.clear();
mFaceCropper.setEyeDistanceFactorMargin((float) i / 10);
adapter.updateView(mViewPager.getCurrentItem());
}
Expand Down Expand Up @@ -126,7 +136,11 @@ public void setupView(View v, int position) {
ImageView imageCropped = (ImageView) v.findViewById(R.id.imageViewCropped);

mPicasso.load(urls[position]).into(image);
mPicasso.load(urls[position]).transform(mCropTransformation).into(imageCropped);

mPicasso.load(urls[position])
.config(Bitmap.Config.RGB_565)
.transform(mCropTransformation)
.into(imageCropped);
}

public void updateView(int position) {
Expand Down

0 comments on commit 9d10ad5

Please sign in to comment.