use of org.json.JSONArray in project clutchandroid by clutchio.
the class ClutchAB method test.
public static void test(String name, ClutchABDataTest testInstance) {
JSONObject metaMeta = getLatestMeta();
if (metaMeta.length() == 0) {
stats.testFailure(name, "no-meta");
stats.setNumChoices(name, 0, true);
return;
}
JSONObject meta = metaMeta.optJSONObject(name);
if (meta == null) {
stats.testFailure(name, "no-meta-name");
stats.setNumChoices(name, 0, true);
return;
}
JSONArray weights = meta.optJSONArray("weights");
JSONArray allData = meta.optJSONArray("data");
if (allData == null || weights == null) {
stats.testFailure(name, "no-data");
return;
}
if (weights.length() == 0) {
return;
}
int choice = cachedChoice(name, doubleJSONArrayToList(weights));
stats.testChosen(name, choice, weights.length());
if (choice == -1) {
return;
}
JSONObject data = allData.optJSONObject(choice);
testInstance.action(data);
}
use of org.json.JSONArray in project AnimeTaste by daimajia.
the class LoadActivity method init.
private void init() {
if (getIntent().getAction().equals(Intent.ACTION_VIEW)) {
Uri uri = getIntent().getData();
if (uri == null) {
error();
}
String vid = uri.getQueryParameter("vid");
int animationId = Integer.valueOf(vid);
ApiConnector.instance().getDetail(animationId, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, final JSONObject response) {
super.onSuccess(statusCode, response);
try {
if (statusCode == 200 && response.has("data") && response.getJSONObject("data").has("result") && response.getJSONObject("data").getBoolean("result")) {
final JSONObject anime = response.getJSONObject("data").getJSONObject("anime");
new Thread() {
@Override
public void run() {
super.run();
MobclickAgent.onEvent(mContext, "yell");
final Intent intent = new Intent(mContext, PlayActivity.class);
Animation animation = Animation.build(anime);
intent.putExtra("Animation", animation);
runOnUiThread(new Runnable() {
@Override
public void run() {
startActivity(intent);
finish();
}
});
}
}.start();
} else {
error();
}
} catch (Exception e) {
e.printStackTrace();
error();
}
}
@Override
public void onFailure(Throwable throwable, JSONArray jsonArray) {
super.onFailure(throwable, jsonArray);
error();
}
@Override
public void onFinish() {
super.onFinish();
}
});
} else {
ApiConnector.instance().getInitData(20, 5, 2, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, final JSONObject response) {
super.onSuccess(response);
if (statusCode == 200 && response.has("data")) {
Message msg = Message.obtain();
msg.obj = response;
executeHandler.sendMessage(msg);
} else {
error();
}
}
@Override
public void onFailure(Throwable error) {
super.onFailure(error);
error();
}
});
}
}
use of org.json.JSONArray in project android by cSploit.
the class GitHubParser method fetchReleases.
private void fetchReleases() throws IOException, JSONException {
JSONArray releases;
JSONObject release;
boolean found;
releases = new JSONArray(new String(RemoteReader.fetch(String.format(RELEASES_URL, username, project))));
mReleases = new JSONArray();
found = false;
for (int i = 0; i < releases.length(); i++) {
release = releases.getJSONObject(i);
if (release.getBoolean("draft") || release.getBoolean("prerelease"))
continue;
if (mTagFilter != null) {
String tag = release.getString("tag_name");
if (!tag.matches(mTagFilter))
continue;
}
if (!found) {
mLastRelease = release;
found = true;
}
mReleases.put(release);
}
}
use of org.json.JSONArray in project flux by eclipse.
the class Utils method editsToJsonArray.
public static JSONArray editsToJsonArray(TextEdit edit) {
final LinkedList<JSONObject> list = new LinkedList<JSONObject>();
edit.accept(new TextEditVisitor() {
@Override
public boolean visit(DeleteEdit delete) {
try {
JSONObject json = new JSONObject();
json.put("offset", delete.getOffset());
json.put("length", delete.getLength());
json.put("text", "");
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(delete);
}
@Override
public boolean visit(InsertEdit insert) {
try {
JSONObject json = new JSONObject();
json.put("offset", insert.getOffset());
json.put("length", 0);
json.put("text", insert.getText());
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(insert);
}
@Override
public boolean visit(ReplaceEdit replace) {
try {
JSONObject json = new JSONObject();
json.put("offset", replace.getOffset());
json.put("length", replace.getLength());
json.put("text", replace.getText());
list.addFirst(json);
} catch (JSONException e) {
e.printStackTrace();
}
return super.visit(replace);
}
});
return new JSONArray(list);
}
use of org.json.JSONArray in project flux by eclipse.
the class RenameService method computeReferences.
public JSONArray computeReferences(String username, String resourcePath, int offset, int length) {
try {
ICompilationUnit unit = liveEditUnits.getLiveEditUnit(username, resourcePath);
if (unit != null) {
final ASTParser parser = ASTParser.newParser(AST.JLS4);
// Parse the class as a compilation unit.
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setSource(unit);
parser.setResolveBindings(true);
// Return the compiled class as a compilation unit
final ASTNode compilationUnit = parser.createAST(null);
final ASTNode nameNode = NodeFinder.perform(compilationUnit, offset, length);
final List<ASTNode> nodes = new ArrayList<ASTNode>();
if (nameNode instanceof SimpleName) {
compilationUnit.accept(new ASTVisitor() {
@Override
public boolean visit(SimpleName node) {
if (node.getIdentifier().equals(((SimpleName) nameNode).getIdentifier())) {
nodes.add(node);
}
return super.visit(node);
}
});
}
JSONArray references = new JSONArray();
for (ASTNode astNode : nodes) {
JSONObject nodeObject = new JSONObject();
nodeObject.put("offset", astNode.getStartPosition());
nodeObject.put("length", astNode.getLength());
references.put(nodeObject);
}
return references;
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
Aggregations