use of com.openmeap.protocol.json.JsUpdateHeader in project OpenMEAP by OpenMEAP.
the class JsApiCoreImpl method performUpdate.
/**
* @param header JSON of the update header
* @param statusCallBack a status change callback
*/
public void performUpdate(final String header, final String statusCallBack) {
// needs to immediately return control to the calling javascript,
// and pass back download status information via the callback function.
JsUpdateHeader jsUpdateHeader = null;
try {
jsUpdateHeader = new JsUpdateHeader(header);
} catch (JSONException e) {
throw new GenericRuntimeException(e);
}
UpdateHeader reloadedHeader = jsUpdateHeader.getWrappedObject();
if (reloadedHeader != null) {
updateHandler.handleUpdate(reloadedHeader, new UpdateHandler.StatusChangeHandler() {
public void onStatusChange(UpdateStatus update) {
try {
JSONObject js = new JSONObject("{update:" + header + "}");
UpdateException error = update.getError();
js.put("bytesDownloaded", update.getBytesDownloaded());
js.put("complete", update.getComplete());
js.put("error", error != null ? new JsError(error.getUpdateResult().toString(), error.getMessage()).toJSONObject() : null);
webView.executeJavascriptFunction(statusCallBack, new String[] { js.toString() });
} catch (JSONException e) {
throw new GenericRuntimeException(e);
}
}
});
}
}
Aggregations