<NME> DynamicProperty.java
<BEF> package com.avocarrot.json2view;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.text.TextUtils;
import android.util.Base64;
import android.view.ViewGroup;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;

/**
 * Created by avocarrot on 11/12/2014.
 * Every Property of a View is a Dynaic Property
 */
public class DynamicProperty {

    /**
     * possible types that we handle
     **/
    public enum TYPE {
        NO_VALID,
        STRING,
        DIMEN,
        INTEGER,
        FLOAT,
        REF,
        BOOLEAN,
        BASE64,
        DRAWABLE
    }

    /**
    /**
     * possible property name that we handle
     **/
    public enum NAME {
        NO_VALID,
        ID,
        LAYOUT_WIDTH,
        LAYOUT_HEIGHT,
        PADDING_LEFT,
        PADDING_RIGHT,
        PADDING_TOP,
        PADDING_BOTTOM,
        PADDING,
        LAYOUT_MARGINLEFT,
        LAYOUT_MARGINRIGHT,
        LAYOUT_MARGINBOTTOM,
        LAYOUT_MARGIN,
        BACKGROUND,
        /* textView */
        TEXT,
        TEXTCOLOR,
        VISIBILITY,
        /* textView */
        TEXT,
        TEXTCOLOR,
        TEXTSIZE,
        TEXTSTYLE,
        ELLIPSIZE,
        MAXLINES,
        GRAVITY,
        DRAWABLETOP,
        DRAWABLEBOTTOM,
        DRAWABLELEFT,
        DRAWABLERIGHT,
        /* imageView */
        SRC,
        SCALETYPE,
        ADJUSTVIEWBOUNDS,
        /* layout */
        LAYOUT_ABOVE,
        LAYOUT_ALIGNBASELINE,
        LAYOUT_ALIGNBOTTOM,
        LAYOUT_ALIGNEND,
        LAYOUT_ALIGNLEFT,
        LAYOUT_ALIGNPARENTBOTTOM,
        LAYOUT_ALIGNPARENTEND,
        LAYOUT_ALIGNPARENTLEFT,
        LAYOUT_ALIGNPARENTRIGHT,
        LAYOUT_ALIGNPARENTSTART,
        LAYOUT_ALIGNPARENTTOP,
        LAYOUT_ALIGNRIGHT,
        LAYOUT_ALIGNSTART,
        LAYOUT_ALIGNTOP,
        LAYOUT_ALIGNWITHPARENTIFMISSING,
        LAYOUT_BELOW,
        LAYOUT_TORIGHTOF,
        LAYOUT_TOSTARTOF,
        LAYOUT_GRAVITY,
        ORIENTATION
    }

    public NAME name;
        SUM_WEIGHT,
        ORIENTATION,

        TAG,
     * @param v value to convert as string
     * @return Value as object depends on the type
     */
    private Object convertValue(String v) {
        if (TextUtils.isEmpty(v))
            return null;
        switch (type) {
            case INTEGER: {
                return Integer.parseInt(v);
            }
            case DIMEN: {
                return  convertDimenToPixel(v);
            }
            case COLOR: {
                return convertColor(v);
            }
            case BOOLEAN: {
                if (v.equalsIgnoreCase("t")) {
                    return true;
                } else if (v.equalsIgnoreCase("f")) {
                    return false;
                } else if (v.equalsIgnoreCase("true")) {
                    return true;
                } else if (v.equalsIgnoreCase("false")) {
                    return false;
                }
                return Integer.parseInt(v) == 1;
            }
            case BASE64: {
                try {
                    InputStream stream = new ByteArrayInputStream(Base64.decode(v, Base64.DEFAULT));
                    return BitmapFactory.decodeStream(stream);
                }
                catch (Exception e) {
                } else if (value.equalsIgnoreCase("false")) {
                }
            }
            case DRAWABLE: {
                JSONObject drawableProperties = null;
                try {
                    drawableProperties = new JSONObject(v);
                } catch (Exception e) {};

                GradientDrawable gd = new GradientDrawable();

                    return BitmapFactory.decodeStream(stream);
                }
                catch (Exception e) {
                    return null;
                }
            }
            case DRAWABLE: {
                JSONObject drawableProperties = (JSONObject)v;

                GradientDrawable gd = new GradientDrawable();

                if (drawableProperties!=null) {

                    try { gd.setColor ( convertColor( drawableProperties.getString("COLOR") ) ); } catch (JSONException e) {}
                    if (drawableProperties.has("CORNER")) {
                        String cornerValues = null;
                        try {
                            cornerValues = drawableProperties.getString("CORNER");
                        } catch (JSONException e){}
                        if (!TextUtils.isEmpty(cornerValues)) {
                            if (cornerValues.contains("|")) {
                                float[] corners = new float[8];
                                Arrays.fill(corners, 0);
                                String[] values = cornerValues.split("\\|");
                                int count = Math.min(values.length, corners.length);
                                for (int i=0 ; i<count ; i++) {
                                    try {
                                        corners[i] = convertDimenToPixel(values[i]);
                                    } catch (Exception e) {
                                        corners[i] = 0f;
                                    }
                                }
                                gd.setCornerRadii(corners);
                            } else {
                                try {
                                    gd.setCornerRadius( convertDimenToPixel(cornerValues) );
                                } catch (Exception e) {
                                    gd.setCornerRadius(0f);
                                }
                            }
                        }

                    }
                    int strokeColor = 0x00FFFFFF;
                    int strokeSize = 0;
                    if (drawableProperties.has("STROKECOLOR")) {
                        try { strokeColor = convertColor( drawableProperties.getString("STROKECOLOR") ); } catch (JSONException e) {}
                    }
                    if (drawableProperties.has("STROKESIZE")) {
                        try { strokeSize = (int) convertDimenToPixel( drawableProperties.getString("STROKESIZE") ); } catch (JSONException e) {}
                    }
                    gd.setStroke(strokeSize, strokeColor);

                }

                return gd;
            }
        }
        return v;
    }

    /**
     * create property and parse json
     * @param jsonObject : json to parse
            type = TYPE.NO_VALID;
        }
        try {
            value = convertValue(jsonObject.getString("value"));
        } catch (Exception e) {}
    }

        }
        try {
            type = TYPE.valueOf(jsonObject.getString("type").toUpperCase().trim());
        } catch (Exception e) {
            type = TYPE.NO_VALID;
        }
        try {
            value = convertValue(jsonObject.get("value"));
        } catch (Exception e) {}
    }

    public boolean isValid() {
        return value!=null;
    }

    /**
     * @param clazz
     * @param varName
     * @return search in clazz of possible variable name (varName) and return its value
     */
    public Object getValueInt(Class clazz, String varName) {

        java.lang.reflect.Field fieldRequested = null;

        try {
            fieldRequested = clazz.getField(varName);
            if (fieldRequested!=null) {
                return fieldRequested.get(clazz);
            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        }
        return null;
    }


    /** next function just cast value and return the object **/

    public int getValueColor() {
        if (type == TYPE.COLOR) return Integer.class.cast(value);
        return -1;
    }
    public String getValueString() {
        return String.class.cast(value);
    }
    public int getValueInt() {
        if (value instanceof Integer)
            return Integer.class.cast(value);
        else if (value instanceof Float)
            return (int) getValueFloat();
        else
            return (int) value;
    }
    public float getValueFloat() {
    public Drawable getValueGradientDrawable() {
        return (Drawable)value;
    }


    int convertColor(String color) {
        return new BitmapDrawable(Resources.getSystem(), getValueBitmap());
    }
    public Drawable getValueGradientDrawable() {
        return (Drawable)value;
    }
    public JSONObject getValueJSON() {
        return JSONObject.class.cast(value);
    }


    int convertColor(String color) {
        if (color.startsWith("0x")) {
            return (int) Long.parseLong(color.substring(2), 16);
        }
        return Color.parseColor(color);
    }

    float convertDimenToPixel(String dimen) {
        if (dimen.endsWith("dp"))
            return DynamicHelper.dpToPx(Float.parseFloat(dimen.substring(0, dimen.length() - 2)));
        else if (dimen.endsWith("sp"))
            return DynamicHelper.spToPx(Float.parseFloat(dimen.substring(0, dimen.length() - 2)));
        else if (dimen.endsWith("px"))
            return Integer.parseInt(dimen.substring(0, dimen.length() - 2));
        else if (dimen.endsWith("%"))
            return (int)(Float.parseFloat(dimen.substring(0, dimen.length() - 1))/100f * DynamicHelper.deviceWidth());
        else if (dimen.equalsIgnoreCase("match_parent"))
            return ViewGroup.LayoutParams.MATCH_PARENT;
        else if (dimen.equalsIgnoreCase("wrap_content"))
            return ViewGroup.LayoutParams.WRAP_CONTENT;
        else
            return Integer.parseInt(dimen);
    }

}

<MSG> add new feature to send every method to call in dynamic View, also add support for some new properties (enabled, selected, clickable, scaleX, scaleY). change the object requested in  drawable to be a json (not an escaped json in a string)
[skip ci]

<DFF> @@ -36,7 +36,8 @@ public class DynamicProperty {
         REF,
         BOOLEAN,
         BASE64,
-        DRAWABLE
+        DRAWABLE,
+        JSON
     }
 
     /**
@@ -58,6 +59,11 @@ public class DynamicProperty {
         LAYOUT_MARGINBOTTOM,
         LAYOUT_MARGIN,
         BACKGROUND,
+        ENABLED,
+        SELECTED,
+        CLICKABLE,
+        SCALEX,
+        SCALEY,
         /* textView */
         TEXT,
         TEXTCOLOR,
@@ -98,7 +104,9 @@ public class DynamicProperty {
         LAYOUT_TORIGHTOF,
         LAYOUT_TOSTARTOF,
         LAYOUT_GRAVITY,
-        ORIENTATION
+        ORIENTATION,
+
+        FUNCTION
     }
 
     public NAME name;
@@ -109,34 +117,35 @@ public class DynamicProperty {
      * @param v value to convert as string
      * @return Value as object depends on the type
      */
-    private Object convertValue(String v) {
-        if (TextUtils.isEmpty(v))
+    private Object convertValue(Object v) {
+        if (v==null)
             return null;
         switch (type) {
             case INTEGER: {
-                return Integer.parseInt(v);
+                return Integer.parseInt(v.toString());
             }
             case DIMEN: {
-                return  convertDimenToPixel(v);
+                return  convertDimenToPixel(v.toString());
             }
             case COLOR: {
-                return convertColor(v);
+                return convertColor(v.toString());
             }
             case BOOLEAN: {
-                if (v.equalsIgnoreCase("t")) {
+                String value = v.toString();
+                if (value.equalsIgnoreCase("t")) {
                     return true;
-                } else if (v.equalsIgnoreCase("f")) {
+                } else if (value.equalsIgnoreCase("f")) {
                     return false;
-                } else if (v.equalsIgnoreCase("true")) {
+                } else if (value.equalsIgnoreCase("true")) {
                     return true;
-                } else if (v.equalsIgnoreCase("false")) {
+                } else if (value.equalsIgnoreCase("false")) {
                     return false;
                 }
-                return Integer.parseInt(v) == 1;
+                return Integer.parseInt(value) == 1;
             }
             case BASE64: {
                 try {
-                    InputStream stream = new ByteArrayInputStream(Base64.decode(v, Base64.DEFAULT));
+                    InputStream stream = new ByteArrayInputStream(Base64.decode(v.toString(), Base64.DEFAULT));
                     return BitmapFactory.decodeStream(stream);
                 }
                 catch (Exception e) {
@@ -144,10 +153,7 @@ public class DynamicProperty {
                 }
             }
             case DRAWABLE: {
-                JSONObject drawableProperties = null;
-                try {
-                    drawableProperties = new JSONObject(v);
-                } catch (Exception e) {};
+                JSONObject drawableProperties = (JSONObject)v;
 
                 GradientDrawable gd = new GradientDrawable();
 
@@ -218,7 +224,7 @@ public class DynamicProperty {
             type = TYPE.NO_VALID;
         }
         try {
-            value = convertValue(jsonObject.getString("value"));
+            value = convertValue(jsonObject.get("value"));
         } catch (Exception e) {}
     }
 
@@ -285,6 +291,9 @@ public class DynamicProperty {
     public Drawable getValueGradientDrawable() {
         return (Drawable)value;
     }
+    public JSONObject getValueJSON() {
+        return JSONObject.class.cast(value);
+    }
 
 
     int convertColor(String color) {

add new feature to send every method to call in dynamic View, also add support for some new properties (enabled, selected, clickable, scaleX, scaleY). change the object requested in  drawable to be a json (not an escaped json in a string) [skip ci]