Search in sources :

Example 1 with DrawTextRegion

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

the class TextViewDecorator method addContent.

@Override
public void addContent(@NotNull DisplayList list, long time, @NotNull SceneContext sceneContext, @NotNull SceneComponent component) {
    Rectangle rect = new Rectangle();
    component.fillDrawRect(time, rect);
    int l = sceneContext.getSwingX(rect.x);
    int t = sceneContext.getSwingY(rect.y);
    int w = sceneContext.getSwingDimension(rect.width);
    int h = sceneContext.getSwingDimension(rect.height);
    String text = ConstraintUtilities.getResolvedText(component.getNlComponent());
    NlComponent nlc = component.getNlComponent();
    Configuration configuration = nlc.getModel().getConfiguration();
    ResourceResolver resourceResolver = configuration.getResourceResolver();
    Integer size = null;
    if (resourceResolver != null) {
        String textSize = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_TEXT_SIZE);
        if (textSize != null) {
            size = ViewEditor.resolveDimensionPixelSize(resourceResolver, textSize, configuration);
        }
    }
    if (size == null) {
        // With the specified string, this method cannot return null
        //noinspection ConstantConditions
        size = ViewEditor.resolveDimensionPixelSize(resourceResolver, DEFAULT_DIM, configuration);
        // temporary
        size = (int) (0.8 * size);
    }
    String alignment = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_TEXT_ALIGNMENT);
    int align = ConstraintUtilities.getAlignment(alignment);
    String single = nlc.getAttribute(SdkConstants.ANDROID_URI, SdkConstants.ATTR_SINGLE_LINE);
    boolean singleLine = Boolean.parseBoolean(single);
    int baseLineOffset = sceneContext.getSwingDimension(component.getBaseline());
    int scaleSize = sceneContext.getSwingDimension(size);
    list.add(new DrawTextRegion(l, t, w, h, baseLineOffset, text, singleLine, false, align, DrawTextRegion.TEXT_ALIGNMENT_VIEW_START, scaleSize));
}
Also used : DrawTextRegion(com.android.tools.idea.uibuilder.scene.draw.DrawTextRegion) NlComponent(com.android.tools.idea.uibuilder.model.NlComponent) Configuration(com.android.tools.idea.configurations.Configuration) ResourceResolver(com.android.ide.common.resources.ResourceResolver)

Aggregations

ResourceResolver (com.android.ide.common.resources.ResourceResolver)1 Configuration (com.android.tools.idea.configurations.Configuration)1 NlComponent (com.android.tools.idea.uibuilder.model.NlComponent)1 DrawTextRegion (com.android.tools.idea.uibuilder.scene.draw.DrawTextRegion)1