package com.assistne.icondottextview;

import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.annotation.ColorInt;

/**
 * Created by assistne on 17/1/20.
 */
// TODO: 17/1/20 BoringLayout计算文本长度
// TODO: 17/1/20 限制文本长度, 过长省略
// TODO: 17/1/20 文本改变的情况

public class TextConfig {

    private static final int DEFAULT_SIZE = 10;
    @ColorInt
    private static final int DEFAULT_COLOR = Color.RED;

    int size = DEFAULT_SIZE;
    @ColorInt int color = DEFAULT_COLOR;
    String text;

    public TextConfig(TypedArray typedArray) {
        if (typedArray != null) {
            size = typedArray.getDimensionPixelSize(R.styleable.IconDotTextView_dot_size, DEFAULT_SIZE);
            color = typedArray.getColor(R.styleable.IconDotTextView_dot_color, DEFAULT_COLOR);
            text = typedArray.getString(R.styleable.IconDotTextView_dot_text);
        }
    }

    public TextConfig(String text, int size, @ColorInt int color) {
        this.text = text;
        this.size = size;
        this.color = color;
    }

    public int getWidth() {
        return 100;
    }

    public int getHeight() {
        return 50;
    }
}

@@ -121,35 +121,190 @@
 oid.
-support.annotation.ColorInt
+graphics.Paint;%0Aimport android.support.annotation.ColorInt;%0Aimport android.text.Layout;%0Aimport android.text.StaticLayout;%0Aimport android.text.TextPaint;%0Aimport android.text.TextUtils
 ;%0A%0A/
@@ -461,16 +461,34 @@
 tConfig 
+implements Config 
 %7B%0A%0A    p
@@ -526,18 +526,18 @@
 _SIZE = 
-10
+36
 ;%0A    @C
@@ -604,93 +604,248 @@
 ED;%0A
-%0A    int size = DEFAULT_SIZE;%0A    @ColorInt int color = DEFAULT_COLOR;%0A    String tex
+    private static final int DEAFULT_MAX_WIDTH = 400;%0A%0A    int size = DEFAULT_SIZE;%0A    int maxWidth = DEAFULT_MAX_WIDTH;%0A    @ColorInt int color = DEFAULT_COLOR;%0A    String text;%0A%0A    private TextPaint mTextPaint;%0A    private Layout mLayou
 t;%0A%0A
@@ -1214,16 +1214,32 @@
       %7D%0A
+        init();%0A
     %7D%0A%0A 
@@ -1393,38 +1393,638 @@
     
-%7D%0A%0A    public int getWidth() %7B
+    init();%0A    %7D%0A%0A    private void init() %7B%0A        initPaint();%0A        initLayout();%0A    %7D%0A%0A    private void initPaint() %7B%0A        mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);%0A        mTextPaint.setColor(color);%0A        mTextPaint.setTextSize(size);%0A    %7D%0A%0A    private void initLayout() %7B%0A        if (!TextUtils.isEmpty(text)) %7B%0A            mLayout = new StaticLayout(text, mTextPaint, 200, Layout.Alignment.ALIGN_CENTER, 1f, 0f, true);%0A        %7D%0A    %7D%0A%0A%0A    public int getWidth() %7B%0A//        int desiredWidth = (int) Math.ceil(Layout.getDesiredWidth(text, mTextPaint));%0A//        return Math.min(desiredWidth, maxWidth);
 %0A   

move layout into TextConfig