use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.
the class ProjectorQuery method startProgressLoop.
private void startProgressLoop() {
long timeLimit = startTime + timeout;
try {
status = ConverterStatus.Checking;
while (System.currentTimeMillis() < timeLimit) {
checkProgress();
if (status != ConverterStatus.Checking) {
return;
}
Thread.sleep(interval);
}
onFailure(new ConvertException(ConvertErrorCode.CheckTimeout));
status = ConverterStatus.Timeout;
} catch (ConvertException e) {
onFailure(e);
status = ConverterStatus.Fail;
} catch (InterruptedException ignored) {
onFailure(new ConvertException(ConvertErrorCode.ConvertFail));
status = ConverterStatus.Fail;
}
}
use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.
the class RoomActivity method staticConvert.
public void staticConvert(MenuItem item) {
Converter c = new Converter(this.token);
c.startConvertTask("https://white-cn-edge-doc-convert.oss-cn-hangzhou.aliyuncs.com/LightWaves.pdf", Converter.ConvertType.Static, new ConverterCallbacks() {
@Override
public void onFailure(ConvertException e) {
logAction(e.getMessage());
}
@Override
public void onFinish(ConvertedFiles ppt, ConversionInfo convertInfo) {
mRoom.putScenes("/static", ppt.getScenes(), 0);
mRoom.setScenePath("/static/1");
logAction(convertInfo.toString());
}
@Override
public void onProgress(Double progress, ConversionInfo convertInfo) {
logAction(String.valueOf(progress));
}
});
// ConvertV5
ConverterV5.Builder builder = new ConverterV5.Builder();
ConverterV5 converter = builder.setResource("https://white-cn-edge-doc-convert.oss-cn-hangzhou.aliyuncs.com/LightWaves.pdf").setType(ConvertType.Static).setScale(1.5).setOutputFormat(ImageFormat.JPEG).setSdkToken(demoAPI.getSdkToken()).setTaskUuid(null).setTaskToken(null).setCallback(new ConverterCallbacks() {
@Override
public void onProgress(Double progress, ConversionInfo convertInfo) {
}
@Override
public void onFinish(ConvertedFiles ppt, ConversionInfo convertInfo) {
}
@Override
public void onFailure(ConvertException e) {
}
}).build();
converter.startConvertTask();
}
use of com.herewhite.sdk.domain.ConvertException in project whiteboard-android by netless-io.
the class Converter method polling.
private void polling(String taskId, ConvertType type, final ConvertCallback callbacks) {
boolean canCheck = this.status == ConverterStatus.Timeout || this.status == ConverterStatus.CheckingFail || this.status == ConverterStatus.GetDynamicFail;
if (this.status != ConverterStatus.Created && !canCheck) {
return;
}
final Converter that = this;
Date expireDate = new Date(this.beginDate.getTime() + this.timeout);
while (converting && expireDate.after(new Date())) {
final CountDownLatch latch = new CountDownLatch(1);
that.status = ConverterStatus.Checking;
checkProgress(taskId, type, new CheckCallback() {
@Override
public void onCheckResponse(ConversionInfo info) {
ConversionInfo.ServerConversionStatus status = info.getConvertStatus();
if (status == ConversionInfo.ServerConversionStatus.Fail || status == ConversionInfo.ServerConversionStatus.NotFound) {
converting = false;
that.status = ConverterStatus.Fail;
ConvertErrorCode code = status == ConversionInfo.ServerConversionStatus.Fail ? ConvertErrorCode.ConvertFail : ConvertErrorCode.NotFound;
ConvertException e = new ConvertException(code, info.getReason());
callbacks.onConvertFailure(e);
} else if (status == ConversionInfo.ServerConversionStatus.Finished) {
// 成功时,可能还要额外获取动态 ppt 内容,不直接设置状态
converting = false;
callbacks.onConvertFinish(info);
} else {
that.status = ConverterStatus.WaitingForNextCheck;
callbacks.onConvertProgress(info.getConvertedPercentage(), info);
}
try {
Thread.sleep(interval);
} catch (Exception e) {
e.printStackTrace();
}
latch.countDown();
}
@Override
public void onCheckFailure(Exception e) {
ConvertException exp = new ConvertException(ConvertErrorCode.CheckFail);
callbacks.onConvertFailure(exp);
converting = false;
latch.countDown();
}
});
try {
latch.await();
} catch (Exception e) {
e.printStackTrace();
}
}
if (this.status == ConverterStatus.WaitingForNextCheck) {
this.status = ConverterStatus.Timeout;
ConvertException exp = new ConvertException(ConvertErrorCode.CheckTimeout);
callbacks.onConvertFailure(exp);
}
}
Aggregations