Skip to content

Commit

Permalink
Merge pull request #3 from joaortk/master
Browse files Browse the repository at this point in the history
Fixed clear button drawing behind text
  • Loading branch information
cleber-henriques-ilegra committed Aug 17, 2017
2 parents cefe6f2 + ee0b68c commit 3acf883
Showing 1 changed file with 8 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public class MaterialEditText extends MaterialBaseEditText {
public static final int FLOATING_LABEL_NORMAL = 1;
public static final int FLOATING_LABEL_HIGHLIGHT = 2;

final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
/**
* the color for the disabled dotted underline.
*/
Expand Down Expand Up @@ -788,14 +792,7 @@ public void setPaddings(int left, int top, int right, int bottom) {
* Set paddings to the correct values
*/
private void correctPaddings() {
int buttonsWidthLeft = 0, buttonsWidthRight = 0;
int buttonsWidth = iconOuterWidth * getButtonsCount();
if (isRTL()) {
buttonsWidthLeft = buttonsWidth;
} else {
buttonsWidthRight = buttonsWidth;
}
super.setPadding(innerPaddingLeft + extraPaddingLeft + buttonsWidthLeft, innerPaddingTop + extraPaddingTop, innerPaddingRight + extraPaddingRight + buttonsWidthRight, innerPaddingBottom + extraPaddingBottom);
super.setPadding(innerPaddingLeft + extraPaddingLeft, innerPaddingTop + extraPaddingTop, innerPaddingRight + extraPaddingRight, innerPaddingBottom + extraPaddingBottom);
}

private int getButtonsCount() {
Expand Down Expand Up @@ -1307,17 +1304,7 @@ protected void onDraw(@NonNull Canvas canvas) {

// draw the clear button
if (hasFocus() && showClearButton && !TextUtils.isEmpty(getText()) && isEnabled()) {
paint.setAlpha(255);
int buttonLeft;
if (isRTL()) {
buttonLeft = startX;
} else {
buttonLeft = endX - iconOuterWidth;
}
Bitmap clearButtonBitmap = clearButtonBitmaps[0];
buttonLeft += (iconOuterWidth - clearButtonBitmap.getWidth()) / 2;
int iconTop = lineStartY + bottomSpacing - iconOuterHeight + (iconOuterHeight - clearButtonBitmap.getHeight()) / 2;
canvas.drawBitmap(clearButtonBitmap, buttonLeft, iconTop, paint);
setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.met_ic_clear, 0);
}

// draw the underline
Expand Down Expand Up @@ -1508,6 +1495,7 @@ public boolean onTouchEvent(MotionEvent event) {
if (clearButtonClicking) {
if (!TextUtils.isEmpty(getText())) {
setText(null);
setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
}
clearButtonClicking = false;
}
Expand All @@ -1527,18 +1515,7 @@ public boolean onTouchEvent(MotionEvent event) {
}

private boolean insideClearButton(MotionEvent event) {
float x = event.getX();
float y = event.getY();
int startX = (iconLeftBitmaps == null ? 0 : (iconOuterWidth + iconPadding));
int endX = (iconRightBitmaps == null ? getWidth() : getWidth() - iconOuterWidth - iconPadding);
int buttonLeft;
if (isRTL()) {
buttonLeft = startX;
} else {
buttonLeft = endX - 2 * iconOuterWidth;
}
int buttonTop = getHeight() - getPaddingBottom() + bottomSpacing - iconOuterHeight;
return (x >= buttonLeft && x < buttonLeft + iconOuterWidth && y >= buttonTop && y < buttonTop + iconOuterHeight);
return (event.getRawX() >= (getRight() - getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width()));
}

private int checkLength(CharSequence text) {
Expand Down

0 comments on commit 3acf883

Please sign in to comment.