Last active
November 16, 2018 18:41
-
-
Save therealak12/d3859daadc7bfeacc567468af40e254e to your computer and use it in GitHub Desktop.
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
import android.graphics.Canvas; | |
import android.graphics.Color; | |
import android.graphics.ColorFilter; | |
import android.graphics.CornerPathEffect; | |
import android.graphics.Paint; | |
import android.graphics.Path; | |
import android.graphics.Rect; | |
import android.graphics.drawable.Drawable; | |
import android.support.annotation.NonNull; | |
import android.support.annotation.Nullable; | |
public class CustomMarkerInfoWindowBackground extends Drawable { | |
private Path path = new Path(); | |
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); | |
public CustomMarkerInfoWindowBackground(int paintColor) { | |
paint.setColor(paintColor); | |
paint.setStrokeJoin(Paint.Join.ROUND); | |
paint.setStrokeCap(Paint.Cap.ROUND); | |
paint.setPathEffect(new CornerPathEffect(12)); | |
} | |
@Override | |
public void draw(@NonNull Canvas canvas) { | |
canvas.drawPath(path, paint); | |
} | |
@Override | |
public void setAlpha(int alpha) { | |
paint.setAlpha(alpha); | |
} | |
@Override | |
public void setColorFilter(@Nullable ColorFilter colorFilter) { | |
paint.setColorFilter(colorFilter); | |
} | |
@Override | |
public int getOpacity() { | |
return paint.getAlpha(); | |
} | |
@Override | |
protected void onBoundsChange(Rect bounds) { | |
super.onBoundsChange(bounds); | |
computeDrawable(bounds); | |
invalidateSelf(); | |
} | |
private void computeDrawable(Rect bounds) { | |
path.reset(); | |
path = createDrawable(bounds); | |
} | |
private Path createDrawable(Rect bounds) { | |
Path drawablePath = new Path(); | |
drawablePath.moveTo(bounds.centerX(), bounds.bottom); | |
drawablePath.lineTo(bounds.left, (int) (bounds.bottom * 0.8)); | |
drawablePath.lineTo(bounds.left, bounds.top); | |
drawablePath.lineTo(bounds.right, bounds.top); | |
drawablePath.lineTo(bounds.right, (int) (bounds.bottom * 0.8)); | |
drawablePath.lineTo(bounds.centerX(), bounds.bottom); | |
drawablePath.close(); | |
return drawablePath; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment