use of com.android.tools.idea.rendering.RenderResult in project android by JetBrains.
the class ConvertToConstraintLayoutAction method inferConstraints.
private static void inferConstraints(NlModel model) {
RenderResult result = model.getRenderResult();
if (result == null || !result.getRenderResult().isSuccess()) {
return;
}
ApplicationManager.getApplication().invokeLater(() -> {
final ConstraintModel constraintModel = ConstraintModel.getConstraintModel(model);
if (constraintModel != null) {
int dpi = model.getConfiguration().getDensity().getDpiValue();
constraintModel.setDpiValue(dpi);
constraintModel.updateNlModel(null, model.getComponents(), true);
// Infer new constraints
WidgetsScene scene = constraintModel.getScene();
try {
Scout.inferConstraints(scene);
} catch (Throwable t) {
Logger.getInstance(ConvertToConstraintLayoutAction.class).warn(t);
}
WriteCommandAction.runWriteCommandAction(model.getProject(), "Infer Constraints", null, new Runnable() {
@Override
public void run() {
constraintModel.saveToXML(true);
constraintModel.setNeedsAnimateConstraints(ConstraintAnchor.SCOUT_CREATOR);
// Finally remove the conversion x/y/width/height attributes
List<NlComponent> components = model.getComponents();
for (NlComponent root : components) {
removeAbsolutePositionAndSizes(root);
}
}
}, model.getFile());
}
}, ModalityState.any());
}
Aggregations