Skip to content

Commit

Permalink
add support for double values
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianTerhorst committed Jun 6, 2016
1 parent 0d71d93 commit f8c5f2f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Created by fabianterhorst on 14.05.16.
*/
//@Layouts(all = true/*, exclude = {R.layout.item_sample}*/)
@Layouts(ids = {R.layout.activity_main, R.layout.item_sample})
@Layouts(ids = {R.layout.activity_main, R.layout.item_sample, R.layout.card_view})
//@Layouts(layouts = {"activity_main"})
//@Layouts
public class AppLayouts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ public LayoutAttribute onConvertLayoutAttributeValue(String attributeValue, Stri
String styleAttribute = "android.R.style." + style;
return onConvertLayoutAttribute(attribute, styleAttribute, attributeName, false);
} else if ((attribute.endsWith("dp") || attribute.endsWith("dip")) && isNumber(attribute.replace("dip", "").replace("dp", ""))) {
return onConvertLayoutAttribute(attribute, "(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, " + attribute.replace("dip", "").replace("dp", "") + ", getResources().getDisplayMetrics())", attributeName, false);
return onConvertLayoutAttribute(attribute, "(int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, " + attribute.replace("dip", "").replace("dp", "") + "f, getResources().getDisplayMetrics())", attributeName, false);
} else if (attribute.equals("false") || attribute.equals("true")) {
return onConvertLayoutAttribute(attribute, attributeName, false);
} else if (attribute.endsWith("sp") && isNumber(attribute.replace("sp", ""))) {
return onConvertLayoutAttribute(attribute, "(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, " + attribute.replace("sp", "") + ", getResources().getDisplayMetrics())", attributeName, false);
return onConvertLayoutAttribute(attribute, "(int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, " + attribute.replace("sp", "") + "f, getResources().getDisplayMetrics())", attributeName, false);
} else if (isNumber(attribute)) {
return onConvertLayoutAttribute(attributeValue, attributeName, false);
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public String attribute(String name, Object value) {

private boolean isNumber(Object text) {
try {
Integer.parseInt(String.valueOf(text));
Double.parseDouble(String.valueOf(text));
return true;
} catch (NumberFormatException ignore) {
return false;
Expand Down

0 comments on commit f8c5f2f

Please sign in to comment.