package com.chaoran.entiry;

import com.chaoran.imp.InputInterface;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.util.TypedValue;
import android.widget.RelativeLayout;

public class SelfTextBut extends RelativeLayout implements InputInterface {
	private SelfEditText et;
	private SelfButton but;

	public SelfTextBut(Context context) {
		super(context);
		int w = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
				30, context.getResources().getDisplayMetrics());
		et = new SelfEditText(context);
		LayoutParams params = new LayoutParams(
				LayoutParams.FILL_PARENT,
				LayoutParams.FILL_PARENT);
		params.setMargins(0, 0, 0, 0);
		et.setPadding(0, 0, w, 0);
		et.setSingleLine(true);
		// et.setLayoutParams(params);
		et.setId(1);
		addView(et, params);
		but = new SelfButton(context);
		LayoutParams butParams = new LayoutParams(
				w, LayoutParams.FILL_PARENT);

		butParams.rightMargin = 0;
		// butParams.leftMargin=this.getWidth()-10;
		butParams.topMargin = 5;
		butParams.bottomMargin = -2;
		but.setPadding(0, 0, 0, 20);
		// butParams.addRule(RelativeLayout.ALIGN_BASELINE, et.getId());
		butParams.addRule(RelativeLayout.ALIGN_RIGHT, et.getId());
		// butParams.addRule(RelativeLayout.ALIGN_TOP, et.getId());
		// butParams.addRule(RelativeLayout.ALIGN_BOTTOM, et.getId());
		// butParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		// but.setBackgroundColor(Color.BLUE);
		but.setText("…");
		// but.setGravity(Gravity.TOP);
		// Drawable dw1 =
		// this.getResources().getDrawable(R.drawable.ic_action_search);
		// but.setBackgroundResource(R.drawable.cang1);
		addView(but, butParams);
	}

	@Override
	public void setOnFocusChangeListener(OnFocusChangeListener l) {
		et.setOnFocusChangeListener(l);
	}

	@Override
	public void setOnClickListener(OnClickListener l) {
		// TODO Auto-generated method stub
		but.setOnClickListener(l);
	}

	public void setText(CharSequence text) {
		et.setText(text);
	}

	public Editable getText() {
		return et.getText();
	}

	public void setClickFun(String fun) {
		but.clickFun = fun;
	}

	public String getClickFun() {
		return but.clickFun;
	}

	public void setTextSize(float size) {
		et.setTextSize(size);
	}

	public void setEnabled(boolean b) {
		et.setEnabled(b);
		but.setEnabled(b);
	}

	public void setTag(Object tag) {
		et.setTag(tag);
	}

	public Object getTag() {
		return et.getTag();
	}

	@Override
	public void setBackgroundDrawable(Drawable gd) {
		et.setBackgroundDrawable(gd);
	}

	/* 接口方法 */
	public String getDefaultValue() {
		return et.defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		et.defaultValue = defaultValue;
	}

	public void setNextFocus(String focus) {
		et.nextFocus = focus;
	}

	public void setFocusInFun(String fun) {
		et.focusInFun = fun;
	}

	public void setFocusOutFun(String fun) {
		et.focusOutFun = fun;
	}

	public void setInputType(int type) {
		et.setInputType(type);
	}

	public boolean getCloseKeyBoard() {
		return et.getCloseKeyBoard();
	}

	public void setCloseKeyBoard(boolean closeKeyBoard) {
		et.setCloseKeyBoard(closeKeyBoard);
	}

	@Override
	public String getNextFocus() {
		return et.getNextFocus();
	}

	@Override
	public String getFocusInFun() {
		return et.getFocusInFun();
	}

	@Override
	public String getFocusOutFun() {
		return et.getFocusOutFun();
	}

	@Override
	public boolean getIsNull() {
		return et.getIsNull();
	}

	@Override
	public void setIsNull(boolean isNull) {
		et.setIsNull(isNull);
	}

	@Override
	public String getLabel() {
		return et.getLabel();
	}

	@Override
	public void setLabel(String label) {
		et.setLabel(label);
	}

	@Override
	public boolean getIsTextChange() {
		return et.getIsTextChange();
	}

	@Override
	public void setIsTextChange(boolean isTextChange) {
		et.setIsTextChange(isTextChange);
	}

	@Override
	public void setTextColor(int color) {
		et.setTextColor(color);
	}
}
