/* * File: label.java * This file is part of Tico, an application * to create and perform interactive communication boards to be * used by people with severe motor disabilities. * * Authors: Eduardo Ferrer * * Date: September-2012 * * Company: Universidad de Zaragoza, CPS, DIIS * * License: * 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 . */ package android.TICO; import android.TICO.Views.RectangleView; import android.content.Context; import android.graphics.Color; import android.graphics.Typeface; import android.graphics.drawable.GradientDrawable; import android.view.ViewGroup.LayoutParams; import android.widget.RelativeLayout; import android.widget.TextView; /** * Defines a label and its attributes. * * @author Eduardo Ferrer * @version 1.0 Sep, 2012 */ public class label { /** * The label type used as attribute in XML encoding and decoding for Android. */ private RectangleView rv; private TextView tv; public final static int HORIZONTAL_FIT_TEXT_MARGIN = 6; public final static int VERTICAL_FIT_TEXT_MARGIN = 4; /** * Creates a new label. * @param marginLeft The number marginLeft of pixels of the left margin * @param marginTop The number marginTop of pixels of the top margin * @param frameSize The size of the frame in pixels of the label * @param text The text of the label * @param textSize The desired size of the text in the label * @param typeface The font of the text * @param textStyle The style of the text * @param context The context that contains the textArea */ public label(int marginLeft,int marginTop,int frameSize,String text,float textSize,Typeface typeface,int textStyle,Context context){ //Creamos la etiqueta con los datos leidos //primero el texto tv=new TextView(context); tv.setSingleLine(); RelativeLayout.LayoutParams ptext = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); ptext.setMargins(marginLeft+frameSize+HORIZONTAL_FIT_TEXT_MARGIN, marginTop+frameSize+VERTICAL_FIT_TEXT_MARGIN,0, 0); tv.setLayoutParams(ptext); tv.setText(text); tv.setTextSize(textSize); tv.setTypeface(typeface,textStyle); //luego el marco rv = new RectangleView(marginLeft, marginTop, (int)(marginLeft+tv.getPaint().measureText(tv.getText().toString()))+2*(frameSize+HORIZONTAL_FIT_TEXT_MARGIN), marginTop + tv.getLineHeight()+(int)tv.getPaint().descent()+2*(frameSize+VERTICAL_FIT_TEXT_MARGIN), context); rv.setBorderWidth(frameSize); } /** * Set the color of the text * @param color The integer that defines the desired color for the text */ public void setTextColor(int textColor){ tv.setTextColor(textColor); } /** * Set the frame color of the label * @param color The color of the label frame */ public void setFrameColor(int frameColor){ rv.setColor(frameColor); } /** * Set the background color and the gradient * @param backgroundColor The color of the background * @param gradient The gradient color of the background */ public void setBackgroundColor(int backgroundColor,int gradient){ if(gradient==Color.TRANSPARENT){ //color simple de fondo rv.setBackgroundColor(backgroundColor); }else{ //color con gradiente de fondo int Colors[]=new int[2]; Colors[0]=backgroundColor; Colors[1]=gradient; GradientDrawable g = new GradientDrawable(GradientDrawable.Orientation.TL_BR, Colors); //Colors is an array with 2 heximal values as int. rv.setBackgroundDrawable(g); } } /** * Add the label to a RelativeLayout * @param lay Relative layout that will contain the label */ public void addTo(RelativeLayout lay){ lay.addView(rv); lay.addView(tv); } }