Use ListFormatter to join strings
Currently in Settings we are using R.string.join_many_items_first, R.string.join_many_items_middle and R.string.join_many_items_last to manually join strings. The join code is messy and the joined string is incorrect in some languages, so we migrate all string join to just use ListFormatter.getInstance().format(). Bug: b/78248791 Test: robotests Change-Id: I898339978e6e2027587e28994b0280fa46821fd6
This commit is contained in:
@@ -4048,12 +4048,6 @@
|
||||
<string name="join_two_items"><xliff:g id="first_item">%1$s</xliff:g> and <xliff:g id="second_item">%2$s</xliff:g></string>
|
||||
<!-- [CHAR_LIMIT=NONE] Format to put together two unrelated items in a list when "and" is not an appropriate conjunction for these 2 items -->
|
||||
<string name="join_two_unrelated_items"><xliff:g id="first_item">%1$s</xliff:g>, <xliff:g id="second_item">%2$s</xliff:g></string>
|
||||
<!-- [CHAR_LIMIT=NONE] Format to put the last item at the end of a series of 3 or more items in a list -->
|
||||
<string name="join_many_items_last"><xliff:g id="all_but_last_item">%1$s</xliff:g>, and <xliff:g id="last_item">%2$s</xliff:g></string>
|
||||
<!-- [CHAR_LIMIT=NONE] Format to put the first item at the start of a series of 3 or more items in a list -->
|
||||
<string name="join_many_items_first"><xliff:g id="first_item">%1$s</xliff:g>, <xliff:g id="all_but_first_and_last_item">%2$s</xliff:g></string>
|
||||
<!-- [CHAR_LIMIT=NONE] Format to put the middle items together in a series of 4 or more items in a list -->
|
||||
<string name="join_many_items_middle"><xliff:g id="added_item">%1$s</xliff:g>, <xliff:g id="rest_of_items">%2$s</xliff:g></string>
|
||||
<!-- Manage applications, individual application info screen, text that appears under the "Permissions" heading after the app has tried to send to a premium SMS. [CHAR LIMIT=50] -->
|
||||
<string name="security_settings_billing_desc">This app may charge you money:</string>
|
||||
<!-- Manage applications, text for permission to send to premium SMS short codes. [CHAR LIMIT=40] -->
|
||||
|
@@ -19,6 +19,7 @@ import static android.provider.Settings.EXTRA_AUTHORITIES;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.os.UserHandle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.BidiFormatter;
|
||||
@@ -96,12 +97,11 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
|
||||
UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
|
||||
final String[] types = authHelper.getEnabledAccountTypes();
|
||||
|
||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||
final List<CharSequence> summaries = new ArrayList<>();
|
||||
|
||||
CharSequence summary = null;
|
||||
if (types == null || types.length == 0) {
|
||||
summary = mContext.getString(R.string.account_dashboard_default_summary);
|
||||
summaries.add(mContext.getString(R.string.account_dashboard_default_summary));
|
||||
} else {
|
||||
// Show up to 3 account types, ignore any null value
|
||||
int accountToAdd = Math.min(3, types.length);
|
||||
@@ -111,16 +111,12 @@ public class AccountDashboardFragment extends DashboardFragment {
|
||||
if (TextUtils.isEmpty(label)) {
|
||||
continue;
|
||||
}
|
||||
if (summary == null) {
|
||||
summary = bidiFormatter.unicodeWrap(label);
|
||||
} else {
|
||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||
bidiFormatter.unicodeWrap(label));
|
||||
}
|
||||
|
||||
summaries.add(bidiFormatter.unicodeWrap(label));
|
||||
accountToAdd--;
|
||||
}
|
||||
}
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
mSummaryLoader.setSummary(this, ListFormatter.getInstance().format(summaries));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,13 +19,14 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.PermissionGroupInfo;
|
||||
import android.content.pm.PermissionInfo;
|
||||
import android.text.TextUtils;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.util.ArraySet;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.BasePreferenceController;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -33,7 +34,7 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
||||
|
||||
private static final String TAG = "AppPermissionPrefCtrl";
|
||||
private static final String KEY_APP_PERMISSION_GROUPS = "manage_perms";
|
||||
private static final String[] PERMISSION_GROUPS = new String[] {
|
||||
private static final String[] PERMISSION_GROUPS = new String[]{
|
||||
"android.permission-group.LOCATION",
|
||||
"android.permission-group.MICROPHONE",
|
||||
"android.permission-group.CAMERA",
|
||||
@@ -64,18 +65,20 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
||||
public CharSequence getSummary() {
|
||||
final Set<String> permissions = getAllPermissionsInGroups();
|
||||
Set<String> grantedPermissionGroups = getGrantedPermissionGroups(permissions);
|
||||
CharSequence summary = null;
|
||||
int count = 0;
|
||||
final List<String> summaries = new ArrayList<>();
|
||||
|
||||
for (String group : PERMISSION_GROUPS) {
|
||||
if (!grantedPermissionGroups.contains(group)) {
|
||||
continue;
|
||||
}
|
||||
summary = concatSummaryText(summary, group);
|
||||
summaries.add(getPermissionGroupLabel(group).toString().toLowerCase());
|
||||
if (++count >= NUM_PERMISSION_TO_USE) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return count > 0 ? mContext.getString(R.string.app_permissions_summary, summary) : null;
|
||||
return count > 0 ? mContext.getString(R.string.app_permissions_summary,
|
||||
ListFormatter.getInstance().format(summaries)) : null;
|
||||
}
|
||||
|
||||
private Set<String> getGrantedPermissionGroups(Set<String> permissions) {
|
||||
@@ -96,14 +99,6 @@ public class AppPermissionsPreferenceController extends BasePreferenceController
|
||||
return grantedPermissionGroups;
|
||||
}
|
||||
|
||||
private CharSequence concatSummaryText(CharSequence currentSummary, String permission) {
|
||||
final String label = getPermissionGroupLabel(permission).toString().toLowerCase();
|
||||
if (TextUtils.isEmpty(currentSummary)) {
|
||||
return label;
|
||||
}
|
||||
return mContext.getString(R.string.join_many_items_middle, currentSummary, label);
|
||||
}
|
||||
|
||||
private CharSequence getPermissionGroupLabel(String group) {
|
||||
try {
|
||||
final PermissionGroupInfo groupInfo = mPackageManager.getPermissionGroupInfo(group, 0);
|
||||
|
@@ -17,6 +17,7 @@ package com.android.settings.applications;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.text.TextUtils;
|
||||
|
||||
@@ -138,25 +139,22 @@ public class DefaultAppSettings extends DashboardFragment {
|
||||
if (!listening) {
|
||||
return;
|
||||
}
|
||||
CharSequence summary = concatSummaryText(
|
||||
mDefaultBrowserPreferenceController.getDefaultAppLabel(),
|
||||
mDefaultPhonePreferenceController.getDefaultAppLabel());
|
||||
summary = concatSummaryText(summary,
|
||||
mDefaultSmsPreferenceController.getDefaultAppLabel());
|
||||
final List<CharSequence> summaries = new ArrayList<>();
|
||||
if(!TextUtils.isEmpty(mDefaultBrowserPreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultBrowserPreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
if(!TextUtils.isEmpty(mDefaultPhonePreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultPhonePreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
if(!TextUtils.isEmpty(mDefaultSmsPreferenceController.getDefaultAppLabel())) {
|
||||
summaries.add(mDefaultSmsPreferenceController.getDefaultAppLabel());
|
||||
}
|
||||
|
||||
CharSequence summary = ListFormatter.getInstance().format(summaries);
|
||||
if (!TextUtils.isEmpty(summary)) {
|
||||
mSummaryLoader.setSummary(this, summary);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence concatSummaryText(CharSequence summary1, CharSequence summary2) {
|
||||
if (TextUtils.isEmpty(summary1)) {
|
||||
return summary2;
|
||||
}
|
||||
if (TextUtils.isEmpty(summary2)) {
|
||||
return summary1;
|
||||
}
|
||||
return mContext.getString(R.string.join_many_items_middle, summary1, summary2);
|
||||
}
|
||||
}
|
||||
|
||||
public static final SummaryLoader.SummaryProviderFactory SUMMARY_PROVIDER_FACTORY =
|
||||
|
@@ -18,6 +18,9 @@ package com.android.settings.inputmethod;
|
||||
|
||||
import android.content.Context;
|
||||
import android.hardware.input.InputManager;
|
||||
import android.icu.text.ListFormatter;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
@@ -28,9 +31,9 @@ import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
||||
import com.android.settingslib.core.lifecycle.events.OnPause;
|
||||
import com.android.settingslib.core.lifecycle.events.OnResume;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
public class PhysicalKeyboardPreferenceController extends AbstractPreferenceController
|
||||
implements PreferenceControllerMixin, LifecycleObserver, OnResume, OnPause,
|
||||
@@ -100,15 +103,10 @@ public class PhysicalKeyboardPreferenceController extends AbstractPreferenceCont
|
||||
mPreference.setSummary(R.string.keyboard_disconnected);
|
||||
return;
|
||||
}
|
||||
String summary = null;
|
||||
final List<String> summaries = new ArrayList<>();
|
||||
for (HardKeyboardDeviceInfo info : keyboards) {
|
||||
if (summary == null) {
|
||||
summary = info.mDeviceName;
|
||||
} else {
|
||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||
info.mDeviceName);
|
||||
summaries.add(info.mDeviceName);
|
||||
}
|
||||
}
|
||||
mPreference.setSummary(summary);
|
||||
mPreference.setSummary(ListFormatter.getInstance().format(summaries));
|
||||
}
|
||||
}
|
||||
|
@@ -19,11 +19,13 @@ package com.android.settings.inputmethod;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.preference.Preference;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.text.BidiFormatter;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.AbstractPreferenceController;
|
||||
@@ -81,15 +83,10 @@ public class VirtualKeyboardPreferenceController extends AbstractPreferenceContr
|
||||
|
||||
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
|
||||
|
||||
String summary = null;
|
||||
final List<String> summaries = new ArrayList<>();
|
||||
for (String label : labels) {
|
||||
if (summary == null) {
|
||||
summary = bidiFormatter.unicodeWrap(label);
|
||||
} else {
|
||||
summary = mContext.getString(R.string.join_many_items_middle, summary,
|
||||
bidiFormatter.unicodeWrap(label));
|
||||
summaries.add(bidiFormatter.unicodeWrap(label));
|
||||
}
|
||||
}
|
||||
preference.setSummary(summary);
|
||||
preference.setSummary(ListFormatter.getInstance().format(summaries));
|
||||
}
|
||||
}
|
||||
|
@@ -21,9 +21,11 @@ import android.app.FragmentManager;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.content.Context;
|
||||
import android.icu.text.ListFormatter;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
|
||||
@@ -44,6 +46,7 @@ import java.util.Map.Entry;
|
||||
@SearchIndexable
|
||||
public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
private static final String KEY_SOUND = "zen_effect_sound";
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -118,18 +121,21 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
} else if (numCategories == 2) {
|
||||
return mContext.getString(R.string.join_two_items, enabledCategories.get(0),
|
||||
enabledCategories.get(1).toLowerCase());
|
||||
} else if (numCategories == 3){
|
||||
String secondaryText = mContext.getString(R.string.join_two_unrelated_items,
|
||||
enabledCategories.get(0), enabledCategories.get(1).toLowerCase());
|
||||
return mContext.getString(R.string.join_many_items_last, secondaryText,
|
||||
enabledCategories.get(2).toLowerCase());
|
||||
} else if (numCategories == 3) {
|
||||
final List<String> summaries = new ArrayList<>();
|
||||
summaries.add(enabledCategories.get(0));
|
||||
summaries.add(enabledCategories.get(1).toLowerCase());
|
||||
summaries.add(enabledCategories.get(2).toLowerCase());
|
||||
|
||||
return ListFormatter.getInstance().format(summaries);
|
||||
} else {
|
||||
String secondaryText = mContext.getString(R.string.join_many_items_middle,
|
||||
enabledCategories.get(0), enabledCategories.get(1).toLowerCase());
|
||||
secondaryText = mContext.getString(R.string.join_many_items_middle, secondaryText,
|
||||
enabledCategories.get(2).toLowerCase());
|
||||
return mContext.getString(R.string.join_many_items_last, secondaryText,
|
||||
mContext.getString(R.string.zen_mode_other_options));
|
||||
final List<String> summaries = new ArrayList<>();
|
||||
summaries.add(enabledCategories.get(0));
|
||||
summaries.add(enabledCategories.get(1).toLowerCase());
|
||||
summaries.add(enabledCategories.get(2).toLowerCase());
|
||||
summaries.add(mContext.getString(R.string.zen_mode_other_options));
|
||||
|
||||
return ListFormatter.getInstance().format(summaries);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -25,7 +25,6 @@ import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffColorFilter;
|
||||
import android.graphics.Typeface;
|
||||
import android.icu.text.DecimalFormatSymbols;
|
||||
import androidx.annotation.ColorRes;
|
||||
import android.text.Layout;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
@@ -37,6 +36,8 @@ import android.text.style.RelativeSizeSpan;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.ColorRes;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
@@ -207,7 +208,7 @@ public class DonutView extends View {
|
||||
R.dimen.storage_donut_view_shrunken_label_text_size));
|
||||
}
|
||||
setContentDescription(getContext().getString(
|
||||
R.string.join_many_items_middle, mPercentString, mFullString));
|
||||
R.string.join_two_unrelated_items, mPercentString, mFullString));
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
@@ -15,9 +15,13 @@
|
||||
*/
|
||||
package com.android.settings.accounts;
|
||||
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest.ShadowAuthenticationHelper.TYPES;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.LABELS;
|
||||
import static com.android.settings.accounts.AccountDashboardFragmentTest
|
||||
.ShadowAuthenticationHelper.TYPES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
@@ -75,10 +79,11 @@ public class AccountDashboardFragmentTest {
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity, loader);
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", " + LABELS[2]);
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1] + ", and " + LABELS[2]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,7 +94,8 @@ public class AccountDashboardFragmentTest {
|
||||
final Activity activity = Robolectric.buildActivity(Activity.class).setup().get();
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity, loader);
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
verify(loader).setSummary(provider,
|
||||
@@ -105,11 +111,12 @@ public class AccountDashboardFragmentTest {
|
||||
ShadowAuthenticationHelper.setEnabledAccount(enabledAccounts);
|
||||
|
||||
final SummaryLoader.SummaryProvider provider =
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity, loader);
|
||||
AccountDashboardFragment.SUMMARY_PROVIDER_FACTORY.createSummaryProvider(activity,
|
||||
loader);
|
||||
provider.setListening(true);
|
||||
|
||||
// should only show the 2 accounts with labels
|
||||
verify(loader).setSummary(provider, LABELS[0] + ", " + LABELS[1]);
|
||||
verify(loader).setSummary(provider, LABELS[0] + " and " + LABELS[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -17,6 +17,7 @@
|
||||
package com.android.settings.applications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
@@ -31,6 +32,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.PermissionGroupInfo;
|
||||
import android.content.pm.PermissionInfo;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
@@ -177,33 +179,38 @@ public class AppPermissionsPreferenceControllerTest {
|
||||
permissions[2] = mPermCamera;
|
||||
permissions[3] = mPermSms;
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("Apps using location, microphone, camera");
|
||||
|
||||
verify(mPreference).setSummary("Apps using location, microphone, and camera");
|
||||
|
||||
permissions[0] = mPermPhone;
|
||||
permissions[1] = mPermMic;
|
||||
permissions[2] = mPermCamera;
|
||||
permissions[3] = mPermSms;
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("Apps using microphone, camera, sms");
|
||||
|
||||
verify(mPreference).setSummary("Apps using microphone, camera, and sms");
|
||||
|
||||
permissions[0] = mPermPhone;
|
||||
permissions[1] = mPermMic;
|
||||
permissions[2] = mPermContacts;
|
||||
permissions[3] = mPermSms;
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("Apps using microphone, sms, contacts");
|
||||
|
||||
verify(mPreference).setSummary("Apps using microphone, sms, and contacts");
|
||||
|
||||
permissions = new PermissionInfo[2];
|
||||
info.permissions = permissions;
|
||||
permissions[0] = mPermLocation;
|
||||
permissions[1] = mPermCamera;
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary("Apps using location, camera");
|
||||
|
||||
verify(mPreference).setSummary("Apps using location and camera");
|
||||
|
||||
permissions = new PermissionInfo[1];
|
||||
info.permissions = permissions;
|
||||
permissions[0] = mPermCamera;
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary("Apps using camera");
|
||||
}
|
||||
}
|
||||
|
@@ -91,44 +91,51 @@ public class DefaultAppSettingsTest {
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1, Phone1, Sms1");
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1, Phone1, and Sms1");
|
||||
|
||||
// 2 available
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1, Phone1");
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1 and Phone1");
|
||||
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn("Sms1");
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1, Sms1");
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1 and Sms1");
|
||||
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn("Sms1");
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn(null);
|
||||
summaryProvider.setListening(true);
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1, Sms1");
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1 and Sms1");
|
||||
|
||||
// 1 available
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn("Browser1");
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn(null);
|
||||
summaryProvider.setListening(true);
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Browser1");
|
||||
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn("Sms1");
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn(null);
|
||||
summaryProvider.setListening(true);
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Sms1");
|
||||
|
||||
when(defaultSms.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn("Phone1");
|
||||
summaryProvider.setListening(true);
|
||||
|
||||
verify(summaryLoader).setSummary(summaryProvider, "Phone1");
|
||||
|
||||
// None available
|
||||
@@ -136,6 +143,7 @@ public class DefaultAppSettingsTest {
|
||||
when(defaultBrowser.getDefaultAppLabel()).thenReturn(null);
|
||||
when(defaultPhone.getDefaultAppLabel()).thenReturn(null);
|
||||
summaryProvider.setListening(true);
|
||||
|
||||
verify(summaryLoader, never()).setSummary(summaryProvider, eq(anyString()));
|
||||
|
||||
}
|
||||
|
@@ -17,8 +17,7 @@
|
||||
package com.android.settings.inputmethod;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.eq;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -28,11 +27,12 @@ import android.app.admin.DevicePolicyManager;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import androidx.core.text.BidiFormatter;
|
||||
import androidx.preference.Preference;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import androidx.core.text.BidiFormatter;
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.testutils.SettingsRobolectricTestRunner;
|
||||
|
||||
@@ -125,18 +125,9 @@ public class VirtualKeyboardPreferenceControllerTest {
|
||||
when(imis.get(0).loadLabel(mPm)).thenReturn(label1);
|
||||
when(imis.get(1).getPackageName()).thenReturn(componentName.getPackageName());
|
||||
when(imis.get(1).loadLabel(mPm)).thenReturn(label2);
|
||||
when(mContext.getString(eq(R.string.join_many_items_middle), anyString(), anyString()))
|
||||
.thenAnswer(invocation -> {
|
||||
final Object[] args = invocation.getArguments();
|
||||
final String str1 = (String) args[1];
|
||||
final String str2 = (String) args[2];
|
||||
return RuntimeEnvironment.application.getString(R.string.join_many_items_middle,
|
||||
str1, str2);
|
||||
});
|
||||
|
||||
mController.updateState(mPreference);
|
||||
|
||||
verify(mPreference).setSummary(
|
||||
formatter.unicodeWrap(label1) + ", " + formatter.unicodeWrap(label2));
|
||||
verify(mPreference).setSummary(formatter.unicodeWrap(label1) + " and " + formatter.unicodeWrap(label2));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user