Skip to content

Commit

Permalink
Merge pull request #4 from OpenCraft/fix-ellipsis-rule
Browse files Browse the repository at this point in the history
Fixed rule that decides if Ellipsis should appear
  • Loading branch information
cleberhenriques authored May 30, 2018
2 parents 44e066a + 1c45d07 commit 641adf5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.text.TextWatcher;
import android.text.method.TransformationMethod;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.MotionEvent;
Expand Down Expand Up @@ -1420,7 +1421,7 @@ protected void onDraw(@NonNull Canvas canvas) {
}

// draw the bottom ellipsis
if (hasFocus() && singleLineEllipsis && getScrollX() != 0) {
if (hasFocus() && singleLineEllipsis && textReachedEndOfEditText()) {
paint.setColor(isInternalValid() ? primaryColor : errorColor);
float startY = lineStartY + bottomSpacing;
int ellipsisStartX;
Expand All @@ -1439,6 +1440,10 @@ protected void onDraw(@NonNull Canvas canvas) {
super.onDraw(canvas);
}

private boolean textReachedEndOfEditText() {
return getPaint().measureText(getText().toString()) > getWidth();
}

private boolean shouldDrawBottomText() {

if (tempErrorText != null) {
Expand Down
17 changes: 17 additions & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,23 @@
android:text="Touch The Ellipsis And See What Happens. Touch The Ellipsis And See What Happens."
app:met_singleLineEllipsis="true" />


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="app:met_singleLineEllipsis=&quot;true&quot;\n#singLineEllipsis will force android:singleLine to true# Gravity"
android:textColor="#888888"
android:textSize="14sp" />

<com.rengwuxian.materialedittext.MaterialEditText
android:id="@+id/singleLineEllipsisEte"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:hint="Single Line Ellipsis"
android:text="Touch The Ellipsis And See What Happens. Touch The Ellipsis And See What Happens."
app:met_singleLineEllipsis="true" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 641adf5

Please sign in to comment.