diff options
| author | Sai Cheemalapati <saicheems@google.com> | 2014-06-23 11:30:45 -0700 |
|---|---|---|
| committer | Sai Cheemalapati <saicheems@google.com> | 2014-06-23 16:20:41 -0700 |
| commit | 9a17f0e3e1a3957c8c2b530171281943bec435f1 (patch) | |
| tree | 67f22f19d022bbefe9ac2b54bfa5ebd6ac9e03e7 | |
| parent | 13b8948c0cc543f62a68fa32c4692ba16a2e93c6 (diff) | |
| download | packages_apps_PhoneCommon-9a17f0e3e1a3957c8c2b530171281943bec435f1.tar.gz packages_apps_PhoneCommon-9a17f0e3e1a3957c8c2b530171281943bec435f1.tar.bz2 packages_apps_PhoneCommon-9a17f0e3e1a3957c8c2b530171281943bec435f1.zip | |
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
| -rw-r--r-- | res/layout/dialpad_view.xml | 4 | ||||
| -rw-r--r-- | res/values/attrs.xml | 4 | ||||
| -rw-r--r-- | res/values/dimens.xml | 3 | ||||
| -rw-r--r-- | src/com/android/phone/common/dialpad/DigitsEditText.java | 33 | ||||
| -rw-r--r-- | src/com/android/phone/common/util/ViewUtil.java | 15 | ||||
| -rw-r--r-- | src/com/android/phone/common/widget/ResizingTextEditText.java | 54 | ||||
| -rw-r--r-- | src/com/android/phone/common/widget/ResizingTextTextView.java | 54 |
7 files changed, 134 insertions, 33 deletions
diff --git a/res/layout/dialpad_view.xml b/res/layout/dialpad_view.xml index 68de527..e84aa2a 100644 --- a/res/layout/dialpad_view.xml +++ b/res/layout/dialpad_view.xml @@ -45,6 +45,7 @@ android:visibility="gone" /> <view class="com.android.phone.common.dialpad.DigitsEditText" + xmlns:ex="http://schemas.android.com/apk/res-auto" android:id="@+id/digits" android:layout_width="0dp" android:layout_height="match_parent" @@ -61,7 +62,8 @@ android:textColor="@color/dialpad_digits_text_color" android:textCursorDrawable="@null" android:fontFamily="sans-serif-light" - android:textStyle="normal" /> + android:textStyle="normal" + ex:resizing_text_min_size="@dimen/dialpad_digits_text_min_size" /> <ImageButton android:id="@+id/deleteButton" diff --git a/res/values/attrs.xml b/res/values/attrs.xml index 09620a8..1c94a14 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -18,4 +18,8 @@ <declare-styleable name="Dialpad"> <attr name="dialpad_key_button_touch_tint" format="color"/> </declare-styleable> + + <declare-styleable name="ResizingText"> + <attr name="resizing_text_min_size" format="dimension"/> + </declare-styleable> </resources> diff --git a/res/values/dimens.xml b/res/values/dimens.xml index d681d9d..1b30097 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -27,7 +27,8 @@ <dimen name="dialpad_bottom_key_height">65dp</dimen> <dimen name="dialpad_key_plus_size">18sp</dimen> <dimen name="dialpad_horizontal_padding">5dp</dimen> - <dimen name="dialpad_digits_text_size">36dp</dimen> + <dimen name="dialpad_digits_text_size">36sp</dimen> + <dimen name="dialpad_digits_text_min_size">24sp</dimen> <dimen name="dialpad_digits_height">64dp</dimen> <dimen name="dialpad_digits_padding">16dp</dimen> <dimen name="dialpad_digits_menu_right_padding">10dp</dimen> 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)); - } - } } diff --git a/src/com/android/phone/common/util/ViewUtil.java b/src/com/android/phone/common/util/ViewUtil.java index 171eee0..34b6274 100644 --- a/src/com/android/phone/common/util/ViewUtil.java +++ b/src/com/android/phone/common/util/ViewUtil.java @@ -18,9 +18,12 @@ package com.android.phone.common.util; import android.content.res.Resources; import android.graphics.Outline; +import android.graphics.Paint; +import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; import android.widget.ListView; +import android.widget.TextView; import com.android.phone.common.R; @@ -94,4 +97,16 @@ public class ViewUtil { listView.getPaddingEnd(), listView.getPaddingBottom() + fabPadding); listView.setClipToPadding(false); } + + public static void resizeText(TextView textView, int originalTextSize, int minTextSize) { + final Paint paint = textView.getPaint(); + final int width = textView.getWidth(); + if (width == 0) return; + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, originalTextSize); + float ratio = width / paint.measureText(textView.getText().toString()); + if (ratio <= 1.0f) { + textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, + Math.max(minTextSize, originalTextSize * ratio)); + } + } } diff --git a/src/com/android/phone/common/widget/ResizingTextEditText.java b/src/com/android/phone/common/widget/ResizingTextEditText.java new file mode 100644 index 0000000..56a30e7 --- /dev/null +++ b/src/com/android/phone/common/widget/ResizingTextEditText.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.phone.common.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.EditText; + +import com.android.phone.common.R; +import com.android.phone.common.util.ViewUtil; + +/** + * EditText which resizes dynamically with respect to text length. + */ +public class ResizingTextEditText extends EditText { + private final int mOriginalTextSize; + private final int mMinTextSize; + + public ResizingTextEditText(Context context, AttributeSet attrs) { + super(context, attrs); + mOriginalTextSize = (int) getTextSize(); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResizingText); + mMinTextSize = (int) a.getDimension(R.styleable.ResizingText_resizing_text_min_size, + mOriginalTextSize); + a.recycle(); + } + + @Override + protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { + super.onTextChanged(text, start, lengthBefore, lengthAfter); + ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize); + } +} diff --git a/src/com/android/phone/common/widget/ResizingTextTextView.java b/src/com/android/phone/common/widget/ResizingTextTextView.java new file mode 100644 index 0000000..76c1cac --- /dev/null +++ b/src/com/android/phone/common/widget/ResizingTextTextView.java @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.phone.common.widget; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; +import android.widget.TextView; + +import com.android.phone.common.R; +import com.android.phone.common.util.ViewUtil; + +/** + * TextView which resizes dynamically with respect to text length. + */ +public class ResizingTextTextView extends TextView { + private final int mOriginalTextSize; + private final int mMinTextSize; + + public ResizingTextTextView(Context context, AttributeSet attrs) { + super(context, attrs); + mOriginalTextSize = (int) getTextSize(); + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ResizingText); + mMinTextSize = (int) a.getDimension(R.styleable.ResizingText_resizing_text_min_size, + mOriginalTextSize); + a.recycle(); + } + + @Override + protected void onTextChanged(CharSequence text, int start, int lengthBefore, int lengthAfter) { + super.onTextChanged(text, start, lengthBefore, lengthAfter); + ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize); + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + ViewUtil.resizeText(this, mOriginalTextSize, mMinTextSize); + } +} |
