diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-16 06:01:12 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2024-05-16 12:13:24 +0200 |
commit | 567891fdf7912ae173429539bc97c68075c00c1f (patch) | |
tree | cf4757af95c3779c07e6c01641daa3a594d32caa /android | |
parent | 7b0d2829fe691e013486578b6e93cf94ceb0cd36 (diff) |
android: Port Settings{Activity,Fragment} from deprecated API
API used in `SettingsActivity` and `SettingsFragment` has
been deprecated, e.g. `PreferenceFragment` was deprecated in
API level 28 [1].
Port that to non-deprecated API from the androidx.preference
library [2].
This addresses these deprecation warnings:
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:14: warning: [deprecation] PreferenceFragment in android.preference has been deprecated
import android.preference.PreferenceFragment;
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:15: warning: [deprecation] PreferenceGroup in android.preference has been deprecated
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:23: warning: [deprecation] getFragmentManager() in Activity has been deprecated
getFragmentManager().beginTransaction()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:23: warning: [deprecation] beginTransaction() in FragmentManager has been deprecated
getFragmentManager().beginTransaction()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:24: warning: [deprecation] replace(int,Fragment) in FragmentTransaction has been deprecated
.replace(android.R.id.content, new SettingsFragment())
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:25: warning: [deprecation] commit() in FragmentTransaction has been deprecated
.commit();
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:28: warning: [deprecation] PreferenceFragment in android.preference has been deprecated
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:28: warning: [deprecation] PreferenceFragment() in PreferenceFragment has been deprecated
public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:30: warning: [deprecation] onCreate(Bundle) in PreferenceFragment has been deprecated
public void onCreate(Bundle savedInstanceState) {
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:31: warning: [deprecation] onCreate(Bundle) in PreferenceFragment has been deprecated
super.onCreate(savedInstanceState);
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:32: warning: [deprecation] addPreferencesFromResource(int) in PreferenceFragment has been deprecated
addPreferencesFromResource(R.xml.libreoffice_preferences);
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:34: warning: [deprecation] PreferenceGroup in android.preference has been deprecated
PreferenceGroup generalGroup = (PreferenceGroup) findPreference("PREF_CATEGORY_GENERAL");
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:34: warning: [deprecation] PreferenceGroup in android.preference has been deprecated
PreferenceGroup generalGroup = (PreferenceGroup) findPreference("PREF_CATEGORY_GENERAL");
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:34: warning: [deprecation] findPreference(CharSequence) in PreferenceFragment has been deprecated
PreferenceGroup generalGroup = (PreferenceGroup) findPreference("PREF_CATEGORY_GENERAL");
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:35: warning: [deprecation] findPreference(CharSequence) in PreferenceGroup has been deprecated
generalGroup.removePreference(generalGroup.findPreference("ENABLE_EXPERIMENTAL"));
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:35: warning: [deprecation] removePreference(Preference) in PreferenceGroup has been deprecated
generalGroup.removePreference(generalGroup.findPreference("ENABLE_EXPERIMENTAL"));
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:36: warning: [deprecation] findPreference(CharSequence) in PreferenceGroup has been deprecated
generalGroup.removePreference(generalGroup.findPreference("ENABLE_DEVELOPER"));
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:36: warning: [deprecation] removePreference(Preference) in PreferenceGroup has been deprecated
generalGroup.removePreference(generalGroup.findPreference("ENABLE_DEVELOPER"));
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:41: warning: [deprecation] onResume() in Fragment has been deprecated
public void onResume() {
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:42: warning: [deprecation] onResume() in Fragment has been deprecated
super.onResume();
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:43: warning: [deprecation] getPreferenceScreen() in PreferenceFragment has been deprecated
getPreferenceScreen().getSharedPreferences()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:43: warning: [deprecation] getSharedPreferences() in Preference has been deprecated
getPreferenceScreen().getSharedPreferences()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:48: warning: [deprecation] onPause() in Fragment has been deprecated
public void onPause() {
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:49: warning: [deprecation] onPause() in Fragment has been deprecated
super.onPause();
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:50: warning: [deprecation] getPreferenceScreen() in PreferenceFragment has been deprecated
getPreferenceScreen().getSharedPreferences()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:50: warning: [deprecation] getSharedPreferences() in Preference has been deprecated
getPreferenceScreen().getSharedPreferences()
^
/home/michi/development/git/libreoffice-WORKTREE-android/android/source/src/java/org/libreoffice/SettingsActivity.java:58: warning: [deprecation] getActivity() in Fragment has been deprecated
[1] https://developer.android.com/reference/android/preference/PreferenceFragment
[2] https://developer.android.com/reference/androidx/preference/package-summary
Change-Id: I3365a487345787056c91fa7addf987edca38e94f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167717
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
Diffstat (limited to 'android')
-rw-r--r-- | android/source/src/java/org/libreoffice/SettingsActivity.java | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/android/source/src/java/org/libreoffice/SettingsActivity.java b/android/source/src/java/org/libreoffice/SettingsActivity.java index 5623abc2e597..e9cb403be459 100644 --- a/android/source/src/java/org/libreoffice/SettingsActivity.java +++ b/android/source/src/java/org/libreoffice/SettingsActivity.java @@ -8,30 +8,35 @@ */ package org.libreoffice; -import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; -import android.preference.PreferenceFragment; -import android.preference.PreferenceGroup; +import androidx.fragment.app.FragmentActivity; +import androidx.preference.PreferenceFragmentCompat; +import androidx.preference.PreferenceGroup; -public class SettingsActivity extends Activity { +public class SettingsActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Display the fragment as the main content. - getFragmentManager().beginTransaction() + getSupportFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); } - public static class SettingsFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener { + public static class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener { + + @Override + public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { + setPreferencesFromResource(R.xml.libreoffice_preferences, rootKey); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.libreoffice_preferences); if(!BuildConfig.ALLOW_EDITING) { - PreferenceGroup generalGroup = (PreferenceGroup) findPreference("PREF_CATEGORY_GENERAL"); + PreferenceGroup generalGroup = findPreference("PREF_CATEGORY_GENERAL"); generalGroup.removePreference(generalGroup.findPreference("ENABLE_EXPERIMENTAL")); generalGroup.removePreference(generalGroup.findPreference("ENABLE_DEVELOPER")); } @@ -41,14 +46,14 @@ public class SettingsActivity extends Activity { public void onResume() { super.onResume(); getPreferenceScreen().getSharedPreferences() - .registerOnSharedPreferenceChangeListener(this); + .registerOnSharedPreferenceChangeListener(this); } @Override public void onPause() { super.onPause(); getPreferenceScreen().getSharedPreferences() - .unregisterOnSharedPreferenceChangeListener(this); + .unregisterOnSharedPreferenceChangeListener(this); } @Override |