// Path: app/src/main/java/org/houxg/leamonax/utils/DisplayUtils.java
// public class DisplayUtils {
//     public static int dp2px(float dp) {
//         final float scale = Leamonax.getContext().getResources().getDisplayMetrics().density;
//         return (int) (dp * scale + 0.5f);
//     }
// 
//     public static int px2dp(float px) {
//         final float scale = Leamonax.getContext().getResources().getDisplayMetrics().density;
//         return (int) (px / scale + 0.5f);
//     }
// }


import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.style.ReplacementSpan;
import org.houxg.leamonax.utils.DisplayUtils;
package org.houxg.leamonax.widget;




public class RoundedRectBackgroundSpan extends ReplacementSpan {

    private int mColor;
    private float mRadius;
    private int padding = 10;
    private RectF mTempRect = new RectF();

    public RoundedRectBackgroundSpan(int color, float radius) {
        this(color, radius, 0);
    }

    public RoundedRectBackgroundSpan(int mColor, float mRadius, int padding) {
        this.mColor = mColor;
        this.mRadius = mRadius;
        this.padding = padding;
    }

    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        return Math.round(paint.measureText(text, start, end) + padding * 2);
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        mTempRect.set(x, top, x + paint.measureText(text, start, end) + padding * 2, bottom);
// Path: app/src/main/java/org/houxg/leamonax/utils/DisplayUtils.java
// public class DisplayUtils {
//     public static int dp2px(float dp) {
//         final float scale = Leamonax.getContext().getResources().getDisplayMetrics().density;
//         return (int) (dp * scale + 0.5f);
//     }
// 
//     public static int px2dp(float px) {
//         final float scale = Leamonax.getContext().getResources().getDisplayMetrics().density;
//         return (int) (px / scale + 0.5f);
//     }
// }


// Path: app/src/main/java/org/houxg/leamonax/widget/RoundedRectBackgroundSpan.java
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.text.style.ReplacementSpan;
import org.houxg.leamonax.utils.DisplayUtils;

package org.houxg.leamonax.widget;




public class RoundedRectBackgroundSpan extends ReplacementSpan {

    private int mColor;
    private float mRadius;
    private int padding = 10;
    private RectF mTempRect = new RectF();

    public RoundedRectBackgroundSpan(int color, float radius) {
        this(color, radius, 0);
    }

    public RoundedRectBackgroundSpan(int mColor, float mRadius, int padding) {
        this.mColor = mColor;
        this.mRadius = mRadius;
        this.padding = padding;
    }

    @Override
    public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
        return Math.round(paint.measureText(text, start, end) + padding * 2);
    }

    @Override
    public void draw(Canvas canvas, CharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint) {
        mTempRect.set(x, top, x + paint.measureText(text, start, end) + padding * 2, bottom);
        float offsetY = DisplayUtils.dp2px(2);