package com.sogouchat.smsmms;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.EditText;
public class AutoTransEditView extends EditText{
private Context context;
public AutoTransEditView(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
}
public AutoTransEditView(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
// TODO Auto-generated constructor stub
}
public AutoTransEditView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
// TODO Auto-generated constructor stub
}
public void SetTextByMark(String str){
if (str.equals("") || str==null) {
}
else {
setText(MessageTranslate.Trans(context, str));
}
}
public void SetTextByMarkAndSetSelectionEnd(String str){
if (str.equals("") || str==null) {
}
else {
setText(MessageTranslate.Trans(context, str));
setSelection(str.length());
}
}
private String OrcStr=null;
private String CurStr=null;
@Override
protected void onTextChanged(CharSequence text, int start,
int lengthBefore, int lengthAfter) {
// TODO Auto-generated method stub
CurStr = text.toString();
if (OrcStr == null) {
OrcStr = text.toString();
}
super.onTextChanged(text, start, lengthBefore, lengthAfter);
if (CurStr!=null && !CurStr.equals("") && !CurStr.equals(OrcStr)) {
OrcStr = CurStr;
int nSelect = getSelectionEnd();
String string = text.toString();
SetTextByMark(string);
setSelection(nSelect);
}
}
}