package com.xtremelabs.droidsugar.view;

import android.text.style.URLSpan;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

@SuppressWarnings({"ALL"})
public class FakeTextView extends FakeView {
    private CharSequence text;
    public CompoundDrawables compoundDrawablesWithIntrinsicBounds;
    public int textResourceId = UNINITIALIZED_ATTRIBUTE;
    public int textColorResourceId = UNINITIALIZED_ATTRIBUTE;
    public int textSize = UNINITIALIZED_ATTRIBUTE;

    public FakeTextView(TextView view) {
        super(view);
    }

    public void setText(CharSequence text) {
        this.textResourceId = UNINITIALIZED_ATTRIBUTE;
        this.text = text;
    }

    public void setText(int textResourceId) {
        this.textResourceId = textResourceId;
        this.text = getResources().getText(textResourceId);
    }

    public CharSequence getText() {
        return text;
    }

    public void setTextColor(int color) {
        textColorResourceId = color;
    }

    public void setTextSize(float size) {
        textSize = (int) size;
    }

    public URLSpan[] getUrls() {
        String[] words = text.toString().split("\\s+");
        List<URLSpan> urlSpans = new ArrayList<URLSpan>();
        for (String word : words) {
            if (word.startsWith("http://")) {
                urlSpans.add(new URLSpan(word));
            }
        }
        return urlSpans.toArray(new URLSpan[urlSpans.size()]);
    }

    public void setCompoundDrawablesWithIntrinsicBounds(int left, int top, int right, int bottom) {
        compoundDrawablesWithIntrinsicBounds = new CompoundDrawables(left, top , right, bottom);
    }

    public static class CompoundDrawables {
        public int left;
        public int top;
        public int right;
        public int bottom;

        public CompoundDrawables(int left, int top, int right, int bottom) {
            this.left = left;
            this.top = top;
            this.right = right;
            this.bottom = bottom;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            CompoundDrawables that = (CompoundDrawables) o;

            if (bottom != that.bottom) return false;
            if (left != that.left) return false;
            if (right != that.right) return false;
            if (top != that.top) return false;

            return true;
        }

        @Override
        public int hashCode() {
            int result = left;
            result = 31 * result + top;
            result = 31 * result + right;
            result = 31 * result + bottom;
            return result;
        }

        @Override
        public String toString() {
            return "CompoundDrawables{" +
                    "left=" + left +
                    ", top=" + top +
                    ", right=" + right +
                    ", bottom=" + bottom +
                    '}';
        }
    }
}

@@ -69,16 +69,50 @@
 RLSpan;%0A
+import android.text.util.Linkify;%0A
 import a
@@ -527,16 +527,87 @@
 TRIBUTE;
+%0A    public boolean autoLinkPhoneNumbers;%0A    private int autoLinkMask;
 %0A%0A    pu
@@ -1556,32 +1556,187 @@
 ize()%5D);%0A    %7D%0A%0A
+    public final void setAutoLinkMask(int mask) %7B%0A        autoLinkMask = mask;%0A%0A        autoLinkPhoneNumbers = (mask & Linkify.PHONE_NUMBERS) != 0;%0A    %7D%0A%0A
     public void 

Add TextView.setAutoLinkMask fake.