Skip to content

Commit

Permalink
Add custom outline provider to support elevation
Browse files Browse the repository at this point in the history
  • Loading branch information
hdodenhof committed Mar 13, 2017
1 parent 7fd3573 commit 4fdd9db
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,23 @@
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.Shader;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewOutlineProvider;
import android.widget.ImageView;

public class CircleImageView extends ImageView {
Expand Down Expand Up @@ -104,6 +110,10 @@ private void init() {
super.setScaleType(SCALE_TYPE);
mReady = true;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setOutlineProvider(new OutlineProvider());
}

if (mSetupPending) {
setup();
mSetupPending = false;
Expand Down Expand Up @@ -435,4 +445,16 @@ private void updateShaderMatrix() {
mBitmapShader.setLocalMatrix(mShaderMatrix);
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private class OutlineProvider extends ViewOutlineProvider {

@Override
public void getOutline(View view, Outline outline) {
Rect bounds = new Rect();
mBorderRect.roundOut(bounds);
outline.setRoundRect(bounds, bounds.width() / 2.0f);
}

}

}

0 comments on commit 4fdd9db

Please sign in to comment.