Search in sources :

Example 1 with LintNotificationPanel

use of com.android.tools.idea.uibuilder.lint.LintNotificationPanel in project android by JetBrains.

the class DesignSurface method hover.

public void hover(@SwingCoordinate int x, @SwingCoordinate int y) {
    ScreenView current = getHoverScreenView(x, y);
    for (Layer layer : myLayers) {
        if (layer instanceof ConstraintsLayer) {
            // For constraint layer, set show on hover if they are above their screen view
            ConstraintsLayer constraintsLayer = (ConstraintsLayer) layer;
            boolean show = false;
            if (constraintsLayer.getScreenView() == current) {
                show = true;
            }
            if (constraintsLayer.isShowOnHover() != show) {
                constraintsLayer.setShowOnHover(show);
                repaint();
            }
        } else if (layer instanceof SceneLayer) {
            // For constraint layer, set show on hover if they are above their screen view
            SceneLayer sceneLayer = (SceneLayer) layer;
            boolean show = false;
            if (sceneLayer.getScreenView() == current) {
                show = true;
            }
            if (sceneLayer.isShowOnHover() != show) {
                sceneLayer.setShowOnHover(show);
                repaint();
            }
        } else if (layer instanceof CanvasResizeLayer) {
            if (((CanvasResizeLayer) layer).changeHovering(x, y)) {
                repaint();
            }
        }
    }
    if (myErrorPanel.isVisible() && myRenderHasProblems) {
        // TODO: we should really move this logic into the error panel itself
        return;
    }
    // Currently, we use the hover action only to check whether we need to show a warning.
    if (AndroidEditorSettings.getInstance().getGlobalState().isShowLint()) {
        ScreenView currentScreenView = getCurrentScreenView();
        LintAnnotationsModel lintModel = currentScreenView != null ? currentScreenView.getModel().getLintAnnotationsModel() : null;
        if (lintModel != null) {
            for (Layer layer : myLayers) {
                String tooltip = layer.getTooltip(x, y);
                if (tooltip != null) {
                    JBPopup lintPopup = myLintTooltipPopup.get();
                    if (lintPopup == null || !lintPopup.isVisible()) {
                        NlUsageTrackerManager.getInstance(this).logAction(LayoutEditorEvent.LayoutEditorEventType.LINT_TOOLTIP);
                        LintNotificationPanel lintPanel = new LintNotificationPanel(getCurrentScreenView(), lintModel);
                        lintPanel.selectIssueAtPoint(Coordinates.getAndroidX(getCurrentScreenView(), x), Coordinates.getAndroidY(getCurrentScreenView(), y));
                        Point point = new Point(x, y);
                        SwingUtilities.convertPointToScreen(point, this);
                        myLintTooltipPopup = new WeakReference<>(lintPanel.showInScreenPosition(myProject, this, point));
                    }
                    break;
                }
            }
        }
    }
}
Also used : LintNotificationPanel(com.android.tools.idea.uibuilder.lint.LintNotificationPanel) LintAnnotationsModel(com.android.tools.idea.uibuilder.lint.LintAnnotationsModel) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 2 with LintNotificationPanel

use of com.android.tools.idea.uibuilder.lint.LintNotificationPanel in project android by JetBrains.

the class LintNotificationAction method actionPerformed.

/** Shows list of warnings/errors */
@Override
public void actionPerformed(AnActionEvent e) {
    NlUsageTrackerManager.getInstance(mySurface).logAction(LayoutEditorEvent.LayoutEditorEventType.SHOW_LINT_MESSAGES);
    ScreenView screenView = mySurface.getCurrentScreenView();
    if (screenView != null) {
        LintAnnotationsModel lintModel = screenView.getModel().getLintAnnotationsModel();
        if (lintModel != null && lintModel.getIssueCount() > 0) {
            LintNotificationPanel notificationPanel = new LintNotificationPanel(screenView, lintModel);
            Object source = e.getInputEvent().getSource();
            if (source instanceof JComponent) {
                notificationPanel.showInBestPositionFor(e.getProject(), (JComponent) source);
            } else {
                notificationPanel.showInBestPositionFor(e.getProject(), e.getDataContext());
            }
        }
    }
}
Also used : ScreenView(com.android.tools.idea.uibuilder.surface.ScreenView) LintNotificationPanel(com.android.tools.idea.uibuilder.lint.LintNotificationPanel) LintAnnotationsModel(com.android.tools.idea.uibuilder.lint.LintAnnotationsModel)

Aggregations

LintAnnotationsModel (com.android.tools.idea.uibuilder.lint.LintAnnotationsModel)2 LintNotificationPanel (com.android.tools.idea.uibuilder.lint.LintNotificationPanel)2 ScreenView (com.android.tools.idea.uibuilder.surface.ScreenView)1 JBPopup (com.intellij.openapi.ui.popup.JBPopup)1