forked from youth5201314/banner
-
Notifications
You must be signed in to change notification settings - Fork 0
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
d11f1d0
commit 67661ea
Showing
21 changed files
with
300 additions
and
62 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
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
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
52 changes: 52 additions & 0 deletions
52
app/src/main/java/com/test/banner/ui/GlideRoundTransform.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,52 @@ | ||
package com.test.banner.ui; | ||
|
||
|
||
import android.content.Context; | ||
import android.content.res.Resources; | ||
import android.graphics.Bitmap; | ||
import android.graphics.BitmapShader; | ||
import android.graphics.Canvas; | ||
import android.graphics.Paint; | ||
import android.graphics.RectF; | ||
|
||
import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool; | ||
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation; | ||
|
||
public class GlideRoundTransform extends BitmapTransformation { | ||
|
||
private static float radius = 0f; | ||
|
||
public GlideRoundTransform(Context context) { | ||
this(context, 4); | ||
} | ||
|
||
public GlideRoundTransform(Context context, int dp) { | ||
super(context); | ||
this.radius = Resources.getSystem().getDisplayMetrics().density * dp; | ||
} | ||
|
||
@Override protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) { | ||
return roundCrop(pool, toTransform); | ||
} | ||
|
||
private static Bitmap roundCrop(BitmapPool pool, Bitmap source) { | ||
if (source == null) return null; | ||
|
||
Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); | ||
if (result == null) { | ||
result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); | ||
} | ||
|
||
Canvas canvas = new Canvas(result); | ||
Paint paint = new Paint(); | ||
paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP)); | ||
paint.setAntiAlias(true); | ||
RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight()); | ||
canvas.drawRoundRect(rectF, radius, radius, paint); | ||
return result; | ||
} | ||
|
||
@Override public String getId() { | ||
return getClass().getName() + Math.round(radius); | ||
} | ||
} |
124 changes: 124 additions & 0 deletions
124
app/src/main/java/com/test/banner/ui/RoundAngleImageView.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,124 @@ | ||
package com.test.banner.ui; | ||
|
||
|
||
import android.content.Context; | ||
import android.content.res.TypedArray; | ||
import android.graphics.Bitmap; | ||
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.Paint; | ||
import android.graphics.Path; | ||
import android.graphics.PorterDuff; | ||
import android.graphics.PorterDuffXfermode; | ||
import android.graphics.RectF; | ||
import android.util.AttributeSet; | ||
import android.widget.ImageView; | ||
|
||
|
||
public class RoundAngleImageView extends ImageView { | ||
|
||
private Paint paint; | ||
private int roundWidth = 5; | ||
private int roundHeight = 5; | ||
private Paint paint2; | ||
|
||
public RoundAngleImageView(Context context, AttributeSet attrs, int defStyle) { | ||
super(context, attrs, defStyle); | ||
init(context, attrs); | ||
} | ||
|
||
public RoundAngleImageView(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
init(context, attrs); | ||
} | ||
|
||
public RoundAngleImageView(Context context) { | ||
super(context); | ||
init(context, null); | ||
} | ||
|
||
private void init(Context context, AttributeSet attrs) { | ||
paint = new Paint(); | ||
paint.setColor(Color.WHITE); | ||
paint.setAntiAlias(true); | ||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); | ||
paint2 = new Paint(); | ||
paint2.setXfermode(null); | ||
} | ||
|
||
@Override | ||
public void draw(Canvas canvas) { | ||
Bitmap bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Bitmap.Config.ARGB_8888); | ||
Canvas canvas2 = new Canvas(bitmap); | ||
super.draw(canvas2); | ||
drawLiftUp(canvas2); | ||
drawRightUp(canvas2); | ||
drawLiftDown(canvas2); | ||
drawRightDown(canvas2); | ||
canvas.drawBitmap(bitmap, 0, 0, paint2); | ||
bitmap.recycle(); | ||
} | ||
|
||
private void drawLiftUp(Canvas canvas) { | ||
Path path = new Path(); | ||
path.moveTo(0, roundHeight); | ||
path.lineTo(0, 0); | ||
path.lineTo(roundWidth, 0); | ||
path.arcTo(new RectF( | ||
0, | ||
0, | ||
roundWidth*2, | ||
roundHeight*2), | ||
-90, | ||
-90); | ||
path.close(); | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
private void drawLiftDown(Canvas canvas) { | ||
Path path = new Path(); | ||
path.moveTo(0, getHeight()-roundHeight); | ||
path.lineTo(0, getHeight()); | ||
path.lineTo(roundWidth, getHeight()); | ||
path.arcTo(new RectF( | ||
0, | ||
getHeight()-roundHeight*2, | ||
0+roundWidth*2, | ||
getHeight()), | ||
90, | ||
90); | ||
path.close(); | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
private void drawRightDown(Canvas canvas) { | ||
Path path = new Path(); | ||
path.moveTo(getWidth()-roundWidth, getHeight()); | ||
path.lineTo(getWidth(), getHeight()); | ||
path.lineTo(getWidth(), getHeight()-roundHeight); | ||
path.arcTo(new RectF( | ||
getWidth()-roundWidth*2, | ||
getHeight()-roundHeight*2, | ||
getWidth(), | ||
getHeight()), 0, 90); | ||
path.close(); | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
private void drawRightUp(Canvas canvas) { | ||
Path path = new Path(); | ||
path.moveTo(getWidth(), roundHeight); | ||
path.lineTo(getWidth(), 0); | ||
path.lineTo(getWidth()-roundWidth, 0); | ||
path.arcTo(new RectF( | ||
getWidth()-roundWidth*2, | ||
0, | ||
getWidth(), | ||
0+roundHeight*2), | ||
-90, | ||
90); | ||
path.close(); | ||
canvas.drawPath(path, paint); | ||
} | ||
|
||
} |
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
Oops, something went wrong.