Home | History | Annotate | Download | only in location
      1 /*
      2  * Copyright (C) 2013 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.settings.location;
     18 
     19 import android.content.Context;
     20 import android.preference.CheckBoxPreference;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.widget.TextView;
     24 
     25 import com.android.settings.R;
     26 
     27 /**
     28  * Check box preference with check box replaced by radio button.
     29  *
     30  * Functionally speaking, it's actually a CheckBoxPreference. We only modified
     31  * the widget to RadioButton to make it "look like" a RadioButtonPreference.
     32  *
     33  * In other words, there's no "RadioButtonPreferenceGroup" in this
     34  * implementation. When you check one RadioButtonPreference, if you want to
     35  * uncheck all the other preferences, you should do that by code yourself.
     36  */
     37 public class RadioButtonPreference extends CheckBoxPreference {
     38     public interface OnClickListener {
     39         public abstract void onRadioButtonClicked(RadioButtonPreference emiter);
     40     }
     41 
     42     private OnClickListener mListener = null;
     43 
     44     public RadioButtonPreference(Context context, AttributeSet attrs, int defStyle) {
     45         super(context, attrs, defStyle);
     46         setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
     47     }
     48 
     49     public RadioButtonPreference(Context context, AttributeSet attrs) {
     50         this(context, attrs, com.android.internal.R.attr.checkBoxPreferenceStyle);
     51     }
     52 
     53     public RadioButtonPreference(Context context) {
     54         this(context, null);
     55     }
     56 
     57     void setOnClickListener(OnClickListener listener) {
     58         mListener = listener;
     59     }
     60 
     61     @Override
     62     public void onClick() {
     63         if (mListener != null) {
     64             mListener.onRadioButtonClicked(this);
     65         }
     66     }
     67 
     68     @Override
     69     protected void onBindView(View view) {
     70         super.onBindView(view);
     71 
     72         TextView title = (TextView) view.findViewById(android.R.id.title);
     73         if (title != null) {
     74             title.setSingleLine(false);
     75             title.setMaxLines(3);
     76         }
     77     }
     78 }
     79