Search in sources :

Example 6 with IntValueProperty

use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.

the class IntExpressionsTest method testGreaterThanEqualExpression.

@Test
public void testGreaterThanEqualExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    IntValueProperty rhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isGreaterThanEqualTo(rhs));
    assertThat(result.get()).isTrue();
    rhs.set(10);
    assertThat(result.get()).isFalse();
    lhs.set(10);
    assertThat(result.get()).isTrue();
    rhs.set(20);
    assertThat(result.get()).isFalse();
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 7 with IntValueProperty

use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.

the class ConstraintsTest method testPercent.

@Test
public void testPercent() throws Exception {
    IntValueProperty percentValue = new IntValueProperty(-5);
    percentValue.addConstraint(value -> Math.max(0, Math.min(100, value)));
    assertThat(percentValue.get()).isEqualTo(0);
    percentValue.set(-5);
    assertThat(percentValue.get()).isEqualTo(0);
    percentValue.set(105);
    assertThat(percentValue.get()).isEqualTo(100);
    percentValue.set(42);
    assertThat(percentValue.get()).isEqualTo(42);
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) Test(org.junit.Test)

Example 8 with IntValueProperty

use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.

the class ConstraintsTest method testGreaterThanOne.

@Test
public void testGreaterThanOne() throws Exception {
    IntValueProperty greaterThanOneValue = new IntValueProperty(5);
    greaterThanOneValue.addConstraint(value -> Math.max(1, value));
    assertThat(greaterThanOneValue.get()).isEqualTo(5);
    greaterThanOneValue.set(-5);
    assertThat(greaterThanOneValue.get()).isEqualTo(1);
    greaterThanOneValue.set(105);
    assertThat(greaterThanOneValue.get()).isEqualTo(105);
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) Test(org.junit.Test)

Example 9 with IntValueProperty

use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.

the class BindingsManagerTest method twoWayBindingsCanBeChained.

@Test
public void twoWayBindingsCanBeChained() {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    IntValueProperty a = new IntValueProperty();
    IntValueProperty b = new IntValueProperty();
    IntValueProperty c = new IntValueProperty();
    bindings.bindTwoWay(a, b);
    bindings.bindTwoWay(b, c);
    c.set(30);
    assertThat(a.get()).isEqualTo(30);
    assertThat(b.get()).isEqualTo(30);
    assertThat(c.get()).isEqualTo(30);
    b.set(-100);
    assertThat(a.get()).isEqualTo(-100);
    assertThat(b.get()).isEqualTo(-100);
    assertThat(c.get()).isEqualTo(-100);
    a.set(9);
    assertThat(a.get()).isEqualTo(9);
    assertThat(b.get()).isEqualTo(9);
    assertThat(c.get()).isEqualTo(9);
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) Test(org.junit.Test)

Example 10 with IntValueProperty

use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.

the class BindingsManagerTest method oneWayBindingAffectedByTarget.

@Test
public void oneWayBindingAffectedByTarget() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    IntValueProperty property1 = new IntValueProperty(10);
    IntValueProperty property2 = new IntValueProperty(20);
    bindings.bind(property1, property2);
    assertThat(property1.get()).isEqualTo(20);
    property1.set(30);
    assertThat(property1.get()).isEqualTo(30);
    assertThat(property2.get()).isEqualTo(20);
    property2.set(40);
    assertThat(property1.get()).isEqualTo(40);
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) Test(org.junit.Test)

Aggregations

IntValueProperty (com.android.tools.idea.ui.properties.core.IntValueProperty)23 Test (org.junit.Test)22 BoolValueProperty (com.android.tools.idea.ui.properties.core.BoolValueProperty)13 BindingsManager (com.android.tools.idea.ui.properties.BindingsManager)12 StringValueProperty (com.android.tools.idea.ui.properties.core.StringValueProperty)3 IntProperty (com.android.tools.idea.ui.properties.core.IntProperty)2 AndroidVersion (com.android.sdklib.AndroidVersion)1 TemplateMetadata.getBuildApiString (com.android.tools.idea.templates.TemplateMetadata.getBuildApiString)1 StringExpression (com.android.tools.idea.ui.properties.expressions.string.StringExpression)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 NotNull (org.jetbrains.annotations.NotNull)1