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