Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6bd7cd42 authored by Yigit Boyar's avatar Yigit Boyar
Browse files

Support for layout files in multiple resource folders

Multiple layout files with the same name now share a common interface.
They also share all variables no matter where it is defined.
If a variable is NOT used in one of the layout files, its implementation
does not create a field BUT STILL creates the setter (to implement
the base interface).

If the same view id is used for two different types of views, return
type in the interface is android.view.View. If it is an include,
the return value is IViewDataBinder.

Change-Id: Ie3cc2bb8ec5ea48b71337e314ec588a050d714df
parent 8323229b
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -10,15 +10,14 @@
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

buildscript {
    repositories {
        jcenter()
        mavenLocal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.0.0'
        classpath  'com.android.databinding:dataBinder:0.3-SNAPSHOT'
        classpath "com.android.tools.build:gradle:$androidPluginVersion"
        classpath "com.android.databinding:dataBinder:$version"
    }
}
apply plugin: 'com.android.application'
+27 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ package com.android.databinding.testapp;
import com.android.databinding.library.DataBinder;
import com.android.databinding.library.IViewDataBinder;

import android.content.pm.ActivityInfo;
import android.os.Looper;
import android.test.ActivityInstrumentationTestCase2;

@@ -23,17 +24,24 @@ public class BaseDataBinderTest<T extends IViewDataBinder>
        extends ActivityInstrumentationTestCase2<TestActivity> {
    private Class<T> mBinderClass;
    private int mLayoutId;
    private int mOrientation;
    protected T mBinder;

    public BaseDataBinderTest(final Class<T> binderClass, final int layoutId) {
        this(binderClass, layoutId, ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    }

    public BaseDataBinderTest(final Class<T> binderClass, final int layoutId, final int orientation) {
        super(TestActivity.class);
        mBinderClass = binderClass;
        mLayoutId = layoutId;
        mOrientation = orientation;
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        getActivity().setRequestedOrientation(mOrientation);
        createBinder();
    }

@@ -47,6 +55,7 @@ public class BaseDataBinderTest<T extends IViewDataBinder>
            @Override
            public void run() {
                mBinder = DataBinder.createBinder(mBinderClass, getActivity(), mLayoutId, null);
                getActivity().setContentView(mBinder.getRoot());
            }
        });
        if (!isMainThread()) {
@@ -54,4 +63,22 @@ public class BaseDataBinderTest<T extends IViewDataBinder>
        }
        assertNotNull(mBinder);
    }

    protected void assertMethod(Class<?> klass, String methodName) throws NoSuchMethodException {
        assertEquals(klass, mBinder.getClass().getDeclaredMethod(methodName).getReturnType());
    }

    protected void assertField(Class<?> klass, String fieldName) throws NoSuchFieldException {
        assertEquals(klass, mBinder.getClass().getDeclaredField(fieldName).getType());
    }

    protected void assertNoField(String fieldName) {
        Exception[] ex = new Exception[1];
        try {
            mBinder.getClass().getDeclaredField(fieldName);
        } catch (NoSuchFieldException e) {
            ex[0] = e;
        }
        assertNotNull(ex[0]);
    }
}
+25 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.databinding.testapp;

import com.android.databinding.library.IViewDataBinder;

import android.content.pm.ActivityInfo;

public class BaseLandDataBinderTest<T extends IViewDataBinder> extends BaseDataBinderTest<T> {

    public BaseLandDataBinderTest(Class<T> binderClass, int layoutId) {
        super(binderClass, layoutId, ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}
+18 −0
Original line number Diff line number Diff line
/*
 * 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 com.android.databinding.testapp;

public class LandDataBinderTest {

}
+13 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import com.android.databinding.testapp.vo.ViewBindingObject;

import android.content.res.ColorStateList;
import android.os.Build;
import android.test.UiThreadTest;
import android.view.View;

public class ViewBindingAdapterTest extends BaseDataBinderTest<ViewAdapterTestBinder> {
@@ -33,9 +34,19 @@ public class ViewBindingAdapterTest extends BaseDataBinderTest<ViewAdapterTestBi
    @Override
    protected void setUp() throws Exception {
        super.setUp();
        try {
            runTestOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mBinder.setViewBinding(mViewBindingObject);
                    mBinder.rebindDirty();
                }
            });
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }

    }

    private void changeValues() throws Throwable {
        runTestOnUiThread(new Runnable() {
Loading