• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ListenerUtil类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.databinding.adapters.ListenerUtil的典型用法代码示例。如果您正苦于以下问题:Java ListenerUtil类的具体用法?Java ListenerUtil怎么用?Java ListenerUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ListenerUtil类属于android.databinding.adapters包,在下文中一共展示了ListenerUtil类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: setOnRefreshListener

import android.databinding.adapters.ListenerUtil; //导入依赖的package包/类
@BindingAdapter(value = {"onRefreshListener", "refreshingAttrChanged"}, requireAll = false)
public static void setOnRefreshListener(final SwipeRefreshLayout view,
                                        final SwipeRefreshLayout.OnRefreshListener listener,
                                        final InverseBindingListener refreshingAttrChanged) {

    SwipeRefreshLayout.OnRefreshListener newValue = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            if (listener != null) {
                if (refreshingAttrChanged != null) {
                    refreshingAttrChanged.onChange();
                }
                listener.onRefresh();
            }
        }
    };

    SwipeRefreshLayout.OnRefreshListener oldValue = ListenerUtil.trackListener(view, newValue, R.id.onRefreshListener);
    if (oldValue != null) {
        view.setOnRefreshListener(null);
    }
    view.setOnRefreshListener(newValue);
}
 
开发者ID:saiwu-bigkoo,项目名称:Android-MVVMFramework,代码行数:24,代码来源:BindingConfig.java


示例2: setListeners

import android.databinding.adapters.ListenerUtil; //导入依赖的package包/类
/**
 * This is how you implement 2-way data binding of a custom attribute if you want to maintain
 * a custom listener interface - OnHueChangeListener, in this case - while also leveraging
 * the synthetic attributes hueAttrChanged (the InverseBindingListener). For an example of
 * how to implement custom 2-way binding with just the synthetic AttrChanged attribute's
 * InverseBindingListener, see DocumentView or LayerListView's currentLayer 2-way binding
 * (along with the InverseBindingMethod declarations in DocumentViewModelBindingAdapters).
 *
 * @param view                   The view we're 2-way binding to.
 * @param onHueChangeListener    The OnHueChangeListener bound by the developer on the view
 *                               in question.
 * @param inverseBindingListener Synthetic attribute representing an InverseBindingListener
 *                               for changes to the hue attribute.
 */
@BindingAdapter(value = {"onHueChange", "hueAttrChanged"}, requireAll = false)
public static void setListeners(HuePicker view,
                                final HuePicker.OnHueChangeListener onHueChangeListener,
                                final InverseBindingListener inverseBindingListener) {
    HuePicker.OnHueChangeListener newListener;
    if (inverseBindingListener == null) {
        // If the synthetic listener param is null, just keep track of the listener set in
        // the binding
        newListener = onHueChangeListener;
    } else {
        // Otherwise define a new listener to wraps both listeners and invoke them at the
        // right time within the new listener if they are non-null
        newListener = new HuePicker.OnHueChangeListener() {
            @Override
            public void onHueChange(HuePicker huePicker, float hue) {
                if (onHueChangeListener != null) {
                    onHueChangeListener.onHueChange(huePicker, hue);
                }
                inverseBindingListener.onChange();
            }
        };
    }

    // Use track listener to record listener we're adding and return any old listeners
    // registered through this method so that on rebind we don't add duplicate listeners
    HuePicker.OnHueChangeListener oldListener = ListenerUtil.trackListener(view, newListener,
            R.id.hueChangeListener);

    // Remove the old listener we set using this BindingAdapter, if there is one
    if (oldListener != null) {
        view.removeHueChangeListener(oldListener);
    }

    // Add our new listener
    if (newListener != null) {
        view.addHueChangeListener(newListener);
    }
}
 
开发者ID:google,项目名称:spline,代码行数:53,代码来源:HuePickerBindingAdapters.java


示例3: setEntries

import android.databinding.adapters.ListenerUtil; //导入依赖的package包/类
/**
 * Assign a list of items to a ViewGroup. This is used with the {@code entries} and
 * {@code layout} attributes in the application namespace. Example Usage:
 * <pre><code>&lt;LinearLayout
 *     android:layout_width="match_parent"
 *     android:layout_height="wrap_content"
 *     android:orientation="vertical"
 *     app:entries="@{items}"
 *     app:layout="@{@layout/item}"/&gt;
 * </code></pre>
 * <p>
 * In the above, {@code items} is a List or ObservableList. {@code layout} does not
 * need to be hard-coded, but most commonly will be. This BindingAdapter will work
 * with any ViewGroup that only needs addView() and removeView() to manage its Views.
 * <p>
 * The layout, &commat;layout/item for example, must have a single variable named
 * {@code data}.
 */
@BindingAdapter({"entries", "layout"})
public static <T> void setEntries(ViewGroup viewGroup,
        List<T> oldEntries, int oldLayoutId,
        List<T> newEntries, int newLayoutId) {
    if (oldEntries == newEntries && oldLayoutId == newLayoutId) {
        return; // nothing has changed
    }

    EntryChangeListener listener =
            ListenerUtil.getListener(viewGroup, R.id.entryListener);
    if (oldEntries != newEntries && listener != null && oldEntries instanceof ObservableList) {
        ((ObservableList)oldEntries).removeOnListChangedCallback(listener);
    }

    if (newEntries == null) {
        viewGroup.removeAllViews();
    } else {
        if (newEntries instanceof ObservableList) {
            if (listener == null) {
                listener =
                        new EntryChangeListener(viewGroup, newLayoutId);
                ListenerUtil.trackListener(viewGroup, listener,
                        R.id.entryListener);
            } else {
                listener.setLayoutId(newLayoutId);
            }
            if (newEntries != oldEntries) {
                ((ObservableList)newEntries).addOnListChangedCallback(listener);
            }
        }
        resetViews(viewGroup, newLayoutId, newEntries);
    }
}
 
开发者ID:google,项目名称:android-ui-toolkit-demos,代码行数:52,代码来源:ListBindingAdapters.java


示例4: setOnScrollListener

import android.databinding.adapters.ListenerUtil; //导入依赖的package包/类
@BindingAdapter(value = {"onScrollStateChanged", "onScrolled"}, requireAll = false)
public static void setOnScrollListener(RecyclerView view, final OnScrollStateChanged scrollStateChanged, final OnScrolled scrolled) {
    final RecyclerView.OnScrollListener newValue;
    if (scrollStateChanged == null && scrolled == null) {
        newValue = null;
    } else {
        newValue = new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (scrollStateChanged != null) {
                    scrollStateChanged.onScrollStateChanged(recyclerView, newState);
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                if (scrolled != null) {
                    scrolled.onScrolled(recyclerView, dx, dy);
                }
            }
        };
    }
    final RecyclerView.OnScrollListener oldValue = ListenerUtil.trackListener(view, newValue, R.id.recyclerViewOnScrollListener);
    if (oldValue != null) {
        view.removeOnScrollListener(oldValue);
    }
    if (newValue != null) {
        view.addOnScrollListener(newValue);
    }
}
 
开发者ID:evant,项目名称:PokeMVVM,代码行数:31,代码来源:RecyclerViewBindingAdapters.java


示例5: setListener

import android.databinding.adapters.ListenerUtil; //导入依赖的package包/类
@BindingAdapter({"android:onViewDetachedFromWindow", "android:onViewAttachedToWindow"})
public static void setListener(View view, final OnViewDetachedFromWindow detach,
                               final OnViewAttachedToWindow attach) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
        final View.OnAttachStateChangeListener newListener;
        if (detach == null && attach == null) {
            newListener = null;
        } else {
            newListener = new View.OnAttachStateChangeListener() {
                @Override
                public void onViewAttachedToWindow(View v) {
                    if (attach != null) {
                        attach.onViewAttachedToWindow(v);
                    }
                }

                @Override
                public void onViewDetachedFromWindow(View v) {
                    if (detach != null) {
                        detach.onViewDetachedFromWindow(v);
                    }
                }
            };
        }
        final View.OnAttachStateChangeListener oldListener = ListenerUtil.trackListener(view,
                newListener, R.id.onAttachStateChangeListener);
        if (oldListener != null) {
            view.removeOnAttachStateChangeListener(oldListener);
        }
        if (newListener != null) {
            view.addOnAttachStateChangeListener(newListener);
        }
    }
}
 
开发者ID:yunair,项目名称:MVVMDemo,代码行数:35,代码来源:CustomListener.java



注:本文中的android.databinding.adapters.ListenerUtil类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InputEdge类代码示例发布时间:2022-05-22
下一篇:
Java DiscoveryStrategyConfig类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap