.setTypeface(Typeface.DEFAULT_BOLD) // Override the normal Typeface .setTextSize(28f) // default size is 24 .setTypeface(Typeface.create("serif", Typeface.BOLD_ITALIC)) .setTextSize(32f) // default size is 24 .setTextColor(new Color(0f, 1f, 1f, 0.70f)) // cyan, with 7% opacity
@Test public void testSetTypeface_Null() throws Exception { TextAttributes attributes = new TextAttributes(); attributes.setTypeface(null); assertEquals(null, attributes.typeface); }
@Test public void testSetTypeface() throws Exception { TextAttributes attributes = new TextAttributes(); Typeface typeface = Typeface.defaultFromStyle(Typeface.NORMAL); attributes.setTypeface(typeface); assertEquals(typeface, attributes.typeface); }
@Test public void testConstructor_Copy() throws Exception { TextAttributes attributes = new TextAttributes(); attributes.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); TextAttributes copy = new TextAttributes(attributes); assertNotNull(copy); assertEquals(attributes, copy); // Ensure we made a deep copy of the colors assertTrue(copy.textColor != attributes.textColor); assertTrue(copy.textOffset != attributes.textOffset); // Ensure we copied the typeface by reference assertTrue(copy.typeface == attributes.typeface); }
@Test public void testHashCode() throws Exception { // Three differing sets of attributes TextAttributes a = new TextAttributes(); TextAttributes b = new TextAttributes(); TextAttributes c = new TextAttributes(); b.setTextColor(new Color(0, 0, 0, 0)); c.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL)); int aHash = a.hashCode(); int bHash = b.hashCode(); int cHash = c.hashCode(); assertNotEquals("a hash vs b hash", bHash, aHash); assertNotEquals("b hash vs c hash", cHash, bHash); assertNotEquals("c hash vs a hash", aHash, cHash); }
attrs.setTypeface(Typeface.DEFAULT_BOLD); // system default bold typeface attrs.setTextSize(48); // 48 screen pixels label = new Label(new Position(38.907192, -77.036871, 0), "Washington", attrs);