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