use of com.android.tools.idea.ddms.screenshot.ScreenshotTask in project android by JetBrains.
the class ScreenshotAction method performAction.
@Override
protected void performAction(@NotNull final IDevice device) {
final Project project = myProject;
new ScreenshotTask(project, device) {
@Override
public void onSuccess() {
String msg = getError();
if (msg != null) {
Messages.showErrorDialog(project, msg, AndroidBundle.message("android.ddms.actions.screenshot"));
return;
}
try {
File backingFile = FileUtil.createTempFile("screenshot", SdkConstants.DOT_PNG, true);
ImageIO.write(getScreenshot(), SdkConstants.EXT_PNG, backingFile);
final ScreenshotViewer viewer = new ScreenshotViewer(project, getScreenshot(), backingFile, device, device.getProperty(IDevice.PROP_DEVICE_MODEL));
viewer.showAndGetOk().doWhenDone((Consumer<Boolean>) ok -> {
if (ok) {
File screenshot = viewer.getScreenshot();
VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(screenshot);
if (vf != null) {
vf.refresh(false, false);
FileEditorManager.getInstance(project).openFile(vf, true);
}
}
});
} catch (Exception e) {
Logger.getInstance(ScreenshotAction.class).warn("Error while displaying screenshot viewer: ", e);
Messages.showErrorDialog(project, AndroidBundle.message("android.ddms.screenshot.generic.error", e), AndroidBundle.message("android.ddms.actions.screenshot"));
}
}
}.queue();
}
Aggregations