use of com.android.tools.idea.ddms.screenshot.ScreenshotViewer 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();
}
use of com.android.tools.idea.ddms.screenshot.ScreenshotViewer in project android by JetBrains.
the class SaveScreenshotAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
try {
BufferedImage image = getImage();
// enforced by update() above
assert image != null && project != null;
// We need to create a temp file since the image preview editor requires a real file
File backingFile = FileUtil.createTempFile("screenshot", SdkConstants.DOT_PNG, true);
ImageIO.write(image, SdkConstants.EXT_PNG, backingFile);
final ScreenshotViewer viewer = new ScreenshotViewer(project, image, backingFile, null, getDeviceName());
viewer.showAndGetOk().doWhenDone(new Consumer<Boolean>() {
@Override
public void consume(Boolean ok) {
if (ok) {
File screenshot = viewer.getScreenshot();
VirtualFile vf = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(screenshot);
if (vf != null) {
FileEditorManager.getInstance(project).openFile(vf, true);
}
}
}
});
} catch (Exception ex) {
Messages.showErrorDialog(project, AndroidBundle.message("android.ddms.screenshot.generic.error", e), AndroidBundle.message("android.ddms.actions.screenshot"));
}
}
Aggregations