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