1package com.xtremelabs.robolectric.shadows;
2
3import android.text.Html;
4import android.text.Spanned;
5import com.xtremelabs.robolectric.internal.Implementation;
6import com.xtremelabs.robolectric.internal.Implements;
7
8@SuppressWarnings({"UnusedDeclaration"})
9@Implements(Html.class)
10public class ShadowHtml {
11
12    @Implementation
13    public static Spanned fromHtml(String source) {
14		if (source == null) {
15			/*
16			 * Mimic the behavior of the real fromHtml() method. It uses a
17			 * StringReader that throws a NullPointerException when a null
18			 * string is passed in.
19			 */
20			throw new NullPointerException();
21		}
22        return new SpannedThatActsLikeString(source);
23    }
24
25    private static class SpannedThatActsLikeString implements Spanned {
26        String source;
27
28        private SpannedThatActsLikeString(String source) {
29            this.source = source;
30        }
31
32        @Override
33        public <T> T[] getSpans(int start, int end, Class<T> type) {
34            return null;
35        }
36
37        @Override
38        public int getSpanStart(Object tag) {
39            return 0;
40        }
41
42        @Override
43        public int getSpanEnd(Object tag) {
44            return 0;
45        }
46
47        @Override
48        public int getSpanFlags(Object tag) {
49            return 0;
50        }
51
52        @Override
53        public int nextSpanTransition(int start, int limit, Class type) {
54            return 0;
55        }
56
57        @Override
58        public int length() {
59            return source.length();
60        }
61
62        @Override
63        public char charAt(int i) {
64            return source.charAt(i);
65        }
66
67        @Override
68        public CharSequence subSequence(int i, int i1) {
69            return null;
70        }
71
72        @Override
73        public String toString() {
74            return source;
75        }
76
77        @Override
78        public boolean equals(Object o) {
79            return source.equals(o);
80        }
81
82        @Override
83        public int hashCode() {
84            return source != null ? source.hashCode() : 0;
85        }
86    }
87}
88