public void call(Object data) { String dataString; if (data == null) { dataString = ""; } else if (data instanceof HashMap) { JSONObject json = TiConvert.toJSON((HashMap) data); dataString = ", " + String.valueOf(json); } else { dataString = ", " + String.valueOf(data); } String code = "Ti.executeListener(" + id + dataString + ");"; synchronized (codeSnippets) { codeSnippets.push(code); } }
@Kroll.method public String stringify(Object data) { if (data instanceof KrollDict) { return TiConvert.toJSON((KrollDict) data).toString(); } else if (data instanceof Object[]) { Object[] objects = (Object[]) data; StringBuilder sb = new StringBuilder(); sb.append("["); for (int i = 0; i < objects.length; i++) { sb.append(stringify(objects[i])); if (i < objects.length - 1) { sb.append(", "); } } sb.append("]"); return sb.toString(); } else { return TiConvert.toString(data); } }