PageRenderTime 8ms CodeModel.GetById 1ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/TextEnlarger/src/com/ideal/textenlarger/ExtendedCheckBoxListView.java

http://eyes-free.googlecode.com/
Java | 107 lines | 58 code | 18 blank | 31 comment | 0 complexity | 2b3f8bd478646cbbbd8786c07f3d02a3 MD5 | raw file
  1/*
  2 * Copyright (C) 2010 The IDEAL Group
  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 com.ideal.textenlarger;
 17
 18
 19import android.content.Context;
 20import android.view.View;
 21import android.widget.CheckBox;
 22import android.widget.LinearLayout;
 23import android.widget.TextView;
 24
 25/**
 26 * Class needed by ApplicationsListActivity.
 27 *
 28 * This was taken from a checkbox list tutorial at anddev.org:
 29 * http://www.anddev.org/extended_checkbox_list__extension_of_checkbox_text_list_tu-t5734.html
 30 */
 31public class ExtendedCheckBoxListView extends LinearLayout {
 32    
 33    private TextView mText;
 34    private CheckBox mCheckBox;
 35    private ExtendedCheckBox mCheckBoxText;
 36    
 37    public ExtendedCheckBoxListView(final Context context, ExtendedCheckBox aCheckBoxifiedText) {
 38         super(context);
 39         
 40         // Set orientation to be horizontal
 41         this.setOrientation(HORIZONTAL);
 42         
 43         mCheckBoxText = aCheckBoxifiedText;
 44         mCheckBox = new CheckBox(context);
 45         mCheckBox.setPadding(0, 0, 20, 0);
 46         
 47         // Set the initial state of the checkbox.
 48         mCheckBox.setChecked(aCheckBoxifiedText.getChecked());
 49         
 50         // Set the right listener for the checkbox, used to update
 51         // our data holder to change it's state after a click too
 52         mCheckBox.setOnClickListener( new OnClickListener()
 53         {
 54         	/**
 55         	 *  When clicked change the state of the 'mCheckBoxText' too!
 56         	 */
 57			public void onClick(View v) {
 58				mCheckBoxText.setChecked(getCheckBoxState());
 59				((ApplicationsListActivity) context).setCheckedState(mText.getText().toString(), getCheckBoxState());
 60			}
 61         });         
 62         
 63         // Add the checkbox
 64         addView(mCheckBox,  new LinearLayout.LayoutParams(
 65                   android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
 66         
 67         mText = new TextView(context);
 68         mText.setText(aCheckBoxifiedText.getText());;
 69         addView(mText, new LinearLayout.LayoutParams(
 70                   android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
 71         
 72         // Remove some controls in order to prevent a strange flickering when clicking on the TextView!
 73         mText.setClickable(false);
 74         mText.setFocusable(false);
 75         mText.setFocusableInTouchMode(false);
 76
 77         setOnClickListener( new OnClickListener()
 78         {
 79        	// Check or unchecked the current checkbox!        	
 80			public void onClick(View v) {
 81				toggleCheckBoxState();
 82				((ApplicationsListActivity) context).setCheckedState(mText.getText().toString(), getCheckBoxState());
 83			}
 84
 85         });    
 86    }
 87    
 88    public void setText(String words) {
 89         mText.setText(words);
 90    }
 91    
 92    public void toggleCheckBoxState()
 93    {
 94    	setCheckBoxState(!getCheckBoxState());
 95    }
 96    
 97    public void setCheckBoxState(boolean bool)
 98    {
 99    	mCheckBox.setChecked(bool);
100    	mCheckBoxText.setChecked(bool);
101    }
102    
103    public boolean getCheckBoxState()
104    {
105    	return mCheckBox.isChecked();
106    }
107}