Example #1
0
 public JSONObject toJSON(Stroke de) {
   JSONObject o = getJSONObject();
   try {
     o.put(JSONConst.JSON_EL_TYPE, JSONConst.JSON_EL_TYPE_STROKE);
     o.put(JSONConst.JSON_ID, de.getId());
     o.put(JSONConst.JSON_TYPE, de.type);
     if (de.locked) {
       o.put(JSONConst.JSON_LOCKED, de.locked);
     }
     if (de.visible) {
       o.put(JSONConst.JSON_VISIBLE, de.visible);
     }
     if (de.textXScale != 1) {
       o.put(JSONConst.JSON_TEXTXSCALE, de.textXScale);
     }
     if (de.text != null && !"".equals(de.text)) {
       o.put(JSONConst.JSON_TEXT, de.text);
       if (de.fontName != null && !"".equals(de.fontName)) {
         o.put(JSONConst.JSON_FONT_NAME, de.fontName);
       }
     }
     if (de.pen != null) {
       o.put(JSONConst.JSON_PEN, jsp.toJSON(de.pen));
     }
     if (de.fill != null) {
       o.put(JSONConst.JSON_FILL, jsf.toJSON(de.fill));
     }
     JSONArray jsPts = new JSONArray();
     for (PointVec pv : de.points) {
       jsPts.put(jspv.toJSON(pv));
     }
     o.put(JSONConst.JSON_POINTS, jsPts);
   } catch (JSONException e) {
     Log.d(VecGlobals.LOG_TAG, "JSON to stroke", e);
   }
   return o;
 }
Example #2
0
 public DrawingElement fromJSON(JSONObject object) {
   Stroke s = new Stroke();
   try {
     if (object.has(JSONConst.JSON_TYPE)) {
       s.type = Stroke.Type.valueOf(object.getString(JSONConst.JSON_TYPE));
       if (object.has(JSONConst.JSON_ID)) {
         s.setId(object.getString(JSONConst.JSON_ID));
       }
       if (object.has(JSONConst.JSON_LOCKED)) {
         s.locked = object.getBoolean(JSONConst.JSON_LOCKED);
       } else {
         s.locked = false;
       }
       if (object.has(JSONConst.JSON_VISIBLE)) {
         s.visible = object.getBoolean(JSONConst.JSON_VISIBLE);
       } else {
         s.visible = true;
       }
       if (object.has(JSONConst.JSON_TEXT)) {
         s.text = object.getString(JSONConst.JSON_TEXT);
       }
       if (object.has(JSONConst.JSON_TEXTXSCALE)) {
         s.textXScale = (float) object.getDouble(JSONConst.JSON_TEXTXSCALE);
       } else {
         s.textXScale = 1;
       }
       if (object.has(JSONConst.JSON_FONT_NAME)) {
         s.fontName = object.getString(JSONConst.JSON_FONT_NAME);
       }
       // s.fontTTF=FileRepository.getFileRepository()._fontController.getTTFont(s.fontName);
       JSONArray jsPts = object.getJSONArray(JSONConst.JSON_POINTS);
       for (int i = 0; i < jsPts.length(); i++) {
         s.points.add(jspv.fromJSON(jsPts.getJSONObject(i)));
       }
       if (object.has(JSONConst.JSON_PEN)) {
         s.pen = jsp.fromJSON(object.getJSONObject(JSONConst.JSON_PEN));
       }
       if (object.has(JSONConst.JSON_FILL)) {
         s.fill = jsf.fromJSON(object.getJSONObject(JSONConst.JSON_FILL));
       }
     }
   } catch (JSONException e) {
     Log.d(VecGlobals.LOG_TAG, "JSON fromstroke", e);
   }
   return s;
 }