Commit 315dcd44 authored by Boris Sazonov's avatar Boris Sazonov Committed by Commit Bot

[Android] Use PreferenceFragmentCompat.getString

Migration to PreferenceFragmentCompat allows using getString method
from that class instead of more lengthy alternatives like
getResources().getString. No behavior change should occur from this CL.

Bug: None
Change-Id: I05bcef1fbba40cb171684ecc54a70b400a020bf9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1822937
Commit-Queue: Boris Sazonov <bsazonov@chromium.org>
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Auto-Submit: Boris Sazonov <bsazonov@chromium.org>
Reviewed-by: default avatarNatalie Chouinard <chouinard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#699481}
parent 8f74db54
......@@ -272,7 +272,7 @@ public class MainPreferences extends PreferenceFragmentCompat
}
private void setOnOffSummary(Preference pref, boolean isOn) {
pref.setSummary(getResources().getString(isOn ? R.string.text_on : R.string.text_off));
pref.setSummary(isOn ? R.string.text_on : R.string.text_off);
}
// SigninManager.SignInStateObserver implementation.
......
......@@ -300,7 +300,7 @@ public class SavePasswordsPreferences
getPreferenceScreen().removePreference(passwordParent);
} else {
getView().announceForAccessibility(
getResources().getText(R.string.accessible_find_in_page_no_results));
getString(R.string.accessible_find_in_page_no_results));
}
}
}
......
......@@ -99,9 +99,6 @@ public class PrivacyPreferences
public void updateSummaries() {
PrefServiceBridge prefServiceBridge = PrefServiceBridge.getInstance();
CharSequence textOn = getActivity().getResources().getText(R.string.text_on);
CharSequence textOff = getActivity().getResources().getText(R.string.text_off);
CheckBoxPreference canMakePaymentPref =
(CheckBoxPreference) findPreference(PREF_CAN_MAKE_PAYMENT);
if (canMakePaymentPref != null) {
......@@ -111,7 +108,8 @@ public class PrivacyPreferences
Preference doNotTrackPref = findPreference(PREF_DO_NOT_TRACK);
if (doNotTrackPref != null) {
doNotTrackPref.setSummary(prefServiceBridge.isDoNotTrackEnabled() ? textOn : textOff);
doNotTrackPref.setSummary(
prefServiceBridge.isDoNotTrackEnabled() ? R.string.text_on : R.string.text_off);
}
Preference usageStatsPref = findPreference(PREF_USAGE_STATS);
......
......@@ -10,7 +10,6 @@ import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
......@@ -231,7 +230,6 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
Preference parentAccounts = findPreference(PREF_PARENT_ACCOUNTS);
Preference childContent = findPreference(PREF_CHILD_CONTENT);
if (mProfile.isChild()) {
Resources res = getActivity().getResources();
PrefServiceBridge prefService = PrefServiceBridge.getInstance();
String firstParent = prefService.getSupervisedUserCustodianEmail();
......@@ -239,13 +237,12 @@ public class AccountManagementFragment extends PreferenceFragmentCompat
String parentText;
if (!secondParent.isEmpty()) {
parentText = res.getString(
parentText = getString(
R.string.account_management_two_parent_names, firstParent, secondParent);
} else if (!firstParent.isEmpty()) {
parentText =
res.getString(R.string.account_management_one_parent_name, firstParent);
parentText = getString(R.string.account_management_one_parent_name, firstParent);
} else {
parentText = res.getString(R.string.account_management_no_parental_data);
parentText = getString(R.string.account_management_no_parental_data);
}
parentAccounts.setSummary(parentText);
......
......@@ -7,7 +7,6 @@ package org.chromium.chrome.browser.preferences.sync;
import android.accounts.Account;
import android.app.Dialog;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
......@@ -461,13 +460,12 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
* @param error The sync error.
*/
private String getSyncErrorTitle(@SyncError int error) {
Resources res = getActivity().getResources();
switch (error) {
case SyncError.SYNC_SETUP_INCOMPLETE:
assert ChromeFeatureList.isEnabled(ChromeFeatureList.SYNC_MANUAL_START_ANDROID);
return res.getString(R.string.sync_settings_not_confirmed_title);
return getString(R.string.sync_settings_not_confirmed_title);
default:
return res.getString(R.string.sync_error_card_title);
return getString(R.string.sync_error_card_title);
}
}
......@@ -476,22 +474,21 @@ public class SyncAndServicesPreferences extends PreferenceFragmentCompat
* @param error The sync error.
*/
private String getSyncErrorHint(@SyncError int error) {
Resources res = getActivity().getResources();
switch (error) {
case SyncError.ANDROID_SYNC_DISABLED:
return res.getString(R.string.hint_android_sync_disabled);
return getString(R.string.hint_android_sync_disabled);
case SyncError.AUTH_ERROR:
return res.getString(R.string.hint_sync_auth_error);
return getString(R.string.hint_sync_auth_error);
case SyncError.CLIENT_OUT_OF_DATE:
return res.getString(
return getString(
R.string.hint_client_out_of_date, BuildInfo.getInstance().hostPackageLabel);
case SyncError.OTHER_ERRORS:
return res.getString(R.string.hint_other_sync_errors);
return getString(R.string.hint_other_sync_errors);
case SyncError.PASSPHRASE_REQUIRED:
return res.getString(R.string.hint_passphrase_required);
return getString(R.string.hint_passphrase_required);
case SyncError.SYNC_SETUP_INCOMPLETE:
assert ChromeFeatureList.isEnabled(ChromeFeatureList.SYNC_MANUAL_START_ANDROID);
return res.getString(R.string.hint_sync_settings_not_confirmed_description);
return getString(R.string.hint_sync_settings_not_confirmed_description);
case SyncError.NO_ERROR:
default:
return null;
......
......@@ -48,7 +48,7 @@ public class ThemePreferences extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(@Nullable Bundle savedInstanceState, String rootKey) {
PreferenceUtils.addPreferencesFromResource(this, R.xml.theme_preferences);
getActivity().setTitle(getResources().getString(R.string.prefs_themes));
getActivity().setTitle(R.string.prefs_themes);
ChromePreferenceManager chromePreferenceManager = ChromePreferenceManager.getInstance();
RadioButtonGroupThemePreference radioButtonGroupThemePreference =
......
......@@ -8,7 +8,6 @@ import static org.chromium.chrome.browser.preferences.SearchUtils.handleSearchNa
import android.content.Context;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
import android.support.graphics.drawable.VectorDrawableCompat;
......@@ -254,8 +253,7 @@ public class SingleCategoryPreferences extends PreferenceFragmentCompat
}
private CharSequence getHeaderTitle(int resourceId, int count) {
SpannableStringBuilder spannable =
new SpannableStringBuilder(getResources().getString(resourceId));
SpannableStringBuilder spannable = new SpannableStringBuilder(getString(resourceId));
String prefCount = String.format(Locale.getDefault(), " - %d", count);
spannable.append(prefCount);
......@@ -452,8 +450,7 @@ public class SingleCategoryPreferences extends PreferenceFragmentCompat
});
builder.setNegativeButton(R.string.cancel, null);
builder.setTitle(R.string.storage_clear_site_storage_title);
Resources res = getResources();
String dialogFormattedText = res.getString(R.string.storage_clear_dialog_text,
String dialogFormattedText = getString(R.string.storage_clear_dialog_text,
Formatter.formatShortFileSize(getActivity(), totalUsage));
builder.setMessage(dialogFormattedText);
builder.create().show();
......@@ -552,7 +549,7 @@ public class SingleCategoryPreferences extends PreferenceFragmentCompat
: R.string.website_settings_add_site_description_cookies_allow;
}
assert resource > 0;
return getResources().getString(resource);
return getString(resource);
}
// OnPreferenceClickListener:
......
......@@ -8,7 +8,6 @@ import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
......@@ -434,9 +433,7 @@ public class SingleWebsitePreferences extends PreferenceFragmentCompat
if (managedBy != null) {
final Intent notificationSettingsIntent =
getNotificationSettingsIntent(manager.getDelegatePackageName(origin));
String summaryText = String.format(
getResources().getString(R.string.website_notification_managed_by_app),
managedBy);
String summaryText = getString(R.string.website_notification_managed_by_app, managedBy);
ChromeImageViewPreference newPreference =
replaceWithReadOnlyCopyOf(preference, summaryText);
setupNotificationManagedByPreference(newPreference, notificationSettingsIntent);
......@@ -459,13 +456,11 @@ public class SingleWebsitePreferences extends PreferenceFragmentCompat
String overrideSummary;
if (isPermissionControlledByDSE(
ContentSettingsType.CONTENT_SETTINGS_TYPE_NOTIFICATIONS)) {
overrideSummary = getResources().getString(
value != null && value == ContentSettingValues.ALLOW
overrideSummary = getString(value != null && value == ContentSettingValues.ALLOW
? R.string.website_settings_permissions_allow_dse
: R.string.website_settings_permissions_block_dse);
} else {
overrideSummary =
getResources().getString(ContentSettingsResources.getSiteSummary(value));
overrideSummary = getString(ContentSettingsResources.getSiteSummary(value));
}
// On Android O this preference is read-only, so we replace the existing pref with a
......@@ -707,10 +702,10 @@ public class SingleWebsitePreferences extends PreferenceFragmentCompat
CharSequence[] descriptions = new String[2];
keys[0] = ContentSetting.toString(ContentSettingValues.ALLOW);
keys[1] = ContentSetting.toString(ContentSettingValues.BLOCK);
descriptions[0] = getResources().getString(
ContentSettingsResources.getSiteSummary(ContentSettingValues.ALLOW));
descriptions[1] = getResources().getString(
ContentSettingsResources.getSiteSummary(ContentSettingValues.BLOCK));
descriptions[0] =
getString(ContentSettingsResources.getSiteSummary(ContentSettingValues.ALLOW));
descriptions[1] =
getString(ContentSettingsResources.getSiteSummary(ContentSettingValues.BLOCK));
listPreference.setEntryValues(keys);
listPreference.setEntries(descriptions);
// TODO(crbug.com/735110): Figure out if this is the correct thing to do - here we are
......@@ -815,10 +810,9 @@ public class SingleWebsitePreferences extends PreferenceFragmentCompat
// The subresource filter permission has a custom BLOCK string.
ListPreference listPreference = (ListPreference) preference;
Resources res = getResources();
listPreference.setEntries(
new String[] {res.getString(R.string.website_settings_permissions_allow),
res.getString(R.string.website_settings_permissions_ads_block)});
new String[] {getString(R.string.website_settings_permissions_allow),
getString(R.string.website_settings_permissions_ads_block)});
listPreference.setValueIndex(permission == ContentSettingValues.ALLOW ? 0 : 1);
}
......@@ -838,10 +832,9 @@ public class SingleWebsitePreferences extends PreferenceFragmentCompat
*/
private void updatePreferenceForDSESetting(Preference preference) {
ListPreference listPreference = (ListPreference) preference;
Resources res = getResources();
listPreference.setEntries(new String[] {
res.getString(R.string.website_settings_permissions_allow_dse),
res.getString(R.string.website_settings_permissions_block_dse),
getString(R.string.website_settings_permissions_allow_dse),
getString(R.string.website_settings_permissions_block_dse),
});
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment