Fix incorrect seperator while concatenating shortcuts
We concatenate the selected shortcut with a comma that is not localized. To fix it we use listformatter to concatenate them. Bug: 186891004 Test: manually test with differnt languages. Change-Id: I2c6692facd457b434c56a0633e784ce771905b29
This commit is contained in:
@@ -52,6 +52,7 @@ import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsPreferenceFragment;
|
||||
import com.android.settings.accessibility.AccessibilityEditDialogUtils.DialogType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.utils.LocaleUtils;
|
||||
import com.android.settings.widget.SettingsMainSwitchBar;
|
||||
import com.android.settings.widget.SettingsMainSwitchPreference;
|
||||
import com.android.settingslib.accessibility.AccessibilityUtils;
|
||||
@@ -659,10 +660,9 @@ public abstract class ToggleFeaturePreferenceFragment extends SettingsPreference
|
||||
if (list.isEmpty()) {
|
||||
list.add(softwareTitle);
|
||||
}
|
||||
final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
|
||||
|
||||
return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */
|
||||
null, joinStrings);
|
||||
null, LocaleUtils.getConcatenatedString(list));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -46,6 +46,7 @@ import com.android.settings.DialogCreatable;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.accessibility.AccessibilityEditDialogUtils.DialogType;
|
||||
import com.android.settings.accessibility.AccessibilityUtil.UserShortcutType;
|
||||
import com.android.settings.utils.LocaleUtils;
|
||||
|
||||
import com.google.android.setupcompat.util.WizardManagerHelper;
|
||||
|
||||
@@ -282,10 +283,9 @@ public class ToggleScreenMagnificationPreferenceFragment extends
|
||||
if (list.isEmpty()) {
|
||||
list.add(softwareTitle);
|
||||
}
|
||||
final String joinStrings = TextUtils.join(/* delimiter= */", ", list);
|
||||
|
||||
return CaseMap.toTitle().wholeString().noLowercase().apply(Locale.getDefault(), /* iter= */
|
||||
null, joinStrings);
|
||||
null, LocaleUtils.getConcatenatedString(list));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
47
src/com/android/settings/utils/LocaleUtils.java
Normal file
47
src/com/android/settings/utils/LocaleUtils.java
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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.utils;
|
||||
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* This class implements some common methods to process with locales
|
||||
*/
|
||||
public class LocaleUtils {
|
||||
|
||||
/**
|
||||
* Returns a character sequence concatenating the items with the localized comma.
|
||||
*
|
||||
* @param items items to be concatenated
|
||||
*/
|
||||
public static CharSequence getConcatenatedString(List<CharSequence> items) {
|
||||
final ListFormatter listFormatter = ListFormatter.getInstance(Locale.getDefault());
|
||||
final CharSequence lastItem = items.get(items.size() - 1);
|
||||
items.add("fake last item");
|
||||
|
||||
// For English with "{0}, {1}, and {2}", the pattern is "{0}, {1}, and {2}".
|
||||
// To get "{0}, {1}, {2}", we add a {fake item}, then the pattern result would be
|
||||
// "{0}, {1}, {2} and {fake item}", then get the substring with the end index of the
|
||||
// last item.
|
||||
final String formatted = listFormatter.format(items);
|
||||
return formatted.subSequence(0, TextUtils.indexOf(formatted, lastItem) + lastItem.length());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user