1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.text.Html;
4 import android.text.Spanned;
5 import com.xtremelabs.robolectric.internal.Implementation;
6 import com.xtremelabs.robolectric.internal.Implements;
7 
8 @SuppressWarnings({"UnusedDeclaration"})
9 @Implements(Html.class)
10 public class ShadowHtml {
11 
12     @Implementation
fromHtml(String source)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 
SpannedThatActsLikeString(String source)28         private SpannedThatActsLikeString(String source) {
29             this.source = source;
30         }
31 
32         @Override
getSpans(int start, int end, Class<T> type)33         public <T> T[] getSpans(int start, int end, Class<T> type) {
34             return null;
35         }
36 
37         @Override
getSpanStart(Object tag)38         public int getSpanStart(Object tag) {
39             return 0;
40         }
41 
42         @Override
getSpanEnd(Object tag)43         public int getSpanEnd(Object tag) {
44             return 0;
45         }
46 
47         @Override
getSpanFlags(Object tag)48         public int getSpanFlags(Object tag) {
49             return 0;
50         }
51 
52         @Override
nextSpanTransition(int start, int limit, Class type)53         public int nextSpanTransition(int start, int limit, Class type) {
54             return 0;
55         }
56 
57         @Override
length()58         public int length() {
59             return source.length();
60         }
61 
62         @Override
charAt(int i)63         public char charAt(int i) {
64             return source.charAt(i);
65         }
66 
67         @Override
subSequence(int i, int i1)68         public CharSequence subSequence(int i, int i1) {
69             return null;
70         }
71 
72         @Override
toString()73         public String toString() {
74             return source;
75         }
76 
77         @Override
equals(Object o)78         public boolean equals(Object o) {
79             return source.equals(o);
80         }
81 
82         @Override
hashCode()83         public int hashCode() {
84             return source != null ? source.hashCode() : 0;
85         }
86     }
87 }
88