Search in sources :

Example 11 with SceneComponent

use of com.android.tools.idea.uibuilder.scene.SceneComponent in project android by JetBrains.

the class GuidelineTarget method updateAttributes.

@Override
protected void updateAttributes(AttributesTransaction attributes, int x, int y) {
    String begin = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_BEGIN);
    String end = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_END);
    String percent = attributes.getAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_PERCENT);
    SceneComponent parent = myComponent.getParent();
    int value = y - parent.getDrawY();
    float dimension = parent.getDrawHeight();
    if (!myIsHorizontal) {
        value = x - parent.getDrawX();
        dimension = parent.getDrawWidth();
    }
    if (begin != null) {
        String position = String.format(SdkConstants.VALUE_N_DP, value);
        attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_BEGIN, position);
    } else if (end != null) {
        String position = String.format(SdkConstants.VALUE_N_DP, (int) dimension - value);
        attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_END, position);
    } else if (percent != null) {
        String percentStringValue = null;
        float percentValue = value / dimension;
        if (percentValue > 1) {
            percentValue = 1;
        }
        if (percentValue < 0) {
            percentValue = 0;
        }
        percentValue = Math.round(percentValue * 100) / 100f;
        percentStringValue = String.valueOf(percentValue);
        if (percentStringValue.equalsIgnoreCase("NaN")) {
            percentStringValue = "0.5";
        }
        attributes.setAttribute(SdkConstants.SHERPA_URI, SdkConstants.LAYOUT_CONSTRAINT_GUIDE_PERCENT, percentStringValue);
    }
}
Also used : SceneComponent(com.android.tools.idea.uibuilder.scene.SceneComponent)

Aggregations

SceneComponent (com.android.tools.idea.uibuilder.scene.SceneComponent)11 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)2 ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 Configuration (com.android.tools.idea.configurations.Configuration)1 AttributesTransaction (com.android.tools.idea.uibuilder.model.AttributesTransaction)1 NlModel (com.android.tools.idea.uibuilder.model.NlModel)1 DisplayList (com.android.tools.idea.uibuilder.scene.draw.DisplayList)1 TextWidget (com.android.tools.sherpa.drawing.decorator.TextWidget)1 WidgetDecorator (com.android.tools.sherpa.drawing.decorator.WidgetDecorator)1 WidgetCompanion (com.android.tools.sherpa.structure.WidgetCompanion)1 WidgetsScene (com.android.tools.sherpa.structure.WidgetsScene)1 Result (com.intellij.openapi.application.Result)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Project (com.intellij.openapi.project.Project)1 XmlFile (com.intellij.psi.xml.XmlFile)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1