public class

ViewGroupBindingAdapter

extends java.lang.Object

 java.lang.Object

↳androidx.databinding.adapters.ViewGroupBindingAdapter

Gradle dependencies

compile group: 'androidx.databinding', name: 'adapters', version: '3.2.0-alpha11'

  • groupId: androidx.databinding
  • artifactId: adapters
  • version: 3.2.0-alpha11

Artifact androidx.databinding:adapters:3.2.0-alpha11 it located at Google repository (https://maven.google.com/)

Androidx class mapping:

androidx.databinding.adapters.ViewGroupBindingAdapter android.databinding.adapters.ViewGroupBindingAdapter

Summary

Constructors
publicViewGroupBindingAdapter()

Methods
public static voidsetAnimateLayoutChanges(ViewGroup view, boolean animate)

public static voidsetListener(ViewGroup view, ViewGroupBindingAdapter.OnAnimationStart start, ViewGroupBindingAdapter.OnAnimationEnd end, ViewGroupBindingAdapter.OnAnimationRepeat repeat)

public static voidsetListener(ViewGroup view, ViewGroupBindingAdapter.OnChildViewAdded added, ViewGroupBindingAdapter.OnChildViewRemoved removed)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public ViewGroupBindingAdapter()

Methods

public static void setAnimateLayoutChanges(ViewGroup view, boolean animate)

public static void setListener(ViewGroup view, ViewGroupBindingAdapter.OnChildViewAdded added, ViewGroupBindingAdapter.OnChildViewRemoved removed)

Source

/*
 * 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 androidx.databinding.adapters;

import android.animation.LayoutTransition;
import android.annotation.TargetApi;
import androidx.databinding.BindingAdapter;
import androidx.databinding.BindingMethod;
import androidx.databinding.BindingMethods;
import android.os.Build;
import androidx.annotation.RestrictTo;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.OnHierarchyChangeListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;

/**
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY)
@BindingMethods({
        @BindingMethod(type = android.view.ViewGroup.class, attribute = "android:alwaysDrawnWithCache", method = "setAlwaysDrawnWithCacheEnabled"),
        @BindingMethod(type = android.view.ViewGroup.class, attribute = "android:animationCache", method = "setAnimationCacheEnabled"),
        @BindingMethod(type = android.view.ViewGroup.class, attribute = "android:splitMotionEvents", method = "setMotionEventSplittingEnabled"),
})
public class ViewGroupBindingAdapter {

    @TargetApi(Build.VERSION_CODES.HONEYCOMB)
    @BindingAdapter({"android:animateLayoutChanges"})
    public static void setAnimateLayoutChanges(ViewGroup view, boolean animate) {
        if (animate) {
            view.setLayoutTransition(new LayoutTransition());
        } else {
            view.setLayoutTransition(null);
        }
    }

    @BindingAdapter(value = {"android:onChildViewAdded", "android:onChildViewRemoved"},
            requireAll = false)
    public static void setListener(ViewGroup view, final OnChildViewAdded added,
            final OnChildViewRemoved removed) {
        if (added == null && removed == null) {
            view.setOnHierarchyChangeListener(null);
        } else {
            view.setOnHierarchyChangeListener(new OnHierarchyChangeListener() {
                @Override
                public void onChildViewAdded(View parent, View child) {
                    if (added != null) {
                        added.onChildViewAdded(parent, child);
                    }
                }

                @Override
                public void onChildViewRemoved(View parent, View child) {
                    if (removed != null) {
                        removed.onChildViewRemoved(parent, child);
                    }
                }
            });
        }
    }

    @BindingAdapter(value = {"android:onAnimationStart", "android:onAnimationEnd",
            "android:onAnimationRepeat"}, requireAll = false)
    public static void setListener(ViewGroup view, final OnAnimationStart start,
            final OnAnimationEnd end, final OnAnimationRepeat repeat) {
        if (start == null && end == null && repeat == null) {
            view.setLayoutAnimationListener(null);
        } else {
            view.setLayoutAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    if (start != null) {
                        start.onAnimationStart(animation);
                    }
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                    if (end != null) {
                        end.onAnimationEnd(animation);
                    }
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                    if (repeat != null) {
                        repeat.onAnimationRepeat(animation);
                    }
                }
            });
        }
    }

    public interface OnChildViewAdded {
        void onChildViewAdded(View parent, View child);
    }

    public interface OnChildViewRemoved {
        void onChildViewRemoved(View parent, View child);
    }

    public interface OnAnimationStart {
        void onAnimationStart(Animation animation);
    }

    public interface OnAnimationEnd {
        void onAnimationEnd(Animation animation);
    }

    public interface OnAnimationRepeat {
        void onAnimationRepeat(Animation animation);
    }
}