use of org.mozilla.focus.locale.LocaleManager in project Rocket by mozilla-tw.
the class SettingsFragment method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(getString(R.string.pref_key_locale))) {
// fragment gets replaced at the end of this method anyways.
if (localeUpdated) {
return;
}
localeUpdated = true;
final ListPreference languagePreference = (ListPreference) findPreference(getString(R.string.pref_key_locale));
final String value = languagePreference.getValue();
final LocaleManager localeManager = LocaleManager.getInstance();
final Locale locale;
if (TextUtils.isEmpty(value)) {
localeManager.resetToSystemLocale(getActivity());
locale = localeManager.getCurrentLocale(getActivity());
} else {
locale = Locales.parseLocaleCode(value);
localeManager.setSelectedLocale(getActivity(), value);
}
TelemetryWrapper.settingsLocaleChangeEvent(key, String.valueOf(locale), TextUtils.isEmpty(value));
localeManager.updateConfiguration(getActivity(), locale);
// Manually notify SettingsActivity of locale changes (in most other cases activities
// will detect changes in onActivityResult(), but that doesn't apply to SettingsActivity).
getActivity().onConfigurationChanged(getActivity().getResources().getConfiguration());
// And ensure that the calling LocaleAware*Activity knows that the locale changed:
getActivity().setResult(SettingsActivity.ACTIVITY_RESULT_LOCALE_CHANGED);
// The easiest way to ensure we update the language is by replacing the entire fragment:
getFragmentManager().beginTransaction().replace(R.id.container, new SettingsFragment()).commit();
return;
}
TelemetryWrapper.settingsEvent(key, String.valueOf(sharedPreferences.getAll().get(key)));
if (key.equals(getString(R.string.pref_key_storage_clear_browsing_data))) {
// Clear browsing data Callback function is not here
// Go to Class CleanBrowsingDataPreference -> onDialogClosed
} else if (key.equals(getString(R.string.pref_key_storage_save_downloads_to))) {
// Save downloads/cache/offline pages to SD card/Internal storage Callback function
}
}
use of org.mozilla.focus.locale.LocaleManager in project focus-android by mozilla-mobile.
the class SettingsFragment method onSharedPreferenceChanged.
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
TelemetryWrapper.settingsEvent(key, String.valueOf(sharedPreferences.getAll().get(key)));
if (!localeUpdated && key.equals(getString(R.string.pref_key_locale))) {
// Updating the locale leads to onSharedPreferenceChanged being triggered again in some
// cases. To avoid an infinite loop we won't update the preference a second time. This
// fragment gets replaced at the end of this method anyways.
localeUpdated = true;
final ListPreference languagePreference = (ListPreference) findPreference(getString(R.string.pref_key_locale));
final String value = languagePreference.getValue();
final LocaleManager localeManager = LocaleManager.getInstance();
final Locale locale;
if (TextUtils.isEmpty(value)) {
localeManager.resetToSystemLocale(getActivity());
locale = localeManager.getCurrentLocale(getActivity());
} else {
locale = Locales.parseLocaleCode(value);
localeManager.setSelectedLocale(getActivity(), value);
}
localeManager.updateConfiguration(getActivity(), locale);
// Manually notify SettingsActivity of locale changes (in most other cases activities
// will detect changes in onActivityResult(), but that doesn't apply to SettingsActivity).
getActivity().onConfigurationChanged(getActivity().getResources().getConfiguration());
// And ensure that the calling LocaleAware*Activity knows that the locale changed:
getActivity().setResult(SettingsActivity.ACTIVITY_RESULT_LOCALE_CHANGED);
// The easiest way to ensure we update the language is by replacing the entire fragment:
getFragmentManager().beginTransaction().replace(R.id.container, SettingsFragment.newInstance()).commit();
}
}
use of org.mozilla.focus.locale.LocaleManager in project focus-android by mozilla-mobile.
the class WebFragment method applyLocale.
@Override
public void applyLocale() {
Context context = getContext();
final LocaleManager localeManager = LocaleManager.getInstance();
if (!localeManager.isMirroringSystemLocale(context)) {
final Locale currentLocale = localeManager.getCurrentLocale(context);
Locale.setDefault(currentLocale);
final Resources resources = context.getResources();
final Configuration config = resources.getConfiguration();
config.setLocale(currentLocale);
context.getResources().updateConfiguration(config, null);
}
// We create and destroy a new WebView here to force the internal state of WebView to know
// about the new language. See issue #666.
final WebView unneeded = new WebView(getContext());
unneeded.destroy();
}
Aggregations