diff options
3 files changed, 49 insertions, 0 deletions
diff --git a/packages/SystemUI/res/values/integers.xml b/packages/SystemUI/res/values/integers.xml index e30d4415a0c4..8d4431520c75 100644 --- a/packages/SystemUI/res/values/integers.xml +++ b/packages/SystemUI/res/values/integers.xml @@ -35,4 +35,6 @@ <!-- Percentage of displacement for items in QQS to guarantee matching with bottom of clock at fade_out_complete_frame --> <dimen name="percent_displacement_at_fade_out" format="float">0.1066</dimen> + + <integer name="qs_carrier_max_em">7</integer> </resources>
\ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java index 703b95a082dc..b5ceeaed4904 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java +++ b/packages/SystemUI/src/com/android/systemui/qs/carrier/QSCarrier.java @@ -19,6 +19,7 @@ package com.android.systemui.qs.carrier; import android.annotation.StyleRes; import android.content.Context; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.text.TextUtils; import android.util.AttributeSet; import android.view.View; @@ -33,6 +34,7 @@ import com.android.settingslib.Utils; import com.android.settingslib.graph.SignalDrawable; import com.android.systemui.FontSizeUtils; import com.android.systemui.R; +import com.android.systemui.util.LargeScreenUtils; import java.util.Objects; @@ -72,6 +74,7 @@ public class QSCarrier extends LinearLayout { mMobileSignal = findViewById(R.id.mobile_signal); mCarrierText = findViewById(R.id.qs_carrier_text); mSpacer = findViewById(R.id.spacer); + updateResources(); } /** @@ -142,4 +145,20 @@ public class QSCarrier extends LinearLayout { public void updateTextAppearance(@StyleRes int resId) { FontSizeUtils.updateFontSizeFromStyle(mCarrierText, resId); } + + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + updateResources(); + } + + private void updateResources() { + boolean useLargeScreenHeader = + LargeScreenUtils.shouldUseLargeScreenShadeHeader(getResources()); + mCarrierText.setMaxEms( + useLargeScreenHeader + ? Integer.MAX_VALUE + : getResources().getInteger(R.integer.qs_carrier_max_em) + ); + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java index 99a17a613041..9115ab3bacca 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/qs/carrier/QSCarrierTest.java @@ -24,6 +24,7 @@ import android.testing.AndroidTestingRunner; import android.testing.TestableLooper; import android.view.LayoutInflater; import android.view.View; +import android.widget.TextView; import androidx.test.filters.SmallTest; @@ -48,6 +49,7 @@ public class QSCarrierTest extends SysuiTestCase { public void setUp() throws Exception { mTestableLooper = TestableLooper.get(this); LayoutInflater inflater = LayoutInflater.from(mContext); + mContext.ensureTestableResources(); mTestableLooper.runWithLooper(() -> mQSCarrier = (QSCarrier) inflater.inflate(R.layout.qs_carrier, null)); @@ -119,4 +121,30 @@ public class QSCarrierTest extends SysuiTestCase { mQSCarrier.updateState(c, true); assertEquals(View.GONE, mQSCarrier.getRSSIView().getVisibility()); } + + @Test + public void testCarrierNameMaxWidth_smallScreen_fromResource() { + int maxEms = 10; + mContext.getOrCreateTestableResources().addOverride(R.integer.qs_carrier_max_em, maxEms); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_use_large_screen_shade_header, false); + TextView carrierText = mQSCarrier.requireViewById(R.id.qs_carrier_text); + + mQSCarrier.onConfigurationChanged(mContext.getResources().getConfiguration()); + + assertEquals(maxEms, carrierText.getMaxEms()); + } + + @Test + public void testCarrierNameMaxWidth_largeScreen_maxInt() { + int maxEms = 10; + mContext.getOrCreateTestableResources().addOverride(R.integer.qs_carrier_max_em, maxEms); + mContext.getOrCreateTestableResources() + .addOverride(R.bool.config_use_large_screen_shade_header, true); + TextView carrierText = mQSCarrier.requireViewById(R.id.qs_carrier_text); + + mQSCarrier.onConfigurationChanged(mContext.getResources().getConfiguration()); + + assertEquals(Integer.MAX_VALUE, carrierText.getMaxEms()); + } } |