@Test public void handle_string() throws Exception { String CENTER = "center"; String CENTER_HORIZONTAL = "center_horizontal"; String CENTER_VERTICAL = "center_vertical"; String LEFT = "left"; String RIGHT = "right"; String TOP = "top"; String BOTTOM = "bottom"; String START = "start"; String END = "end"; Map<String, Integer> sGravityMap = new HashMap<>(); sGravityMap.put(CENTER, Gravity.CENTER); sGravityMap.put(CENTER_HORIZONTAL, Gravity.CENTER_HORIZONTAL); sGravityMap.put(CENTER_VERTICAL, Gravity.CENTER_VERTICAL); sGravityMap.put(LEFT, Gravity.LEFT); sGravityMap.put(RIGHT, Gravity.RIGHT); sGravityMap.put(TOP, Gravity.TOP); sGravityMap.put(BOTTOM, Gravity.BOTTOM); sGravityMap.put(START, Gravity.START); sGravityMap.put(END, Gravity.END); for (final Map.Entry<String, Integer> entry : sGravityMap.entrySet()) { System.out.print("\nGravityAttributeProcessorTest:handle_string() when gravity : '" + entry.getKey() + "'\n"); AttributeProcessor processor = new GravityAttributeProcessor() { @Override public void setGravity(View view, @Gravity int gravity) { assertThat(gravity, is(entry.getValue())); } }; processor.handleValue(null, new Primitive(entry.getKey())); } }
@Override public void handleValue(V view, Value value) { int gravity = android.view.Gravity.NO_GRAVITY; if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { gravity = value.getAsInt(); } else if (value.isPrimitive()) { gravity = ParseHelper.parseGravity(value.getAsString()); } setGravity(view, gravity); }
GravityAttributeProcessor extends AttributeProcessor<V> { @Override public void handleValue(V view, Value value) { int gravity = android.view.Gravity.NO_GRAVITY; if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { gravity = value.getAsInt(); } else if (value.isPrimitive()) { gravity = ParseHelper.parseGravity(value.getAsString()); } setGravity(view, gravity); } }
GravityAttributeProcessor extends AttributeProcessor<V> { @Override public void handleValue(V view, Value value) { int gravity = android.view.Gravity.NO_GRAVITY; if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { gravity = value.getAsInt(); } else if (value.isPrimitive()) { gravity = ParseHelper.parseGravity(value.getAsString()); } setGravity(view, gravity); }  }
GravityAttributeProcessor extends AttributeProcessor<V> { @Override public void handleValue(V view, Value value) { int gravity = android.view.Gravity.NO_GRAVITY; if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { gravity = value.getAsInt(); } else if (value.isPrimitive()) { gravity = ParseHelper.parseGravity(value.getAsString()); } setGravity(view, gravity); }  @Override void handleValue(V view, Value value); @Override void handleResource(V view, Resource resource); @Override void handleAttributeResource(V view, AttributeResource attribute); @Override void handleStyleResource(V view, StyleResource style); abstract void setGravity(V view, @Gravity int gravity); @Override Value compile(@Nullable Value value, Context context); }
GravityAttributeProcessor extends AttributeProcessor<V> { @Override public void handleValue(V view, Value value) { int gravity = android.view.Gravity.NO_GRAVITY; if (value.isPrimitive() && value.getAsPrimitive().isNumber()) { gravity = value.getAsInt(); } else if (value.isPrimitive()) { gravity = ParseHelper.parseGravity(value.getAsString()); } setGravity(view, gravity); }  @Override void handleValue(V view, Value value); @Override void handleResource(V view, Resource resource); @Override void handleAttributeResource(V view, AttributeResource attribute); @Override void handleStyleResource(V view, StyleResource style); abstract void setGravity(V view, @Gravity int gravity); @Override Value compile(@Nullable Value value, Context context); static final Primitive NO_GRAVITY; }