From 9a17f0e3e1a3957c8c2b530171281943bec435f1 Mon Sep 17 00:00:00 2001 From: Sai Cheemalapati Date: Mon, 23 Jun 2014 11:30:45 -0700 Subject: Add text resizing to InCallUI name field (2/2). Set maximum size of primary name text to 45 pt. Scales down to minimum size of 34 pt. Bug: 15457502 Change-Id: I12dabf66cbefaa4ad458abdb910e8b0417f5b234 --- .../phone/common/dialpad/DigitsEditText.java | 33 ++-------------------- 1 file changed, 2 insertions(+), 31 deletions(-) (limited to 'src/com/android/phone/common/dialpad/DigitsEditText.java') diff --git a/src/com/android/phone/common/dialpad/DigitsEditText.java b/src/com/android/phone/common/dialpad/DigitsEditText.java index b2022aa..f6e87b7 100644 --- a/src/com/android/phone/common/dialpad/DigitsEditText.java +++ b/src/com/android/phone/common/dialpad/DigitsEditText.java @@ -28,18 +28,15 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import com.android.phone.common.R; +import com.android.phone.common.widget.ResizingTextEditText; /** * EditText which suppresses IME show up. */ -public class DigitsEditText extends EditText { - // Only scale the text down to 66% smaller at most. - private static final float MIN_TEXT_RESIZE_RATIO = 0.66f; - private final float mOriginalTextSize; +public class DigitsEditText extends ResizingTextEditText { public DigitsEditText(Context context, AttributeSet attrs) { super(context, attrs); - mOriginalTextSize = getTextSize(); setInputType(getInputType() | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); setShowSoftInputOnFocus(false); } @@ -65,30 +62,4 @@ public class DigitsEditText extends EditText { } return ret; } - - @Override - protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { - super.onTextChanged(text, start, lengthBefore, lengthAfter); - resizeText(getWidth()); - } - - @Override - protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - resizeText(w); - } - - private void resizeText(int width) { - if (width == 0) { - return; - } - final Paint paint = getPaint(); - setTextSize(TypedValue.COMPLEX_UNIT_PX, mOriginalTextSize); - - float ratio = width / paint.measureText(getText().toString()); - if (ratio <= 1.0f) { - setTextSize(TypedValue.COMPLEX_UNIT_PX, - mOriginalTextSize * Math.max(MIN_TEXT_RESIZE_RATIO, ratio)); - } - } } -- cgit v1.2.3