Android Open Source - json2view Dynamic View Json Builder






From Project

Back to project page json2view.

License

The source code is released under:

MIT License

If you think the Android project json2view listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.avocarrot.json2view;
/*  w  w  w .  j  a  v  a 2  s  . c o m*/
import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class DynamicViewJsonBuilder {

    private String widget = "";
    private List<JSONObject> properties;
    private List<JSONObject> views;

    public DynamicViewJsonBuilder() {
        properties = new ArrayList<>();
        views = new ArrayList<>();
    }

    public DynamicViewJsonBuilder setWidget(String widget) {
        this.widget = widget;
        return this;
    }
    public DynamicViewJsonBuilder addProperty(JSONObject property) {
        this.properties.add(property);
        return this;
    }
    public DynamicViewJsonBuilder addView(JSONObject view) {
        this.views.add(view);
        return this;
    }

    public JSONObject build() {
        Map<String, Object> map = new HashMap<>();
        map.put("widget", widget);
        map.put("properties", new JSONArray(properties));
        map.put("views", new JSONArray(views));
        return new JSONObject(map);
    }

}




Java Source Code List

com.avocarrot.json2view.ApplicationTest.java
com.avocarrot.json2view.DynamicHelper.java
com.avocarrot.json2view.DynamicPropertyJsonBuilder.java
com.avocarrot.json2view.DynamicProperty.java
com.avocarrot.json2view.DynamicViewId.java
com.avocarrot.json2view.DynamicViewJsonBuilder.java
com.avocarrot.json2view.DynamicView.java
com.avocarrot.json2view.TestActivity.java
com.avocarrot.json2view.TestImageViewPropertiesCase.java
com.avocarrot.json2view.TestInvalidJson.java
com.avocarrot.json2view.TestLayoutPropertiesCase.java
com.avocarrot.json2view.TestSampleCase.java
com.avocarrot.json2view.TestViewPropertiesCase.java
com.avocarrot.json2view.Utils.java
com.avocarrot.json2view.sample.MainActivity.java