Search in sources :

Example 21 with IntValueProperty

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

the class ConstraintsTest method testNegative.

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

Example 22 with IntValueProperty

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

the class BindingsManagerTest method twoWayBindingsAffectEachOther.

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

Example 23 with IntValueProperty

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

the class ServiceContextTest method dataModelCanRegisterActionsAndObservableValues.

@Test
public void dataModelCanRegisterActionsAndObservableValues() throws Exception {
    ServiceContext context = new ServiceContext("Gradle");
    {
        final IntValueProperty count = new IntValueProperty();
        Runnable incCount = new Runnable() {

            @Override
            public void run() {
                count.increment();
            }
        };
        final StringValueProperty title = new StringValueProperty("Title");
        final BoolValueProperty enabled = new BoolValueProperty(true);
        Runnable toggleEnabled = new Runnable() {

            @Override
            public void run() {
                enabled.invert();
            }
        };
        context.putValue("count", count);
        context.putValue("title", title);
        context.putValue("enabled", enabled);
        context.putAction("incCount", incCount);
        context.putAction("toggleEnabled", toggleEnabled);
    }
    IntValueProperty count = (IntValueProperty) context.getValue("count");
    StringValueProperty title = (StringValueProperty) context.getValue("title");
    BoolValueProperty enabled = (BoolValueProperty) context.getValue("enabled");
    assertThat(title.get()).isEqualTo("Title");
    assertThat(count.get()).isEqualTo(0);
    context.getAction("incCount").run();
    assertThat(count.get()).isEqualTo(1);
    assertThat(enabled.get()).isTrue();
    context.getAction("toggleEnabled").run();
    assertThat(enabled.get()).isFalse();
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) StringValueProperty(com.android.tools.idea.ui.properties.core.StringValueProperty) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) 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