FeedBackPointDrawable.kt 1.88 KB
Newer Older
ydl committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
package com.yidianling.user.mine.view

import android.annotation.SuppressLint
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.ColorFilter
import android.graphics.Paint
import android.graphics.drawable.Drawable
import com.yidianling.common.tools.RxImageTool

/**
 * @author jiucheng
 * @描述:自定义圆点绘制
 * @Copyright Copyright (c) 2018
 * @Company 壹点灵
 * @date 2018/12/18
 */
class FeedBackPointDrawable : Drawable {
    /**
     * 边框是否在在左边
     */
    private var isLeft = false
    /**
     * 用于边框和背景的画笔
     */
    private var paint: Paint? = null
    private var otherPaint: Paint? = null

    constructor(isLeft: Boolean) : super() {
        this.isLeft = isLeft
        initArc()
    }


    private fun initArc() {
        paint = Paint()
        paint!!.isAntiAlias = true
        paint!!.color = Color.parseColor("#F0F0F0")
        paint!!.style = Paint.Style.FILL
        otherPaint = Paint()
        otherPaint!!.isAntiAlias = true
        otherPaint!!.color = Color.parseColor("#E0E0E0")
        otherPaint!!.style = Paint.Style.STROKE
        otherPaint!!.strokeWidth = RxImageTool.dp2px(0.5f).toFloat()
    }

    @SuppressLint("NewApi")
    override fun draw(canvas: Canvas?) {
        canvas!!.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.exactCenterX(), paint)
        if (isLeft) {
            canvas!!.drawArc(0.5f, 0.5f, bounds.exactCenterX() * 2-0.5f, bounds.exactCenterY() * 2-0.5f, -90f, 180f, false, otherPaint)
        } else {
            canvas!!.drawArc(0.5f, 0.5f, bounds.exactCenterX() * 2-0.5f, bounds.exactCenterY() * 2-0.5f, 90f, 180f, false, otherPaint)
        }
    }

    override fun setAlpha(alpha: Int) {
    }

    @SuppressLint("WrongConstant")
    override fun getOpacity(): Int {
        return 0
    }

    override fun setColorFilter(colorFilter: ColorFilter?) {
    }
}