Search in sources :

Example 1 with ScreenshotViewer

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();
}
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)

Example 2 with ScreenshotViewer

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

Aggregations

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