diff options
author | Yigit Boyar <yboyar@google.com> | 2015-05-20 17:06:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-05-20 17:06:59 +0000 |
commit | 0ba9cf91183c16e18f8055e9d08a6618f4f60019 (patch) | |
tree | cc0467accae7431536e70d08e78a0f361763d3ee /integration-tests/TestApp/app | |
parent | b9e4aa96812692a7dcf468445e64bc5b30d3c79a (diff) | |
parent | 8533f27db6c31b0c295ae62d314dbf07ea640571 (diff) | |
download | data-binding-0ba9cf91183c16e18f8055e9d08a6618f4f60019.tar.gz |
Merge "Properly handle constant binding expressions"
Diffstat (limited to 'integration-tests/TestApp/app')
5 files changed, 186 insertions, 2 deletions
diff --git a/integration-tests/TestApp/app/src/androidTest/java/android/databinding/testapp/ConstantWithConditionalTest.java b/integration-tests/TestApp/app/src/androidTest/java/android/databinding/testapp/ConstantWithConditionalTest.java new file mode 100644 index 00000000..37ff9397 --- /dev/null +++ b/integration-tests/TestApp/app/src/androidTest/java/android/databinding/testapp/ConstantWithConditionalTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.databinding.testapp; + +import android.databinding.testapp.databinding.ConstantBindingWithConditionalBinding; +import android.databinding.testapp.vo.BasicObject; +import android.databinding.testapp.vo.ConstantBindingTestObject; +import android.test.UiThreadTest; + +import java.util.ArrayList; + +public class ConstantWithConditionalTest extends BaseDataBinderTest<ConstantBindingWithConditionalBinding>{ + + public ConstantWithConditionalTest() { + super(ConstantBindingWithConditionalBinding.class); + } + + @UiThreadTest + public void testValues() { + initBinder(); + mBinder.executePendingBindings(); + BasicObject basicObject = new BasicObject(); + basicObject.setField1("tt"); + basicObject.setField2("blah"); + ConstantBindingTestObject obj = new ConstantBindingTestObject(); + mBinder.setVm(obj); + mBinder.executePendingBindings(); + assertTrue(mBinder.myTextView.hasFixedSize()); + assertTrue(mBinder.progressBar.isIndeterminate()); + + obj.setErrorMessage("blah"); + mBinder.invalidateAll(); + mBinder.executePendingBindings(); + assertFalse(mBinder.progressBar.isIndeterminate()); + + obj.setErrorMessage(null); + ArrayList<String> list = new ArrayList<>(); + obj.setCountryModels(list); + mBinder.invalidateAll(); + mBinder.executePendingBindings(); + assertTrue(mBinder.progressBar.isIndeterminate()); + + list.add("abc"); + mBinder.invalidateAll(); + mBinder.executePendingBindings(); + assertFalse(mBinder.progressBar.isIndeterminate()); + + } +} diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/view/MyTextView.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/view/MyTextView.java new file mode 100644 index 00000000..e109cac7 --- /dev/null +++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/view/MyTextView.java @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.databinding.testapp.view; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.TextView; + +public class MyTextView extends TextView { + private boolean mHasFixedSize; + public MyTextView(Context context) { + super(context); + } + public MyTextView(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public MyTextView(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public MyTextView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + public void setHasFixedSize(boolean hasFixedSize){ + mHasFixedSize = hasFixedSize; + } + + public boolean hasFixedSize() { + return mHasFixedSize; + } +} diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ConstantBindingTestObject.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ConstantBindingTestObject.java new file mode 100644 index 00000000..051d8fc9 --- /dev/null +++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ConstantBindingTestObject.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2015 The Android Open Source Project + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.databinding.testapp.vo; + +import java.util.List; + +public class ConstantBindingTestObject { + private List<String> mCountryModels; + private String mErrorMessage; + + public List<String> getCountryModels() { + return mCountryModels; + } + + public String getErrorMessage() { + return mErrorMessage; + } + + public void setCountryModels(List<String> countryModels) { + this.mCountryModels = countryModels; + } + + public void setErrorMessage(String errorMessage) { + this.mErrorMessage = errorMessage; + } +} diff --git a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java index a955e81d..bdb438eb 100644 --- a/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java +++ b/integration-tests/TestApp/app/src/main/java/android/databinding/testapp/vo/ViewBindingObject.java @@ -24,7 +24,7 @@ public class ViewBindingObject extends BindingAdapterBindingObject { @Bindable private int mBackgroundTint = 0xFF00FF00; @Bindable - private boolean mFadeScrollbars = false; + private boolean mFadeScrollbars = true; @Bindable private int mNextFocusForward = R.id.padding; @Bindable @@ -150,7 +150,7 @@ public class ViewBindingObject extends BindingAdapterBindingObject { public void changeValues() { mBackgroundTint = 0xFFFF0000; - mFadeScrollbars = true; + mFadeScrollbars = false; mNextFocusForward = R.id.paddingStartEnd; mNextFocusLeft = R.id.paddingTopBottom; mNextFocusRight = R.id.backgroundTint; diff --git a/integration-tests/TestApp/app/src/main/res/layout/constant_binding_with_conditional.xml b/integration-tests/TestApp/app/src/main/res/layout/constant_binding_with_conditional.xml new file mode 100644 index 00000000..cd7f2809 --- /dev/null +++ b/integration-tests/TestApp/app/src/main/res/layout/constant_binding_with_conditional.xml @@ -0,0 +1,43 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + ~ Copyright (C) 2015 The Android Open Source Project + ~ Licensed under the Apache License, Version 2.0 (the "License"); + ~ you may not use this file except in compliance with the License. + ~ You may obtain a copy of the License at + ~ http://www.apache.org/licenses/LICENSE-2.0 + ~ Unless required by applicable law or agreed to in writing, software + ~ distributed under the License is distributed on an "AS IS" BASIS, + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + ~ See the License for the specific language governing permissions and + ~ limitations under the License. + --> +<layout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto"> + + <data> + <variable + name="vm" + type="android.databinding.testapp.vo.ConstantBindingTestObject" /> + </data> + + <FrameLayout + android:layout_width="match_parent" + android:layout_height="match_parent"> + + <android.databinding.testapp.view.MyTextView + android:id="@+id/my_text_view" + android:layout_width="match_parent" + android:layout_height="match_parent" + app:hasFixedSize="@{true}" + /> + + + <ProgressBar + android:id="@+id/progress_bar" + style="@android:style/Widget.ProgressBar.Horizontal" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + app:indeterminate='@{vm.countryModels.size == 0 && vm.errorMessage == null}' /> + </FrameLayout> +</layout> |