Created
March 16, 2016 14:58
-
-
Save ayvazj/470d139cbff92a3ae7ec to your computer and use it in GitHub Desktop.
parse btfy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public BtfyAnimationGroup parseAnimationGroup(JsonNode jSONObject) throws BtfyParseException { | |
String typeStr = jSONObject.path("type").asText(); | |
if (typeStr.equals("animationGroup")) { | |
String jsonId = jSONObject.path("id").asText(); | |
if (TextUtils.isEmpty(jsonId)) { | |
throw new BtfyParseException("Animation missing id."); | |
} | |
if (!jSONObject.has("initialValues")) { | |
throw new BtfyParseException("Animation group missing initial values."); | |
} | |
String parentId = jSONObject.path("parentId").asText(); | |
BtfyShape shape = parseShape(jSONObject); | |
long duration = Math.round(jSONObject.path("duration").asDouble() * 1000.0d); | |
String textStr = null; | |
if (jSONObject.has("text") && !TextUtils.isEmpty(jSONObject.path("text").asText())) { | |
try { | |
textStr = this.stringMap.getString(jsonId, jSONObject.path("text").asText()); | |
} catch (RuntimeException re) { | |
textStr = jSONObject.path("text").asText(); | |
} | |
} | |
String backgroundImageStr = jSONObject.path("backgroundImage").asText(null); | |
ArrayList<BtfyAnimationElement> animationElements = new ArrayList<>(); | |
parseAnimations(jSONObject, animationElements); | |
JsonNode jsonInitialValues = jSONObject.get("initialValues"); | |
BtfySize initialValuesSize = parseSize(jsonInitialValues.path("size"), "Missing size in initial values."); | |
BtfyPoint anchorPoint = jsonInitialValues.get("anchorPoint") != null ? parsePoint(jsonInitialValues.get("anchorPoint")) : new BtfyPoint(0.0f, 0.0f); | |
BtfyColor backgroundColor = jsonInitialValues.get("backgroundColor") != null ? BtfyColor.parseRGBA(jsonInitialValues.get("backgroundColor")) : BtfyColor.transparent(); | |
float opacity = (float)jsonInitialValues.path("opacity").asDouble(1.0d); | |
BtfyPoint position = jsonInitialValues.get("position") != null ? parsePoint(jsonInitialValues.get("position")) : new BtfyPoint(0.0f, 0.0f); | |
BtfyPoint scale = jsonInitialValues.get("scale") != null ? parseScale(jsonInitialValues.get("scale")) : new BtfyPoint(1.0f, 1.0f); | |
int rotation = jsonInitialValues.path("rotation").asInt(0); | |
float textSize = (float) jsonInitialValues.path("fontSize").asDouble(); | |
BtfyColor textColor = jsonInitialValues.get("textColor") != null ? BtfyColor.parseRGBA(jsonInitialValues.get("textColor")) : BtfyColor.white(); | |
Typeface typeface = parseTypeface(jsonInitialValues.path("textStyle").asText()); | |
int textAlign = parseTextAlign(jsonInitialValues); | |
return new BtfyAnimationGroup(jsonId, | |
TextUtils.isEmpty(parentId) ? null : parentId, | |
shape, | |
duration, | |
textStr, | |
backgroundImageStr, | |
new BtfyInitialValues( | |
initialValuesSize, | |
anchorPoint, | |
backgroundColor, | |
opacity, | |
position, | |
scale, | |
rotation, | |
textSize, | |
textColor, | |
typeface, | |
textAlign | |
), | |
animationElements); | |
} | |
throw new BtfyParseException("Unexpected animation group type", String.valueOf(typeStr)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment