Revert "Screen Resolution: add space for 4-digit values"

This reverts commit 14050c89f5.

Reason for revert: b/406416297
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:626993cd66a1e2b75cc40445373d22503f73f19e)
Merged-In: Ib683398cf3c3753d2874e4f108c0bb09a9635ab5
Change-Id: Ib683398cf3c3753d2874e4f108c0bb09a9635ab5
This commit is contained in:
Vadym Omelnytskyi
2025-03-30 23:52:42 -07:00
committed by Android Build Coastguard Worker
parent e1c2d09e01
commit a2d3155609
2 changed files with 1 additions and 63 deletions

View File

@@ -28,7 +28,6 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.Display; import android.view.Display;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting; import androidx.annotation.VisibleForTesting;
import androidx.preference.PreferenceScreen; import androidx.preference.PreferenceScreen;
@@ -53,15 +52,11 @@ import java.util.concurrent.atomic.AtomicInteger;
/** Preference fragment used for switch screen resolution */ /** Preference fragment used for switch screen resolution */
@SearchIndexable @SearchIndexable
public class ScreenResolutionFragment extends RadioButtonPickerFragment { public class ScreenResolutionFragment extends RadioButtonPickerFragment {
public static final String NON_BREAKING_SPACE = "\u00A0";
private static final String TAG = "ScreenResolution"; private static final String TAG = "ScreenResolution";
private Resources mResources; private Resources mResources;
private static final String SCREEN_RESOLUTION = "user_selected_resolution"; private static final String SCREEN_RESOLUTION = "user_selected_resolution";
private static final String SCREEN_RESOLUTION_KEY = "screen_resolution"; private static final String SCREEN_RESOLUTION_KEY = "screen_resolution";
private static final int RESOLUTION_SPACE_THRESHOLD = 1_000;
private static final int RESOLUTION_SPACE_THRESHOLD_DIGIT_AMOUNT = 3;
private Display mDefaultDisplay; private Display mDefaultDisplay;
private String[] mScreenResolutionOptions; private String[] mScreenResolutionOptions;
private Set<Point> mResolutions; private Set<Point> mResolutions;
@@ -99,45 +94,12 @@ public class ScreenResolutionFragment extends RadioButtonPickerFragment {
private SpannableString getResolutionSpannable(int width, int height) { private SpannableString getResolutionSpannable(int width, int height) {
String resolutionString = getResolutionString(width, height); String resolutionString = width + " x " + height;
String accessibleText = mResources.getString( String accessibleText = mResources.getString(
R.string.screen_resolution_delimiter_a11y, width, height); R.string.screen_resolution_delimiter_a11y, width, height);
return Utils.createAccessibleSequence(resolutionString, accessibleText); return Utils.createAccessibleSequence(resolutionString, accessibleText);
} }
/**
* Formats the given width and height into a resolution string, inserting non-breaking
* spaces as thousand separators if the values exceed a specified threshold.
*
* @param width The width value.
* @param height The height value.
* @return A formatted string representing the resolution (e.g., "1 080 x 1 280").
* Non-breaking spaces are used to ensure the numbers and 'x' stay together.
* If the width or height is less than RESOLUTION_SPACE_THRESHOLD, no spaces are added.
*/
@NonNull
@VisibleForTesting
static String getResolutionString(int width, int height) {
StringBuilder resolutionStrBldr = new StringBuilder(String.valueOf(width));
if (width >= RESOLUTION_SPACE_THRESHOLD) {
int insertWidthPosition =
resolutionStrBldr.length() - RESOLUTION_SPACE_THRESHOLD_DIGIT_AMOUNT;
resolutionStrBldr.insert(insertWidthPosition, NON_BREAKING_SPACE);
}
resolutionStrBldr.append(NON_BREAKING_SPACE);
resolutionStrBldr.append("x");
resolutionStrBldr.append(NON_BREAKING_SPACE);
resolutionStrBldr.append(String.valueOf(height));
if (height >= RESOLUTION_SPACE_THRESHOLD) {
int insertHeightPosition =
resolutionStrBldr.length() - RESOLUTION_SPACE_THRESHOLD_DIGIT_AMOUNT;
resolutionStrBldr.insert(insertHeightPosition, NON_BREAKING_SPACE);
}
return resolutionStrBldr.toString();
}
@Override @Override
protected int getPreferenceScreenResId() { protected int getPreferenceScreenResId() {
return R.xml.screen_resolution_settings; return R.xml.screen_resolution_settings;

View File

@@ -110,28 +110,4 @@ public class ScreenResolutionFragmentTest {
assertThat(preference.getSummary().toString().contentEquals(summary)).isTrue(); assertThat(preference.getSummary().toString().contentEquals(summary)).isTrue();
} }
@Test
public void testResolutionString_widthAndHeightAboveThreshold() {
String result = ScreenResolutionFragment.getResolutionString(1080, 1280);
assertThat(result).isEqualTo("1\u00A0080\u00A0x\u00A01\u00A0280");
}
@Test
public void testResolutionString_widthAboveThreshold_heightBelowThreshold() {
String result = ScreenResolutionFragment.getResolutionString(1080, 980);
assertThat(result).isEqualTo("1\u00A0080\u00A0x\u00A0980");
}
@Test
public void testResolutionString_widthBelowThreshold_heightBelowThreshold() {
String result = ScreenResolutionFragment.getResolutionString(980, 980);
assertThat(result).isEqualTo("980\u00A0x\u00A0980");
}
@Test
public void testResolutionString_widthBelowThreshold_heightAboveThreshold() {
String result = ScreenResolutionFragment.getResolutionString(980, 1080);
assertThat(result).isEqualTo("980\u00A0x\u00A01\u00A0080");
}
} }