Search in sources :

Example 16 with BindingsManager

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

the class AdapterPropertiesTest method bindingStringToIntAdapterWorks.

@Test
public void bindingStringToIntAdapterWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty intString = new StringValueProperty("0");
    IntProperty intValue = new IntValueProperty(1);
    bindings.bindTwoWay(new StringToIntAdapterProperty(intString), intValue);
    assertThat(intString.get()).isEqualTo("1");
    intString.set("-99");
    assertThat(intValue.get()).isEqualTo(-99);
    intString.set("not an int");
    assertThat(intValue.get()).isEqualTo(-99);
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 17 with BindingsManager

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

the class AdapterPropertiesTest method bindingStringToDoubleAdapterWorks.

@Test
public void bindingStringToDoubleAdapterWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty doubleString = new StringValueProperty("0");
    DoubleProperty doubleValue = new DoubleValueProperty(20.0);
    // Defaults to 1 decimal point of precision
    StringToDoubleAdapterProperty adapterProperty = new StringToDoubleAdapterProperty(doubleString);
    bindings.bindTwoWay(adapterProperty, doubleValue);
    assertThat(doubleString.get()).isEqualTo("20.0");
    assertThat(adapterProperty.inSync().get()).isTrue();
    doubleString.set("100.5");
    assertThat(doubleValue.get()).isWithin(0.01).of(100.5);
    assertThat(adapterProperty.inSync().get()).isTrue();
    doubleString.set("not a double");
    assertThat(doubleValue.get()).isWithin(0.01).of(100.5);
    assertThat(adapterProperty.inSync().get()).isFalse();
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 18 with BindingsManager

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

the class AdapterPropertiesTest method bindingStringToDoubleAdapterWithPrecisionWorks.

@Test
public void bindingStringToDoubleAdapterWithPrecisionWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty doubleString = new StringValueProperty("0");
    DoubleProperty doubleValue = new DoubleValueProperty(0.1234);
    bindings.bindTwoWay(new StringToDoubleAdapterProperty(doubleString, 3), doubleValue);
    assertThat(doubleString.get()).isEqualTo("0.123");
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 19 with BindingsManager

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

the class AdapterPropertiesTest method bindingStringToDoubleAdapterWithLocale.

@Test
public void bindingStringToDoubleAdapterWithLocale() throws Exception {
    Locale.setDefault(Locale.ITALIAN);
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty doubleString = new StringValueProperty("0");
    DoubleProperty doubleValue = new DoubleValueProperty(0.9876);
    bindings.bindTwoWay(new StringToDoubleAdapterProperty(doubleString, 2, 3), doubleValue);
    assertThat(doubleString.get()).isEqualTo("0,988");
    doubleValue.set(0.3);
    assertThat(doubleString.get()).isEqualTo("0,30");
    doubleValue.set(0.299);
    assertThat(doubleString.get()).isEqualTo("0,299");
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 20 with BindingsManager

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

the class IntExpressionsTest method testLessThanEqualValueExpression.

@Test
public void testLessThanEqualValueExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isLessThanEqualTo(10));
    assertThat(result.get()).isTrue();
    lhs.set(10);
    assertThat(result.get()).isTrue();
    lhs.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)

Aggregations

BindingsManager (com.android.tools.idea.ui.properties.BindingsManager)38 Test (org.junit.Test)38 BoolValueProperty (com.android.tools.idea.ui.properties.core.BoolValueProperty)27 IntValueProperty (com.android.tools.idea.ui.properties.core.IntValueProperty)12 DoubleValueProperty (com.android.tools.idea.ui.properties.core.DoubleValueProperty)11 StringValueProperty (com.android.tools.idea.ui.properties.core.StringValueProperty)4