[go: nahoru, domu]

1612997fe2e41366573855f56898b27d4c8787244George Mount/*
2612997fe2e41366573855f56898b27d4c8787244George Mount * Copyright (C) 2015 The Android Open Source Project
3612997fe2e41366573855f56898b27d4c8787244George Mount *
4612997fe2e41366573855f56898b27d4c8787244George Mount * Licensed under the Apache License, Version 2.0 (the "License");
5612997fe2e41366573855f56898b27d4c8787244George Mount * you may not use this file except in compliance with the License.
6612997fe2e41366573855f56898b27d4c8787244George Mount * You may obtain a copy of the License at
7612997fe2e41366573855f56898b27d4c8787244George Mount *
8612997fe2e41366573855f56898b27d4c8787244George Mount *      http://www.apache.org/licenses/LICENSE-2.0
9612997fe2e41366573855f56898b27d4c8787244George Mount *
10612997fe2e41366573855f56898b27d4c8787244George Mount * Unless required by applicable law or agreed to in writing, software
11612997fe2e41366573855f56898b27d4c8787244George Mount * distributed under the License is distributed on an "AS IS" BASIS,
12612997fe2e41366573855f56898b27d4c8787244George Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13612997fe2e41366573855f56898b27d4c8787244George Mount * See the License for the specific language governing permissions and
14612997fe2e41366573855f56898b27d4c8787244George Mount * limitations under the License.
15612997fe2e41366573855f56898b27d4c8787244George Mount */
16fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountpackage android.databinding.adapters;
17612997fe2e41366573855f56898b27d4c8787244George Mount
18716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.databinding.BindingAdapter;
19fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.BindingMethod;
20fead9ca09b117136b35bc5bf137340a754f9edddGeorge Mountimport android.databinding.BindingMethods;
21716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.widget.AbsListView;
22716ba89e7f459f49ea85070d4710c1d79d715298George Mountimport android.widget.AbsListView.OnScrollListener;
233561e3e665698843b1c664385a842e779198960bGeorge Mount
243561e3e665698843b1c664385a842e779198960bGeorge Mount@BindingMethods({
25716ba89e7f459f49ea85070d4710c1d79d715298George Mount        @BindingMethod(type = AbsListView.class, attribute = "android:listSelector", method = "setSelector"),
26716ba89e7f459f49ea85070d4710c1d79d715298George Mount        @BindingMethod(type = AbsListView.class, attribute = "android:scrollingCache", method = "setScrollingCacheEnabled"),
27716ba89e7f459f49ea85070d4710c1d79d715298George Mount        @BindingMethod(type = AbsListView.class, attribute = "android:smoothScrollbar", method = "setSmoothScrollbarEnabled"),
28716ba89e7f459f49ea85070d4710c1d79d715298George Mount        @BindingMethod(type = AbsListView.class, attribute = "android:onMovedToScrapHeap", method = "setRecyclerListener"),
293561e3e665698843b1c664385a842e779198960bGeorge Mount})
303561e3e665698843b1c664385a842e779198960bGeorge Mountpublic class AbsListViewBindingAdapter {
31612997fe2e41366573855f56898b27d4c8787244George Mount
3296b22e7bbbf942aea1079dc8e8d0c4657663e5a7George Mount    @BindingAdapter(value = {"android:onScroll", "android:onScrollStateChanged"},
3396b22e7bbbf942aea1079dc8e8d0c4657663e5a7George Mount            requireAll = false)
34716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public static void setOnScroll(AbsListView view, final OnScroll scrollListener,
35716ba89e7f459f49ea85070d4710c1d79d715298George Mount            final OnScrollStateChanged scrollStateListener) {
36716ba89e7f459f49ea85070d4710c1d79d715298George Mount        view.setOnScrollListener(new OnScrollListener() {
37716ba89e7f459f49ea85070d4710c1d79d715298George Mount            @Override
38716ba89e7f459f49ea85070d4710c1d79d715298George Mount            public void onScrollStateChanged(AbsListView view, int scrollState) {
39716ba89e7f459f49ea85070d4710c1d79d715298George Mount                if (scrollStateListener != null) {
40716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    scrollStateListener.onScrollStateChanged(view, scrollState);
41716ba89e7f459f49ea85070d4710c1d79d715298George Mount                }
42716ba89e7f459f49ea85070d4710c1d79d715298George Mount            }
43716ba89e7f459f49ea85070d4710c1d79d715298George Mount
44716ba89e7f459f49ea85070d4710c1d79d715298George Mount            @Override
45716ba89e7f459f49ea85070d4710c1d79d715298George Mount            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
46716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    int totalItemCount) {
47716ba89e7f459f49ea85070d4710c1d79d715298George Mount                if (scrollListener != null) {
48716ba89e7f459f49ea85070d4710c1d79d715298George Mount                    scrollListener
49716ba89e7f459f49ea85070d4710c1d79d715298George Mount                            .onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount);
50716ba89e7f459f49ea85070d4710c1d79d715298George Mount                }
51716ba89e7f459f49ea85070d4710c1d79d715298George Mount            }
52716ba89e7f459f49ea85070d4710c1d79d715298George Mount        });
53716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
54716ba89e7f459f49ea85070d4710c1d79d715298George Mount
55716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public interface OnScroll {
56716ba89e7f459f49ea85070d4710c1d79d715298George Mount        void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
57716ba89e7f459f49ea85070d4710c1d79d715298George Mount                int totalItemCount);
58716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
59716ba89e7f459f49ea85070d4710c1d79d715298George Mount
60716ba89e7f459f49ea85070d4710c1d79d715298George Mount    public interface OnScrollStateChanged {
61716ba89e7f459f49ea85070d4710c1d79d715298George Mount        void onScrollStateChanged(AbsListView view, int scrollState);
62716ba89e7f459f49ea85070d4710c1d79d715298George Mount    }
63612997fe2e41366573855f56898b27d4c8787244George Mount}
64