.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 testSetTextColor() throws Exception { TextAttributes attributes = new TextAttributes(); Color black = new Color(0, 0, 0, 1); attributes.setTextColor(black); // Verify that the object is an equivalent deep copy. assertEquals(black, attributes.textColor); assertTrue(black != attributes.textColor); }
/** * Test identical cache keys are equal and generate identical hash codes. The {@Typeface} class setting is ignored * as the Android environment is required for non-null values. This has the effect of testing properties set to null * during equivalency testing. */ @Test public void testIdenticalWithAttributes() { // Common Text Attributes TextAttributes attrs = new TextAttributes(); attrs.setEnableOutline(true); attrs.setOutlineColor(new Color(0.5f, 0.2f, 0.3f, 1)); attrs.setOutlineWidth(15); attrs.setTextColor(new Color(1, 1, 0.2f, 1)); attrs.setTextSize(90); // Common Text String text = "Testing"; // Cache Key 1 RenderContext.TextCacheKey textCacheKeyOne = new RenderContext.TextCacheKey().set(text, attrs); // Cache Key 2 RenderContext.TextCacheKey textCacheKeyTwo = new RenderContext.TextCacheKey().set(text, attrs); assertTrue("TextCacheKey with attributes equals", textCacheKeyOne.equals(textCacheKeyTwo)); assertTrue("TextCacheKey with attributes hashcode", textCacheKeyOne.hashCode() == textCacheKeyTwo.hashCode()); }
@Test public void testModifiedAttrs() { // Common Text Attributes TextAttributes attrs = new TextAttributes(); attrs.setEnableOutline(true); attrs.setOutlineColor(new Color(0.5f, 0.2f, 0.3f, 1)); attrs.setOutlineWidth(15); attrs.setTextColor(new Color(1, 1, 0.2f, 1)); attrs.setTextSize(90); // Common Text String text = "Testing"; // Cache Key 1 RenderContext.TextCacheKey textCacheKeyOne = new RenderContext.TextCacheKey().set(text, attrs); // Modify color property Color outlineColor = attrs.getOutlineColor().set(1, 1, 0.3f, 1); attrs.setOutlineColor(outlineColor); // Cache Key 2 RenderContext.TextCacheKey textCacheKeyTwo = new RenderContext.TextCacheKey().set(text, attrs); assertFalse("TextCacheKey modified attributes equals", textCacheKeyOne.equals(textCacheKeyTwo)); assertFalse("TextCacheKey modified attributes hashcode", textCacheKeyOne.hashCode() == textCacheKeyTwo.hashCode()); } }
@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.setTextColor(new Color(0, 0, 0, 1)); // black text via r,g,b,a attrs.setOutlineColor(new Color(1, 1, 1, 1)); // white outline via r,g,b,a attrs.setOutlineWidth(5); // thicken the white outline