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 
17 package com.android.tv.ui.sidepanel;
18 
19 import android.util.TypedValue;
20 import android.view.Gravity;
21 import android.view.View;
22 import android.widget.CompoundButton;
23 import android.widget.LinearLayout;
24 import android.widget.TextView;
25 import com.android.tv.R;
26 
27 public class CheckBoxItem extends CompoundButtonItem {
28     private final boolean mLayoutForLargeDescription;
29 
CheckBoxItem(String title)30     public CheckBoxItem(String title) {
31         this(title, null);
32     }
33 
CheckBoxItem(String title, String description)34     public CheckBoxItem(String title, String description) {
35         this(title, description, false);
36     }
37 
CheckBoxItem(String title, String description, boolean layoutForLargeDescription)38     public CheckBoxItem(String title, String description, boolean layoutForLargeDescription) {
39         super(title, description);
40         mLayoutForLargeDescription = layoutForLargeDescription;
41     }
42 
43     @Override
onBind(View view)44     protected void onBind(View view) {
45         super.onBind(view);
46         if (mLayoutForLargeDescription) {
47             CompoundButton checkBox = (CompoundButton) view.findViewById(getCompoundButtonId());
48             LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) checkBox.getLayoutParams();
49             lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
50             lp.topMargin =
51                     view.getResources()
52                             .getDimensionPixelOffset(R.dimen.option_item_check_box_margin_top);
53             checkBox.setLayoutParams(lp);
54 
55             TypedValue outValue = new TypedValue();
56             view.getResources()
57                     .getValue(
58                             R.dimen.option_item_check_box_line_spacing_multiplier, outValue, true);
59 
60             TextView descriptionTextView = (TextView) view.findViewById(getDescriptionViewId());
61             descriptionTextView.setMaxLines(Integer.MAX_VALUE);
62             descriptionTextView.setLineSpacing(0, outValue.getFloat());
63         }
64     }
65 
66     @Override
getResourceId()67     protected int getResourceId() {
68         return R.layout.option_item_check_box;
69     }
70 
71     @Override
getCompoundButtonId()72     protected int getCompoundButtonId() {
73         return R.id.check_box;
74     }
75 
76     @Override
onSelected()77     protected void onSelected() {
78         setChecked(!isChecked());
79     }
80 }
81