Back to project page SpunkyCharts.
The source code is released under:
GNU General Public License
If you think the Android project SpunkyCharts listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.jogden.spunkycharts.misc; /* //from w w w.ja v a2 s.c om Copyright (C) 2014 Jonathon Ogden < jeog.dev@gmail.com > This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses. */ import com.jogden.spunkycharts.R; import android.content.Context; import android.content.res.TypedArray; import android.graphics.Color; import android.text.Editable; import android.util.AttributeSet; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.TableLayout; /** Custom view that accepts text and a click to input it */ public class TextInput extends LinearLayout { private final static float DEF_BUTTON_WEIGHT = 7f; private final static int DEF_TEXT_COLOR = Color.BLACK; private float textBoxWeight; private EditText textBox; private Button button; public TextInput(Context context ) { super(context); textBoxWeight = DEF_BUTTON_WEIGHT; _textInput(context); textBox.setTextColor(DEF_TEXT_COLOR); } public TextInput(Context context, AttributeSet attrs ) { super(context, attrs); _extractAttr(context, attrs); } public TextInput( Context context, AttributeSet attrs, int steez ){ super(context, attrs, steez); _extractAttr(context, attrs); } { this.setOrientation(LinearLayout.HORIZONTAL); } public void setOnClickListener(OnClickListener cl) { button.setOnClickListener(cl); } public Editable getText() { return textBox.getText(); } private void _extractAttr( Context context, AttributeSet attrs ){ TypedArray ta = context.obtainStyledAttributes( attrs,R.styleable.CustomSpunky ); TypedArray ta2 = context.obtainStyledAttributes( attrs, new int[]{android.R.attr.textColor} ); textBoxWeight = ta.getFloat( R.styleable.CustomSpunky_button_weight, DEF_BUTTON_WEIGHT ); _textInput(context); textBox.setTextColor( ta2.getColor(0,R.color.black)); textBox.setSingleLine(); ta.recycle(); ta2.recycle(); } private void _textInput(Context context) { textBox = new EditText(context); button = new Button(context); textBox.setLayoutParams( new TableLayout.LayoutParams( 0, LayoutParams.MATCH_PARENT, 10 - textBoxWeight ) ); button.setLayoutParams( new TableLayout.LayoutParams( 0, LayoutParams.MATCH_PARENT, textBoxWeight ) ); this.addView( textBox ); this.addView( button ); } }