summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSai Cheemalapati <saicheems@google.com>2014-06-23 11:30:45 -0700
committerSai Cheemalapati <saicheems@google.com>2014-06-23 16:20:41 -0700
commit9a17f0e3e1a3957c8c2b530171281943bec435f1 (patch)
tree67f22f19d022bbefe9ac2b54bfa5ebd6ac9e03e7 /src
parent13b8948c0cc543f62a68fa32c4692ba16a2e93c6 (diff)
downloadandroid_packages_apps_PhoneCommon-9a17f0e3e1a3957c8c2b530171281943bec435f1.tar.gz
android_packages_apps_PhoneCommon-9a17f0e3e1a3957c8c2b530171281943bec435f1.tar.bz2
android_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
Diffstat (limited to 'src')
-rw-r--r--src/com/android/phone/common/dialpad/DigitsEditText.java33
-rw-r--r--src/com/android/phone/common/util/ViewUtil.java15
-rw-r--r--src/com/android/phone/common/widget/ResizingTextEditText.java54
-rw-r--r--src/com/android/phone/common/widget/ResizingTextTextView.java54
4 files changed, 125 insertions, 31 deletions
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);
+ }
+}