1 package org.robolectric.shadows; 2 3 import android.graphics.Typeface; 4 import org.robolectric.annotation.Implements; 5 import org.robolectric.shadows.ShadowTypeface.Picker; 6 7 /** Base class for {@link ShadowTypeface} classes. */ 8 @Implements(value = Typeface.class, shadowPicker = Picker.class) 9 public abstract class ShadowTypeface { 10 11 /** 12 * Returns the font description. 13 * 14 * @return Font description. 15 */ getFontDescription()16 public abstract FontDesc getFontDescription(); 17 18 /** Contains data about a font. */ 19 public static class FontDesc { 20 public final String familyName; 21 public final int style; 22 FontDesc(String familyName, int style)23 public FontDesc(String familyName, int style) { 24 this.familyName = familyName; 25 this.style = style; 26 } 27 28 @Override equals(Object o)29 public boolean equals(Object o) { 30 if (this == o) { 31 return true; 32 } 33 if (!(o instanceof FontDesc)) { 34 return false; 35 } 36 37 FontDesc fontDesc = (FontDesc) o; 38 39 if (style != fontDesc.style) { 40 return false; 41 } 42 if (familyName != null 43 ? !familyName.equals(fontDesc.familyName) 44 : fontDesc.familyName != null) { 45 return false; 46 } 47 48 return true; 49 } 50 51 @Override hashCode()52 public int hashCode() { 53 int result = familyName != null ? familyName.hashCode() : 0; 54 result = 31 * result + style; 55 return result; 56 } 57 getFamilyName()58 public String getFamilyName() { 59 return familyName; 60 } 61 getStyle()62 public int getStyle() { 63 return style; 64 } 65 } 66 67 /** Shadow picker for {@link Typeface}. */ 68 public static final class Picker extends GraphicsShadowPicker<Object> { Picker()69 public Picker() { 70 super(ShadowLegacyTypeface.class, ShadowNativeTypeface.class); 71 } 72 } 73 } 74