package com.partynetwork.iparty.imessage;
import android.content.Context;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.EditText;
public class CustomEditText extends EditText {
private Drawable dLeft;
private Drawable dRight;
private Rect rBounds;
private Rect lBounds;
public CustomEditText(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public CustomEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public CustomEditText(Context context) {
super(context);
}
@Override
public void setCompoundDrawables(Drawable left, Drawable top,
Drawable right, Drawable bottom) {
if (left != null) {
dLeft = left;
}
if (right != null) {
dRight = right;
}
super.setCompoundDrawables(left, top, right, bottom);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP && dRight != null
&& dLeft != null) {
lBounds = dLeft.getBounds();
rBounds = dRight.getBounds();
final int x = (int) event.getX();
final int y = (int) event.getY();
// System.out.println("x:/y: "+x+"/"+y);
// System.out.println("bounds: "+bounds.left+"/"+bounds.right+"/"+bounds.top+"/"+bounds.bottom);
// check to make sure the touch event was within the bounds of the
// drawable
if (x >= (this.getWidth() - rBounds.width()- this.getPaddingRight())
&& x <= (this.getRight())
&& y >= this.getPaddingTop()
&& y <= (this.getHeight() - this.getPaddingBottom())) {
// System.out.println("touch");
this.setText("speak");
event.setAction(MotionEvent.ACTION_CANCEL);// use this to
// prevent the
// keyboard from
// coming up
}else if (x >= 0
&& x <= (this.getPaddingLeft()+lBounds.width())
&& y >= this.getPaddingTop()
&& y <= (this.getHeight() - this.getPaddingBottom())) {
// System.out.println("touch");
this.setText("search");
event.setAction(MotionEvent.ACTION_CANCEL);// use this to
// prevent the
// keyboard from
// coming up
}
}
return super.onTouchEvent(event);
}
@Override
protected void finalize() throws Throwable {
dRight = null;
dLeft = null;
rBounds = null;
lBounds = null;
super.finalize();
}
}