Example usage for android.graphics.drawable StateListDrawable getPadding

List of usage examples for android.graphics.drawable StateListDrawable getPadding

Introduction

In this page you can find the example usage for android.graphics.drawable StateListDrawable getPadding.

Prototype

@Override
    public boolean getPadding(Rect padding) 

Source Link

Usage

From source file:org.kde.necessitas.ministro.ExtractStyle.java

private JSONObject getStateListDrawable(Object drawable, String filename) {
    JSONObject json = new JSONObject();
    try {/*from   w  ww .j av a 2  s  .  c  om*/
        StateListDrawable stateList = (StateListDrawable) drawable;
        final int numStates = (Integer) StateListDrawable.class.getMethod("getStateCount").invoke(stateList);
        JSONArray array = new JSONArray();
        for (int i = 0; i < numStates; i++) {
            JSONObject stateJson = new JSONObject();
            final Drawable d = (Drawable) StateListDrawable.class.getMethod("getStateDrawable", Integer.TYPE)
                    .invoke(stateList, i);
            final int[] states = (int[]) StateListDrawable.class.getMethod("getStateSet", Integer.TYPE)
                    .invoke(stateList, i);
            stateJson.put("states", getStatesList(states));
            stateJson.put("drawable", getDrawable(d, filename + "__" + getStatesName(states)));
            array.put(stateJson);
        }
        json.put("type", "stateslist");
        Rect padding = new Rect();
        if (stateList.getPadding(padding))
            json.put("padding", getJsonRect(padding));
        json.put("stateslist", array);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return json;
}