-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2245244
commit dfe8854
Showing
4 changed files
with
50 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
Entangle/entangle-android/src/com/megasoft/entangle/views/RoundedTransformation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.megasoft.entangle.views; | ||
|
||
import android.graphics.Bitmap; | ||
import android.graphics.Bitmap.Config; | ||
import android.graphics.BitmapShader; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
import android.graphics.Shader; | ||
|
||
// enables hardware accelerated rounded corners | ||
// original idea here : http://www.curious-creature.org/2012/12/11/android-recipe-1-image-with-rounded-corners/ | ||
public class RoundedTransformation implements com.squareup.picasso.Transformation { | ||
private final int radius; | ||
private final int margin; // dp | ||
|
||
// radius is corner radii in dp | ||
// margin is the board in dp | ||
public RoundedTransformation(final int radius, final int margin) { | ||
this.radius = radius; | ||
this.margin = margin; | ||
} | ||
|
||
@Override | ||
public Bitmap transform(final 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(), 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"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters