CardViewBindingAdapter.java revision c619d8f69127c1200103d8119101c5f0675661d0
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 */
16package android.databinding.adapters;
17
18import android.databinding.BindingAdapter;
19import android.databinding.BindingMethod;
20import android.databinding.BindingMethods;
21import android.support.v7.widget.CardView;
22
23@BindingMethods({
24        @BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardCornerRadius", method = "setRadius"),
25        @BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardMaxElevation", method = "setMaxCardElevation"),
26        @BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardPreventCornerOverlap", method = "setPreventCornerOverlap"),
27        @BindingMethod(type = android.support.v7.widget.CardView.class, attribute = "cardUseCompatPadding", method = "setUseCompatPadding"),
28})
29public class CardViewBindingAdapter {
30
31    @BindingAdapter("contentPadding")
32    public static void setContentPadding(CardView view, int padding) {
33        view.setContentPadding(padding, padding, padding, padding);
34    }
35
36    @BindingAdapter("contentPaddingLeft")
37    public static void setContentPaddingLeft(CardView view, int left) {
38        int top = view.getContentPaddingTop();
39        int right = view.getContentPaddingRight();
40        int bottom = view.getContentPaddingBottom();
41        view.setContentPadding(left, top, right, bottom);
42    }
43
44    @BindingAdapter("contentPaddingTop")
45    public static void setContentPaddingTop(CardView view, int top) {
46        int left = view.getContentPaddingLeft();
47        int right = view.getContentPaddingRight();
48        int bottom = view.getContentPaddingBottom();
49        view.setContentPadding(left, top, right, bottom);
50    }
51
52    @BindingAdapter("contentPaddingRight")
53    public static void setContentPaddingRight(CardView view, int right) {
54        int left = view.getContentPaddingLeft();
55        int top = view.getContentPaddingTop();
56        int bottom = view.getContentPaddingBottom();
57        view.setContentPadding(left, top, right, bottom);
58    }
59
60    @BindingAdapter("contentPaddingBottom")
61    public static void setContentPaddingBottom(CardView view, int bottom) {
62        int left = view.getContentPaddingLeft();
63        int top = view.getContentPaddingTop();
64        int right = view.getContentPaddingRight();
65        view.setContentPadding(left, top, right, bottom);
66    }
67}
68