Search in sources :

Example 1 with ConvertToWebpAction

use of com.android.tools.idea.rendering.webp.ConvertToWebpAction in project android by JetBrains.

the class ConvertToWebpActionTest method invokeConvertToWebpAction.

private static void invokeConvertToWebpAction(@NotNull Project project, @NotNull VirtualFile res) {
    // Ideally I'd invoke the context menu on the res node, "Convert to WebP Format",
    // but the pane fixture doesn't support invoking context menu actions yet.
    // Shortcut:
    //ProjectViewFixture.PaneFixture pane = projectFrame.getProjectView().selectAndroidPane();
    //pane.selectByPath("app", "res");
    Map<String, Object> data = Maps.newHashMap();
    data.put(CommonDataKeys.VIRTUAL_FILE_ARRAY.getName(), new VirtualFile[] { res });
    data.put(CommonDataKeys.PROJECT.getName(), project);
    DataContext context = SimpleDataContext.getSimpleContext(data, null);
    AnActionEvent actionEvent = new AnActionEvent(null, context, "test", new Presentation(), ActionManager.getInstance(), 0);
    ConvertToWebpAction action = new ConvertToWebpAction();
    GuiActionRunner.execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            //noinspection SSBasedInspection
            SwingUtilities.invokeLater(() -> action.actionPerformed(actionEvent));
        }
    });
}
Also used : ConvertToWebpAction(com.android.tools.idea.rendering.webp.ConvertToWebpAction) GuiTask(org.fest.swing.edt.GuiTask) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext)

Example 2 with ConvertToWebpAction

use of com.android.tools.idea.rendering.webp.ConvertToWebpAction in project android by JetBrains.

the class AndroidLintConvertToWebpInspection method getQuickFixes.

@Override
@NotNull
public AndroidLintQuickFix[] getQuickFixes(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull String message) {
    return new AndroidLintQuickFix[] { new DefaultLintQuickFix("Convert images to WebP...") {

        @Override
        public boolean isApplicable(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.ContextType contextType) {
            return AndroidFacet.getInstance(startElement) != null;
        }

        @Override
        public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
            AndroidFacet facet = AndroidFacet.getInstance(startElement);
            if (facet != null) {
                AndroidModuleInfo info = AndroidModuleInfo.get(facet);
                int minSdkVersion = info.getMinSdkVersion().getApiLevel();
                List<VirtualFile> folders = facet.getResourceFolderManager().getFolders();
                ConvertToWebpAction action = new ConvertToWebpAction();
                action.perform(startElement.getProject(), minSdkVersion, folders.toArray(VirtualFile.EMPTY_ARRAY));
            }
        }
    } };
}
Also used : AndroidModuleInfo(com.android.tools.idea.model.AndroidModuleInfo) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConvertToWebpAction(com.android.tools.idea.rendering.webp.ConvertToWebpAction) AndroidLintQuickFix(org.jetbrains.android.inspections.lint.AndroidLintQuickFix) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ConvertToWebpAction (com.android.tools.idea.rendering.webp.ConvertToWebpAction)2 AndroidModuleInfo (com.android.tools.idea.model.AndroidModuleInfo)1 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiElement (com.intellij.psi.PsiElement)1 GuiTask (org.fest.swing.edt.GuiTask)1 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)1 AndroidLintQuickFix (org.jetbrains.android.inspections.lint.AndroidLintQuickFix)1 NotNull (org.jetbrains.annotations.NotNull)1