[Regional Preferences] Remove u extension for subtitle of Language
- Remove the language tag info of subtitle in Settings -> System -> Languages - Syuc same result to entry of numbering system. Bug: b/268278327 Bug: b/268276472 Test: atest passed Test: Manual test passed Change-Id: I46dd0899059e9209b99f5ef3b7b84eb083d4e140
This commit is contained in:
@@ -27,10 +27,16 @@ public class LocaleFeatureProviderImpl implements LocaleFeatureProvider {
|
|||||||
@Override
|
@Override
|
||||||
public String getLocaleNames() {
|
public String getLocaleNames() {
|
||||||
final LocaleList locales = LocalePicker.getLocales();
|
final LocaleList locales = LocalePicker.getLocales();
|
||||||
|
Locale[] arrLocalesWithoutExtension = new Locale[locales.size()];
|
||||||
|
for (int i = 0; i < locales.size(); i++) {
|
||||||
|
arrLocalesWithoutExtension[i] = locales.get(i).stripExtensions();
|
||||||
|
}
|
||||||
final Locale displayLocale = Locale.getDefault();
|
final Locale displayLocale = Locale.getDefault();
|
||||||
return LocaleHelper.toSentenceCase(
|
return LocaleHelper.toSentenceCase(
|
||||||
LocaleHelper.getDisplayLocaleList(
|
LocaleHelper.getDisplayLocaleList(
|
||||||
locales, displayLocale, 2 /* Show up to two locales from the list */),
|
new LocaleList(arrLocalesWithoutExtension),
|
||||||
|
displayLocale,
|
||||||
|
2 /* Show up to two locales from the list */),
|
||||||
displayLocale);
|
displayLocale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,12 +17,9 @@
|
|||||||
package com.android.settings.regionalpreferences;
|
package com.android.settings.regionalpreferences;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.LocaleList;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
import com.android.settings.core.BasePreferenceController;
|
||||||
|
import com.android.settings.localepicker.LocaleFeatureProviderImpl;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.StringJoiner;
|
|
||||||
|
|
||||||
/** A controller for the entry of Numbering System's page */
|
/** A controller for the entry of Numbering System's page */
|
||||||
public class NumberingSystemController extends BasePreferenceController {
|
public class NumberingSystemController extends BasePreferenceController {
|
||||||
@@ -50,12 +47,6 @@ public class NumberingSystemController extends BasePreferenceController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getSummary() {
|
public CharSequence getSummary() {
|
||||||
LocaleList localeList = LocaleList.getDefault();
|
return new LocaleFeatureProviderImpl().getLocaleNames();
|
||||||
StringJoiner stringJoiner = new StringJoiner(", ");
|
|
||||||
for (int i = 0; i < localeList.size(); i++) {
|
|
||||||
Locale locale = localeList.get(i);
|
|
||||||
stringJoiner.add(locale.stripExtensions().getDisplayName(locale));
|
|
||||||
}
|
|
||||||
return stringJoiner.toString();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2023 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.settings.localepicker;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
|
import android.app.ActivityThread;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.LocaleList;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
|
public class LocaleFeatureProviderImplTest {
|
||||||
|
private LocaleFeatureProviderImpl mLocaleFeatureProviderImpl;
|
||||||
|
private Configuration mCacheConfig;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
mLocaleFeatureProviderImpl = new LocaleFeatureProviderImpl();
|
||||||
|
// Cache current configuration.
|
||||||
|
mCacheConfig = ActivityManager.getService().getConfiguration();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() throws Exception {
|
||||||
|
// Recovery the configuration to the current device.
|
||||||
|
ActivityManager.getService().updatePersistentConfigurationWithAttribution(mCacheConfig,
|
||||||
|
ActivityThread.currentOpPackageName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocaleNames_hasEnAndZh_resultIsEnglishAndChinese() throws Exception {
|
||||||
|
LocaleList locales = LocaleList.forLanguageTags("en-US-u-mu-celsius,zh-TW");
|
||||||
|
final Configuration config = new Configuration();
|
||||||
|
config.setLocales(locales);
|
||||||
|
ActivityManager.getService().updatePersistentConfigurationWithAttribution(config,
|
||||||
|
ActivityThread.currentOpPackageName(), null);
|
||||||
|
|
||||||
|
String result = mLocaleFeatureProviderImpl.getLocaleNames().trim();
|
||||||
|
|
||||||
|
String expected1 =
|
||||||
|
Locale.forLanguageTag("en-US-u-mu-celsius").stripExtensions().getDisplayName();
|
||||||
|
String expected2 = Locale.forLanguageTag("zh-TW").getDisplayName();
|
||||||
|
assertTrue(result.contains(expected1));
|
||||||
|
assertTrue(result.contains(expected2));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getLocaleNames_hasExtension_resultWithoutExtensionInfo() throws Exception {
|
||||||
|
LocaleList locales = LocaleList.forLanguageTags("en-US-u-mu-celsius,zh-TW");
|
||||||
|
final Configuration config = new Configuration();
|
||||||
|
config.setLocales(locales);
|
||||||
|
ActivityManager.getService().updatePersistentConfigurationWithAttribution(config,
|
||||||
|
ActivityThread.currentOpPackageName(), null);
|
||||||
|
|
||||||
|
String result = mLocaleFeatureProviderImpl.getLocaleNames().toLowerCase(Locale.ROOT);
|
||||||
|
|
||||||
|
assertFalse(result.contains("celsius"));
|
||||||
|
}
|
||||||
|
}
|
@@ -1,83 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2023 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.settings.regionalpreferences;
|
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.LocaleList;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
public class NumberingSystemControllerTest {
|
|
||||||
private Context mApplicationContext;
|
|
||||||
private NumberingSystemController mController;
|
|
||||||
private LocaleList mCacheLocales;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
mApplicationContext = ApplicationProvider.getApplicationContext();
|
|
||||||
mController = new NumberingSystemController(mApplicationContext, "key");
|
|
||||||
mCacheLocales = LocaleList.getDefault();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() throws Exception {
|
|
||||||
LocaleList.setDefault(mCacheLocales);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_has1Locale_showEnUs() {
|
|
||||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US"));
|
|
||||||
|
|
||||||
String summary = mController.getSummary().toString();
|
|
||||||
|
|
||||||
String expectedResult =
|
|
||||||
Locale.forLanguageTag("en-us").getDisplayName();
|
|
||||||
assertEquals(expectedResult, summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_has2Locales_showEnUsAndZhTw() {
|
|
||||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US,zh-TW"));
|
|
||||||
|
|
||||||
String summary = mController.getSummary().toString();
|
|
||||||
|
|
||||||
Locale locale1 = Locale.forLanguageTag("en-US");
|
|
||||||
Locale locale2 = Locale.forLanguageTag("zh-TW");
|
|
||||||
String expectedResult =
|
|
||||||
locale1.getDisplayName(locale1) + ", " + locale2.getDisplayName(locale2);
|
|
||||||
assertEquals(expectedResult, summary);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getSummary_localeHasExtensionTag_showEnUsWithoutTag() {
|
|
||||||
LocaleList.setDefault(LocaleList.forLanguageTags("en-US-u-ca-chinese"));
|
|
||||||
|
|
||||||
String summary = mController.getSummary().toString();
|
|
||||||
|
|
||||||
String expectedResult = Locale.forLanguageTag("en-US").getDisplayName();
|
|
||||||
assertEquals(expectedResult, summary);
|
|
||||||
}
|
|
||||||
}
|
|
Reference in New Issue
Block a user