Merge "Don't limit carrier text when using large screen" into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-11-01 22:19:45 +00:00
committed by Android (Google) Code Review
3 changed files with 49 additions and 0 deletions

View File

@@ -35,4 +35,6 @@
<!-- Percentage of displacement for items in QQS to guarantee matching with bottom of clock at <!-- Percentage of displacement for items in QQS to guarantee matching with bottom of clock at
fade_out_complete_frame --> fade_out_complete_frame -->
<dimen name="percent_displacement_at_fade_out" format="float">0.1066</dimen> <dimen name="percent_displacement_at_fade_out" format="float">0.1066</dimen>
<integer name="qs_carrier_max_em">7</integer>
</resources> </resources>

View File

@@ -19,6 +19,7 @@ package com.android.systemui.qs.carrier;
import android.annotation.StyleRes; import android.annotation.StyleRes;
import android.content.Context; import android.content.Context;
import android.content.res.ColorStateList; import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.View; import android.view.View;
@@ -33,6 +34,7 @@ import com.android.settingslib.Utils;
import com.android.settingslib.graph.SignalDrawable; import com.android.settingslib.graph.SignalDrawable;
import com.android.systemui.FontSizeUtils; import com.android.systemui.FontSizeUtils;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.util.LargeScreenUtils;
import java.util.Objects; import java.util.Objects;
@@ -72,6 +74,7 @@ public class QSCarrier extends LinearLayout {
mMobileSignal = findViewById(R.id.mobile_signal); mMobileSignal = findViewById(R.id.mobile_signal);
mCarrierText = findViewById(R.id.qs_carrier_text); mCarrierText = findViewById(R.id.qs_carrier_text);
mSpacer = findViewById(R.id.spacer); mSpacer = findViewById(R.id.spacer);
updateResources();
} }
/** /**
@@ -142,4 +145,20 @@ public class QSCarrier extends LinearLayout {
public void updateTextAppearance(@StyleRes int resId) { public void updateTextAppearance(@StyleRes int resId) {
FontSizeUtils.updateFontSizeFromStyle(mCarrierText, 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)
);
}
} }

View File

@@ -24,6 +24,7 @@ import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper; import android.testing.TestableLooper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.TextView;
import androidx.test.filters.SmallTest; import androidx.test.filters.SmallTest;
@@ -48,6 +49,7 @@ public class QSCarrierTest extends SysuiTestCase {
public void setUp() throws Exception { public void setUp() throws Exception {
mTestableLooper = TestableLooper.get(this); mTestableLooper = TestableLooper.get(this);
LayoutInflater inflater = LayoutInflater.from(mContext); LayoutInflater inflater = LayoutInflater.from(mContext);
mContext.ensureTestableResources();
mTestableLooper.runWithLooper(() -> mTestableLooper.runWithLooper(() ->
mQSCarrier = (QSCarrier) inflater.inflate(R.layout.qs_carrier, null)); mQSCarrier = (QSCarrier) inflater.inflate(R.layout.qs_carrier, null));
@@ -119,4 +121,30 @@ public class QSCarrierTest extends SysuiTestCase {
mQSCarrier.updateState(c, true); mQSCarrier.updateState(c, true);
assertEquals(View.GONE, mQSCarrier.getRSSIView().getVisibility()); 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());
}
} }