Search in sources :

Example 1 with ScreenshotTask

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();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Consumer(com.intellij.util.Consumer) ScreenshotTask(com.android.tools.idea.ddms.screenshot.ScreenshotTask) ScreenshotViewer(com.android.tools.idea.ddms.screenshot.ScreenshotViewer) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ScreenshotTask (com.android.tools.idea.ddms.screenshot.ScreenshotTask)1 ScreenshotViewer (com.android.tools.idea.ddms.screenshot.ScreenshotViewer)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Consumer (com.intellij.util.Consumer)1 File (java.io.File)1