Skip to content

Instantly share code, notes, and snippets.

@funnythingz
Last active August 29, 2015 14:22
Show Gist options
  • Save funnythingz/6513e1fabd6b9fd24bb6 to your computer and use it in GitHub Desktop.
Save funnythingz/6513e1fabd6b9fd24bb6 to your computer and use it in GitHub Desktop.
package com.funnythingz.iroiro.domain;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class ColorsFactory {
protected JSONObject mJsonObject;
public ColorsFactory(JSONObject jsonObject) {
mJsonObject = jsonObject;
}
public ArrayList<Color> createColors() throws JSONException {
JSONArray colorsJsonArray = mJsonObject.getJSONArray("color_list");
ArrayList<Color> colorsArrayList = new ArrayList<Color>();
int len = colorsJsonArray.length();
for(int i = 0; i < len; i++) {
JSONObject color = colorsJsonArray.getJSONObject(i);
int colorId = color.getInt("id");
String colorName = color.getString("name");
String colorCode = color.getString("code");
String colorTextCode = color.getString("text_code");
colorsArrayList.add(new Color(colorName, colorCode, colorTextCode));
}
return colorsArrayList;
}
}
package com.funnythingz.iroiro.domain;
import org.json.JSONObject;
public class Color {
public String name;
public String code;
public String textCode;
public Color(String name, String code, String textCode) {
this.name = name;
this.code = code;
this.textCode = textCode;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment