Home | History | Annotate | Download | only in sidepanel
      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 
     26 import com.android.tv.R;
     27 
     28 public class CheckBoxItem extends CompoundButtonItem {
     29     private final boolean mLayoutForLargeDescription;
     30 
     31     public CheckBoxItem(String title) {
     32         this(title, null);
     33     }
     34 
     35     public CheckBoxItem(String title, String description) {
     36         this(title, description, false);
     37     }
     38 
     39     public CheckBoxItem(String title, String description, boolean layoutForLargeDescription) {
     40         super(title, description);
     41         mLayoutForLargeDescription = layoutForLargeDescription;
     42     }
     43 
     44     @Override
     45     protected void onBind(View view) {
     46         super.onBind(view);
     47         if (mLayoutForLargeDescription) {
     48             CompoundButton checkBox = (CompoundButton) view.findViewById(getCompoundButtonId());
     49             LinearLayout.LayoutParams lp =
     50                     (LinearLayout.LayoutParams) checkBox.getLayoutParams();
     51             lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
     52             lp.topMargin = view.getResources().getDimensionPixelOffset(
     53                     R.dimen.option_item_check_box_margin_top);
     54             checkBox.setLayoutParams(lp);
     55 
     56             TypedValue outValue = new TypedValue();
     57             view.getResources().getValue(R.dimen.option_item_check_box_line_spacing_multiplier,
     58                     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
     67     protected int getResourceId() {
     68         return R.layout.option_item_check_box;
     69     }
     70 
     71     @Override
     72     protected int getCompoundButtonId() {
     73         return R.id.check_box;
     74     }
     75 
     76     @Override
     77     protected void onSelected() {
     78         setChecked(!isChecked());
     79     }
     80 }