Dialer: convert VoicemailSecretCodeActivity to androidx
* fixes Fragment$InstantiationException on launch. PreferenceActivity
cannot instantiate PreferenceFragmentCompat due to it being a
androidx.fragment.app.Fragment instead of the expected
android.app.Fragment.
* also fix double listing of preferences in override screen.
Change-Id: Ibd9b1fe064cff23b81aca592bdde2b41c200b784
diff --git a/java/com/android/voicemail/impl/configui/ConfigOverrideFragment.java b/java/com/android/voicemail/impl/configui/ConfigOverrideFragment.java
index 6597593..263ae6a 100644
--- a/java/com/android/voicemail/impl/configui/ConfigOverrideFragment.java
+++ b/java/com/android/voicemail/impl/configui/ConfigOverrideFragment.java
@@ -54,10 +54,9 @@
private static final String CONFIG_OVERRIDE_KEY_PREFIX = "vvm_config_override_key_";
@Override
- public void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
PreferenceManager.setDefaultValues(getActivity(), R.xml.vvm_config_override, false);
- addPreferencesFromResource(R.xml.vvm_config_override);
+ setPreferencesFromResource(R.xml.vvm_config_override, rootKey);
// add listener so the value of a EditTextPreference will be updated to the summary.
for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
@@ -82,17 +81,6 @@
}
@Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- setPreferencesFromResource(R.xml.vvm_config_override, rootKey);
-
- for (int i = 0; i < getPreferenceScreen().getPreferenceCount(); i++) {
- Preference preference = getPreferenceScreen().getPreference(i);
- preference.setOnPreferenceChangeListener(this);
- updatePreference(preference);
- }
- }
-
- @Override
public boolean onPreferenceTreeClick(Preference preference) {
if (TextUtils.equals(
preference.getKey(), getString(R.string.vvm_config_override_load_current_key))) {
diff --git a/java/com/android/voicemail/impl/configui/VoicemailSecretCodeActivity.java b/java/com/android/voicemail/impl/configui/VoicemailSecretCodeActivity.java
index d6b0c4b..aa7e263 100644
--- a/java/com/android/voicemail/impl/configui/VoicemailSecretCodeActivity.java
+++ b/java/com/android/voicemail/impl/configui/VoicemailSecretCodeActivity.java
@@ -1,6 +1,6 @@
/*
* Copyright (C) 2017 The Android Open Source Project
- * Copyright (C) 2023 The LineageOS Project
+ * Copyright (C) 2024 The LineageOS Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,44 +17,21 @@
package com.android.voicemail.impl.configui;
-import android.content.Intent;
-import android.preference.PreferenceActivity;
-import android.provider.VoicemailContract;
+import android.os.Bundle;
-import java.util.List;
+import androidx.appcompat.app.AppCompatActivity;
+import com.android.dialer.R;
/** Activity launched by simulator->voicemail, provides debug features. */
@SuppressWarnings("FragmentInjection") // not exported
-public class VoicemailSecretCodeActivity extends PreferenceActivity {
-
- private Header syncHeader;
+public class VoicemailSecretCodeActivity extends AppCompatActivity {
@Override
- public void onBuildHeaders(List<Header> target) {
- super.onBuildHeaders(target);
- syncHeader = new Header();
- syncHeader.title = "Sync";
- target.add(syncHeader);
-
- Header configOverride = new Header();
- configOverride.fragment = ConfigOverrideFragment.class.getName();
- configOverride.title = "VVM config override";
- target.add(configOverride);
- }
-
- @Override
- public void onHeaderClick(Header header, int position) {
- if (header == syncHeader) {
- Intent intent = new Intent(VoicemailContract.ACTION_SYNC_VOICEMAIL);
- intent.setPackage(getPackageName());
- sendBroadcast(intent);
- return;
- }
- super.onHeaderClick(header, position);
- }
-
- @Override
- protected boolean isValidFragment(String fragmentName) {
- return true;
+ protected void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setTheme(R.style.SettingsStyle);
+ getSupportFragmentManager().beginTransaction()
+ .replace(android.R.id.content, new VoicemailSecretCodeFragment())
+ .commit();
}
}
diff --git a/java/com/android/voicemail/impl/configui/VoicemailSecretCodeFragment.java b/java/com/android/voicemail/impl/configui/VoicemailSecretCodeFragment.java
new file mode 100644
index 0000000..f34fe5a
--- /dev/null
+++ b/java/com/android/voicemail/impl/configui/VoicemailSecretCodeFragment.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2024 The LineageOS Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.voicemail.impl.configui;
+
+import android.os.Bundle;
+import android.text.TextUtils;
+
+import androidx.preference.Preference;
+import androidx.preference.Preference.OnPreferenceClickListener;
+import androidx.preference.PreferenceFragmentCompat;
+
+import android.content.Intent;
+import android.provider.VoicemailContract;
+
+public class VoicemailSecretCodeFragment extends PreferenceFragmentCompat
+ implements OnPreferenceClickListener {
+
+ private Preference syncPreference;
+ private Preference configOverridePreference;
+ private static final String SYNC_KEY = "sync_preference";
+ private static final String CONFIG_OVERRIDE_KEY =
+ "config_override_preference";
+
+ @Override
+ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
+ setPreferencesFromResource(R.xml.vvm_secret_main, rootKey);
+
+ syncPreference = findPreference(SYNC_KEY);
+ syncPreference.setOnPreferenceClickListener(this);
+
+ configOverridePreference = findPreference(CONFIG_OVERRIDE_KEY);
+ configOverridePreference.setOnPreferenceClickListener(this);
+ }
+
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (TextUtils.equals(preference.getKey(), SYNC_KEY)) {
+ Intent intent = new Intent(VoicemailContract.ACTION_SYNC_VOICEMAIL);
+ intent.setPackage(requireContext().getPackageName());
+ requireContext().sendBroadcast(intent);
+ } else {
+ getParentFragmentManager().beginTransaction()
+ .replace(android.R.id.content, new ConfigOverrideFragment())
+ .addToBackStack(null)
+ .commit();
+ }
+ return true;
+ }
+}
diff --git a/java/com/android/voicemail/impl/configui/res/values/strings.xml b/java/com/android/voicemail/impl/configui/res/values/strings.xml
index fea76be..6aa214e 100644
--- a/java/com/android/voicemail/impl/configui/res/values/strings.xml
+++ b/java/com/android/voicemail/impl/configui/res/values/strings.xml
@@ -17,5 +17,6 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="vvm_config_override_load_current_key" translatable="false">vvm_config_override_load_current</string>
<string name="vvm_config_override_enabled_key" translatable="false">vvm_config_override_enabled</string>
-
+ <string name="sync_preference_title">Sync</string>
+ <string name="config_override_preference_title">VVM config override</string>
</resources>
diff --git a/java/com/android/voicemail/impl/configui/res/xml/vvm_secret_main.xml b/java/com/android/voicemail/impl/configui/res/xml/vvm_secret_main.xml
new file mode 100644
index 0000000..969b22c
--- /dev/null
+++ b/java/com/android/voicemail/impl/configui/res/xml/vvm_secret_main.xml
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <Preference
+ android:key="sync_preference"
+ android:title="@string/sync_preference_title" />
+ <Preference
+ android:key="config_override_preference"
+ android:title="@string/config_override_preference_title" />
+</PreferenceScreen>