@@ -0,0 +1,2458 @@
+package cn.com.open.mooc.common.view;%0A%0Aimport android.content.Context;%0Aimport android.content.res.TypedArray;%0Aimport android.graphics.Canvas;%0Aimport android.graphics.Paint;%0Aimport android.graphics.Path;%0Aimport android.graphics.PorterDuff;%0Aimport android.graphics.PorterDuffXfermode;%0Aimport android.graphics.RectF;%0Aimport android.util.AttributeSet;%0Aimport android.util.TypedValue;%0Aimport android.widget.ImageView;%0A%0Aimport cn.com.open.mooc.R;%0A%0A/**%0A * %E5%8F%AA%E6%9C%89%E4%B8%8A%E6%96%B9%E6%98%AF%E5%9C%86%E8%A7%92%E7%9A%84%E5%9B%BE%E7%89%87%E6%8E%A7%E4%BB%B6%0A *%0A * Created by like on 2017/2/9.%0A */%0A%0Apublic class TopCornerImageView extends ImageView %7B%0A%0A    int cornerSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 6, getResources().getDisplayMetrics());%0A    private Path shapePath;%0A%0A    public TopCornerImageView(Context context) %7B%0A        this(context, null);%0A    %7D%0A%0A    public TopCornerImageView(Context context, AttributeSet attrs) %7B%0A        this(context, attrs, 0);%0A    %7D%0A    Paint paint;%0A    public TopCornerImageView(Context context, AttributeSet attrs, int defStyleAttr) %7B%0A        super(context, attrs, defStyleAttr);%0A        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TopCornerImageView, defStyleAttr, 0);%0A        cornerSize = a.getDimensionPixelSize(R.styleable.TopCornerImageView_corner_size, cornerSize);%0A        paint = new Paint();%0A        paint.setColor(0xFF000000);%0A        paint.setAntiAlias(true);%0A        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_IN));%0A    %7D%0A%0A    @Override%0A    protected void onSizeChanged(int w, int h, int oldw, int oldh) %7B%0A        super.onSizeChanged(w, h, oldw, oldh);%0A        if (w == oldw && h == oldh)%0A            return;%0A        if (shapePath == null)%0A            shapePath = new Path();%0A%0A        shapePath.moveTo(0, h);%0A        shapePath.lineTo(0, cornerSize);%0A        shapePath.arcTo(new RectF(0, 0, cornerSize*2, cornerSize*2), 180, 90);%0A        shapePath.lineTo(w - cornerSize, 0);%0A        shapePath.arcTo(new RectF(w - cornerSize*2, 0, w, cornerSize*2), 90, 270);%0A        shapePath.lineTo(w, h);%0A        shapePath.close();%0A    %7D%0A%0A    @Override%0A    protected void onDraw(Canvas canvas) %7B%0A        if (cornerSize * 2 %3E getWidth() %7C%7C cornerSize*2 %3EgetHeight()) %7B%0A            super.onDraw(canvas);%0A            return;%0A        %7D%0A        int sc = canvas.saveLayer(0,0,getWidth(),getHeight(), null, Canvas.ALL_SAVE_FLAG);%0A        super.onDraw(canvas);%0A        // %E7%94%BB%E5%87%BA%E5%9C%86%E8%A7%92%0A        canvas.drawPath(shapePath, paint);%0A        canvas.restoreToCount(sc);%0A    %7D%0A%7D%0A

Add files via upload