diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-16 07:01:35 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-16 12:13:30 +0200 |
commit | 39ed595d608efd852a0239f6cf74f1168981cfc2 (patch) | |
tree | 19212df951544298efce749fb0ebb7f0ed3dd47b /android | |
parent | 567891fdf7912ae173429539bc97c68075c00c1f (diff) |
android: No longer manually set UI language
Drop the possibility to manually set a UI language
introduced in
commit f2e35a695671028b32139df1824ff536e7610d35
Author: Mert Tumer <merttumer@outlook.com>
Date: Tue Sep 18 23:29:57 2018 +0300
Added language support on Android Viewer
Since
commit 5bf2ec9ed8728a2042e110122ea2b0e4ff55104a
Author: Michael Weghorn <m.weghorn@posteo.de>
Date: Fri Dec 20 10:40:34 2019 +0100
android: Use system locale by default
, Android Viewer defaulted to the system
language for its UI language as well.
In addition, current Android versions allow to set
a specific language for apps: [1]
The previous approach of manually setting a language
in Android Viewer shouldn't really be necessary any more.
With the app now being available for translation on
Weblate and having been translated to more languages,
the list of available languages had become out of sync.
Additionally, the manually selected language wasn't
consistently applied everywhere:
* On the start activity where a document can be selected,
it was only applied after closing the app, then opening
it again.
* in the Settings, the language was not applied at all,
that was always using the system locale anyway
Changes to the system locale are applied immediately
and consistently, so stick to the default Android mechanism
and reduce the overall complexity and maintenance burden.
[1] https://support.google.com/android/answer/12395118?hl=en
Change-Id: Ida61650b888a563f2346ea94a14b260802b1d24d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167718
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
7 files changed, 1 insertions, 113 deletions
diff --git a/android/source/res/values/arrays.xml b/android/source/res/values/arrays.xml deleted file mode 100644 index 832bca781572..000000000000 --- a/android/source/res/values/arrays.xml +++ /dev/null @@ -1,15 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <string-array name="SupportedLanguagesValues"> - <item>SYSTEM_DEFAULT_LANGUAGE</item> - <item >de</item> - <item >en</item> - <item >tr</item> - </string-array> - <string-array name="SupportedLanguages"> - <item>(System Default)</item> - <item>Deutsch</item> - <item>English</item> - <item>Turkçe</item> - </string-array> -</resources> diff --git a/android/source/res/values/strings.xml b/android/source/res/values/strings.xml index 3766db146098..36b3cef75a25 100644 --- a/android/source/res/values/strings.xml +++ b/android/source/res/values/strings.xml @@ -140,8 +140,6 @@ <string name="alert_ok">OK</string> <string name="alert_cancel">Cancel</string> <string name="current_uno_command">Current UNO command</string> - <string name="display_language">Display Language</string> - <string name="display_language_summary">Set the default display language</string> <string name="pdf_export_finished">PDF export finished</string> <string name="unable_to_export_pdf">Unable to export to pdf</string> <string name="unable_to_save">Unable to save file</string> diff --git a/android/source/res/xml/libreoffice_preferences.xml b/android/source/res/xml/libreoffice_preferences.xml index 052efacb2e3e..d8ca4dc8c7a7 100644 --- a/android/source/res/xml/libreoffice_preferences.xml +++ b/android/source/res/xml/libreoffice_preferences.xml @@ -4,15 +4,6 @@ android:title="@string/pref_category_general" android:key="PREF_CATEGORY_GENERAL"> - <ListPreference - android:title="@string/display_language" - android:summary="@string/display_language_summary" - android:entries="@array/SupportedLanguages" - android:entryValues="@array/SupportedLanguagesValues" - android:defaultValue="SYSTEM_DEFAULT_LANGUAGE" - android:key="DISPLAY_LANGUAGE" - /> - <CheckBoxPreference android:title="@string/pref_experimental_editing" android:key="ENABLE_EXPERIMENTAL" diff --git a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java index ebe54cf27c64..3b03c83adda9 100644 --- a/android/source/src/java/org/libreoffice/LibreOfficeApplication.java +++ b/android/source/src/java/org/libreoffice/LibreOfficeApplication.java @@ -25,9 +25,4 @@ public class LibreOfficeApplication extends MultiDexApplication { public static Handler getMainHandler() { return mainHandler; } - - @Override - protected void attachBaseContext(Context base) { - super.attachBaseContext(LocaleHelper.onAttach(base)); - } } diff --git a/android/source/src/java/org/libreoffice/LocaleHelper.java b/android/source/src/java/org/libreoffice/LocaleHelper.java deleted file mode 100644 index e3997f913a32..000000000000 --- a/android/source/src/java/org/libreoffice/LocaleHelper.java +++ /dev/null @@ -1,56 +0,0 @@ -package org.libreoffice; - -import android.content.Context; -import android.content.SharedPreferences; -import android.content.res.Configuration; -import android.content.res.Resources; -import androidx.preference.PreferenceManager; - -import java.util.Locale; - -public class LocaleHelper { - - private static final String SELECTED_LANG = "org.libreoffice.selected.lang"; - // value for language that indicates that system's default language should be used - public static final String SYSTEM_DEFAULT_LANGUAGE = "SYSTEM_DEFAULT_LANGUAGE"; - - public static Context onAttach(Context context){ - String lang = getPersistedData(context, Locale.getDefault().getLanguage()); - return setLocale(context, lang); - } - - public static Context setLocale(Context context, String lang) { - persist(context, lang); - return updateResources(context, lang); - } - - @SuppressWarnings("deprecation") - private static Context updateResources(Context context, String lang) { - Locale locale; - if (lang.equals(SYSTEM_DEFAULT_LANGUAGE)) { - locale = Locale.getDefault(); - } else { - locale = new Locale(lang); - } - Locale.setDefault(locale); - - Resources res = context.getResources(); - Configuration cfg = res.getConfiguration(); - cfg.locale = locale; - cfg.setLayoutDirection(locale); - - res.updateConfiguration(cfg, res.getDisplayMetrics()); - return context; - } - - private static void persist(Context context, String lang) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - preferences.edit().putString(SELECTED_LANG, lang); - preferences.edit().apply(); - } - - private static String getPersistedData(Context context, String lang) { - SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); - return preferences.getString(SELECTED_LANG, lang); - } -} diff --git a/android/source/src/java/org/libreoffice/SettingsActivity.java b/android/source/src/java/org/libreoffice/SettingsActivity.java index e9cb403be459..90d3f95459e4 100644 --- a/android/source/src/java/org/libreoffice/SettingsActivity.java +++ b/android/source/src/java/org/libreoffice/SettingsActivity.java @@ -59,9 +59,6 @@ public class SettingsActivity extends FragmentActivity { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { SettingsListenerModel.getInstance().changePreferenceState(sharedPreferences, key); - if(key.equals("DISPLAY_LANGUAGE")){ - getActivity().recreate(); - } } } } diff --git a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java index e87779df0eae..63eed9d37069 100644 --- a/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java +++ b/android/source/src/java/org/libreoffice/ui/LibreOfficeUIActivity.java @@ -46,16 +46,14 @@ import android.widget.TextView; import org.libreoffice.AboutDialogFragment; import org.libreoffice.BuildConfig; import org.libreoffice.LibreOfficeMainActivity; -import org.libreoffice.LocaleHelper; import org.libreoffice.R; import org.libreoffice.SettingsActivity; -import org.libreoffice.SettingsListenerModel; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -public class LibreOfficeUIActivity extends AppCompatActivity implements SettingsListenerModel.OnSettingsPreferenceChangedListener, View.OnClickListener{ +public class LibreOfficeUIActivity extends AppCompatActivity implements View.OnClickListener{ public enum DocumentType { WRITER, CALC, @@ -70,7 +68,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings private static final String RECENT_DOCUMENTS_KEY = "RECENT_DOCUMENT_URIS"; // delimiter used for storing multiple URIs in a string private static final String RECENT_DOCUMENTS_DELIMITER = " "; - private static final String DISPLAY_LANGUAGE = "DISPLAY_LANGUAGE"; public static final String NEW_DOC_TYPE_KEY = "NEW_DOC_TYPE_KEY"; public static final String NEW_WRITER_STRING_KEY = "private:factory/swriter"; @@ -140,9 +137,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - readPreferences(); - SettingsListenerModel.getInstance().setListener(this); - // init UI createUI(); fabOpenAnimation = AnimationUtils.loadAnimation(this, R.anim.fab_open); @@ -160,11 +154,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings } } - @Override - protected void attachBaseContext(Context newBase) { - super.attachBaseContext(LocaleHelper.onAttach(newBase)); - } - public void createUI() { setContentView(R.layout.activity_document_browser); @@ -332,17 +321,6 @@ public class LibreOfficeUIActivity extends AppCompatActivity implements Settings return super.onOptionsItemSelected(item); } - public void readPreferences(){ - SharedPreferences defaultPrefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); - final String displayLanguage = defaultPrefs.getString(DISPLAY_LANGUAGE, LocaleHelper.SYSTEM_DEFAULT_LANGUAGE); - LocaleHelper.setLocale(this, displayLanguage); - } - - @Override - public void settingsPreferenceChanged(SharedPreferences sharedPreferences, String key) { - readPreferences(); - } - @Override protected void onResume() { super.onResume(); |