Change auto scaling minimum font size in Emergency information and Hint textView.
A lot of localization strings of 'Emergency information' and 'Tap again to open'
will be truncated by largest font and display size,
reduce auto scaling minimum font size to prevent this problem.
Bug: 70124370
Test: manual on Pixel 2
Change-Id: Icca550912a8660f1195a534d1faf0a2663b03387
diff --git a/src/com/android/phone/EmergencyActionGroup.java b/src/com/android/phone/EmergencyActionGroup.java
index 54842f3..b647623 100644
--- a/src/com/android/phone/EmergencyActionGroup.java
+++ b/src/com/android/phone/EmergencyActionGroup.java
@@ -28,8 +28,11 @@
import android.content.pm.ResolveInfo;
import android.provider.Settings;
import android.telephony.TelephonyManager;
+import android.text.Layout;
import android.text.TextUtils;
import android.util.AttributeSet;
+import android.util.TypedValue;
+import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewAnimationUtils;
@@ -80,8 +83,10 @@
mSelectedContainer = (ViewGroup) findViewById(R.id.selected_container);
mSelectedContainer.setOnClickListener(this);
mSelectedLabel = (TextView) findViewById(R.id.selected_label);
+ mSelectedLabel.addOnLayoutChangeListener(mLayoutChangeListener);
mRippleView = findViewById(R.id.ripple_view);
mLaunchHint = findViewById(R.id.launch_hint);
+ mLaunchHint.addOnLayoutChangeListener(mLayoutChangeListener);
}
@Override
@@ -243,6 +248,11 @@
CharSequence buttonText = ((Button) v).getText();
mSelectedLabel.setText(buttonText);
mSelectedLabel.setAutoSizeTextTypeWithDefaults(TextView.AUTO_SIZE_TEXT_TYPE_UNIFORM);
+
+ // In order to trigger OnLayoutChangeListener for reset default minimum font size.
+ mSelectedLabel.requestLayout();
+ mLaunchHint.requestLayout();
+
mSelectedContainer.setVisibility(VISIBLE);
int centerX = v.getLeft() + v.getWidth() / 2;
int centerY = v.getTop() + v.getHeight() / 2;
@@ -267,6 +277,43 @@
mSelectedContainer.requestFocus();
}
+
+ private final OnLayoutChangeListener mLayoutChangeListener = new OnLayoutChangeListener() {
+ @Override
+ public void onLayoutChange(View v, int left, int top, int right, int bottom,
+ int oldLeft,
+ int oldTop, int oldRight, int oldBottom) {
+ decreaseAutoSizeMinTextSize(v);
+ }
+ };
+
+ /**
+ * Prevent some localization string will be truncated if there is low resolution screen
+ * or font size and display size of setting is largest.
+ */
+ private void decreaseAutoSizeMinTextSize(View selectedView) {
+ if (selectedView != null) {
+ if (selectedView instanceof TextView) {
+ TextView textView = (TextView) selectedView;
+ textView.setEllipsize(TextUtils.TruncateAt.END);
+
+ // The textView layout will be null due to it's property is hiding when
+ // initialization.
+ Layout layout = textView.getLayout();
+ if (layout != null) {
+ if (layout.getEllipsisCount(textView.getMaxLines() - 1) > 0) {
+ textView.setAutoSizeTextTypeUniformWithConfiguration(
+ 8,
+ textView.getAutoSizeMaxTextSize(),
+ textView.getAutoSizeStepGranularity(),
+ TypedValue.COMPLEX_UNIT_SP);
+ textView.setGravity(Gravity.CENTER);
+ }
+ }
+ }
+ }
+ }
+
private void animateHintText(View selectedView, View v, Animator reveal) {
selectedView.setTranslationX(
(v.getLeft() + v.getWidth() / 2 - mSelectedContainer.getWidth() / 2) / 5);