Android Open Source - android-cassowary-layout Cassowary Util






From Project

Back to project page android-cassowary-layout.

License

The source code is released under:

Apache License

If you think the Android project android-cassowary-layout listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package no.agens.cassowarylayout.util;
//www. j  av a2  s .  co  m

import org.pybee.cassowary.Constraint;
import org.pybee.cassowary.ConstraintNotFound;
import org.pybee.cassowary.Expression;
import org.pybee.cassowary.SimplexSolver;
import org.pybee.cassowary.Strength;
import org.pybee.cassowary.Variable;

/**
 * Created by alex on 08/10/2014.
 */
public class CassowaryUtil {

    public static Constraint createWeakEqualityConstraint() {
        return new Constraint(new Expression(null, -1.0, 0), Strength.WEAK);
    }

    public static Constraint createWeakInequalityConstraint(Variable variable, Constraint.Operator op, double value) {
        Expression expression = new Expression(value);
        return new Constraint(variable, op, expression, Strength.STRONG);
    }

    public static void updateConstraint(Constraint constraint, Variable variable, double value) {
        Expression expression = constraint.expression();
        expression.set_constant(value);
        expression.setVariable(variable, -1);
    }


    public static Constraint createOrUpdateLeqInequalityConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) {
        if (constraint != null) {
            double currentValue = constraint.expression().constant();
            // This will not detect if the variable or strength has changed.
            if (currentValue != value) {
                try {
                    solver.removeConstraint(constraint);
                } catch (ConstraintNotFound constraintNotFound) {
                    constraintNotFound.printStackTrace();
                }
                constraint = null;
            }
        }

        if (constraint == null) {
            constraint = new Constraint(variable, Constraint.Operator.LEQ, value, Strength.STRONG);
            solver.addConstraint(constraint);
        }

        return constraint;
    }

    public static Constraint createOrUpdateLinearEquationConstraint(Variable variable, Constraint constraint, double value, SimplexSolver solver) {
        if (constraint != null) {
            double currentValue = constraint.expression().constant();
            // This will not detect if the variable, strength or operation has changed
            if (currentValue != value) {
                try {
                    solver.removeConstraint(constraint);
                } catch (ConstraintNotFound constraintNotFound) {
                    constraintNotFound.printStackTrace();
                }
                constraint = null;
            }
        }

        if (constraint == null) {
            constraint = new Constraint(variable, Constraint.Operator.EQ, value, Strength.STRONG);
            solver.addConstraint(constraint);
        }

        return constraint;
    }
}




Java Source Code List

no.agens.cassowarylayout.ApplicationTest.java
no.agens.cassowarylayout.CassowaryLayout.java
no.agens.cassowarylayout.CassowaryModel.java
no.agens.cassowarylayout.ChildNode.java
no.agens.cassowarylayout.ConstraintParser.java
no.agens.cassowarylayout.ContainerNode.java
no.agens.cassowarylayout.DefaultViewIdResolver.java
no.agens.cassowarylayout.Node.java
no.agens.cassowarylayout.ViewIdResolver.java
no.agens.cassowarylayout.util.CassowaryUtil.java
no.agens.cassowarylayout.util.DimensionParserTest.java
no.agens.cassowarylayout.util.DimensionParser.java
no.agens.cassowarylayout.util.ExpressionTokenizerTest.java
no.agens.cassowarylayout.util.InfixToPostFixTest.java
no.agens.cassowarylayout.util.MeasureSpecUtils.java
no.agens.cassowarylayout.util.TimerUtil.java
no.agens.cassowarylayoutdemo.ApplicationTest.java
no.agens.cassowarylayoutdemo.CassowaryLayoutInLinearLayoutActivity.java
no.agens.cassowarylayoutdemo.CassowaryLayoutMatchParentActivity.java
no.agens.cassowarylayoutdemo.CassowaryLayoutWrapContentActivity.java
no.agens.cassowarylayoutdemo.CassowaryLayoutsInCassowaryLayoutActivity.java
no.agens.cassowarylayoutdemo.CassowaryLayoutsInListViewActivity.java
no.agens.cassowarylayoutdemo.CenterInParentActivity.java
no.agens.cassowarylayoutdemo.CenterViewRelativeToSiblingActivity.java
no.agens.cassowarylayoutdemo.ChessBoardActivity.java
no.agens.cassowarylayoutdemo.DynamicWidthActivity.java
no.agens.cassowarylayoutdemo.ExampleMenuActivity.java
no.agens.cassowarylayoutdemo.FixedAspectRatioDemoActivity.java
no.agens.cassowarylayoutdemo.IntrinsicHeightTextInWrapContentContainerActivity.java
no.agens.cassowarylayoutdemo.LayoutParamsSwitcherActivity.java
no.agens.cassowarylayoutdemo.LinearLayoutInCassowaryLayoutActivity.java
no.agens.cassowarylayoutdemo.ParallaxScrollingActivity.java
no.agens.cassowarylayoutdemo.PreSetupTestActivity.java
no.agens.cassowarylayoutdemo.ProgrammaticDemoActivity.java
no.agens.cassowarylayoutdemo.XmlLayoutDemoActivity.java
no.agens.cassowarylayoutdemo.util.EditRatioDialog.java