• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package android.databinding;
17 
18 /**
19  * Listener set on {@link ViewDataBinding#addOnRebindCallback(OnRebindCallback)} that
20  * is called when bound values must be reevaluated in {@link
21  * ViewDataBinding#executePendingBindings()}.
22  */
23 public abstract class OnRebindCallback<T extends ViewDataBinding> {
24 
25     /**
26      * Called when values in a ViewDataBinding should be reevaluated. This does not
27      * mean that values will actually change, but only that something in the data
28      * model that affects the bindings has been perturbed.
29      * <p>
30      * Return true to allow the reevaluation to happen or false if the reevaluation
31      * should be stopped. If false is returned, it is the responsibility of the
32      * OnRebindListener implementer to explicitly call {@link
33      * ViewDataBinding#executePendingBindings()}.
34      * <p>
35      * The default implementation only returns <code>true</code>.
36      *
37      * @param binding The ViewDataBinding that is reevaluating its bound values.
38      * @return true to indicate that the reevaluation should continue or false to
39      * halt evaluation.
40      */
onPreBind(T binding)41     public boolean onPreBind(T binding) {
42         return true;
43     }
44 
45     /**
46      * Called after all callbacks have completed {@link #onPreBind(ViewDataBinding)} when
47      * one or more of the calls has returned <code>false</code>.
48      * <p>
49      * The default implementation does nothing.
50      *
51      * @param binding The ViewDataBinding that is reevaluating its bound values.
52      */
onCanceled(T binding)53     public void onCanceled(T binding) {
54     }
55 
56     /**
57      * Called after values have been reevaluated in {@link
58      * ViewDataBinding#executePendingBindings()}. This is only called if all listeners have
59      * returned true from {@link #onPreBind(ViewDataBinding)}.
60      * <p>
61      * The default implementation does nothing.
62      *
63      * @param binding The ViewDataBinding that is reevaluating its bound values.
64      */
onBound(T binding)65     public void onBound(T binding) {
66     }
67 }
68