[Catalyst] Support RadioButtonPickerFragment
Bug: 368359967 Flag: com.android.settings.flags.catalyst_screen_timeout Test: manual Change-Id: Ibd3a1c52b152054bf01e37848785c5bda588df5f
This commit is contained in:
@@ -35,6 +35,8 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.annotation.XmlRes;
|
import androidx.annotation.XmlRes;
|
||||||
import androidx.fragment.app.DialogFragment;
|
import androidx.fragment.app.DialogFragment;
|
||||||
@@ -54,6 +56,7 @@ import com.android.settings.widget.LoadingViewController;
|
|||||||
import com.android.settingslib.CustomDialogPreferenceCompat;
|
import com.android.settingslib.CustomDialogPreferenceCompat;
|
||||||
import com.android.settingslib.CustomEditTextPreferenceCompat;
|
import com.android.settingslib.CustomEditTextPreferenceCompat;
|
||||||
import com.android.settingslib.core.instrumentation.Instrumentable;
|
import com.android.settingslib.core.instrumentation.Instrumentable;
|
||||||
|
import com.android.settingslib.preference.PreferenceScreenCreator;
|
||||||
import com.android.settingslib.search.Indexable;
|
import com.android.settingslib.search.Indexable;
|
||||||
import com.android.settingslib.widget.LayoutPreference;
|
import com.android.settingslib.widget.LayoutPreference;
|
||||||
|
|
||||||
@@ -176,6 +179,24 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected final int getPreferenceScreenResId(@NonNull Context context) {
|
||||||
|
return getPreferenceScreenResId();
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns if catalyst is enabled on current screen. */
|
||||||
|
protected final boolean isCatalystEnabled() {
|
||||||
|
return getPreferenceScreenCreator() != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected @Nullable PreferenceScreenCreator getPreferenceScreenCreator() {
|
||||||
|
if (!Flags.catalyst()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Context context = getContext();
|
||||||
|
return context != null ? getPreferenceScreenCreator(context) : null;
|
||||||
|
}
|
||||||
|
|
||||||
public View setPinnedHeaderView(int layoutResId) {
|
public View setPinnedHeaderView(int layoutResId) {
|
||||||
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
final LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||||
final View pinnedHeader =
|
final View pinnedHeader =
|
||||||
|
@@ -147,7 +147,7 @@ public abstract class InstrumentedPreferenceFragment extends ObservablePreferenc
|
|||||||
mMetricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
|
mMetricsFeatureProvider.logClickedPreference(preference, getMetricsCategory());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateActivityTitleWithScreenTitle(PreferenceScreen screen) {
|
protected void updateActivityTitleWithScreenTitle(PreferenceScreen screen) {
|
||||||
if (screen != null) {
|
if (screen != null) {
|
||||||
final CharSequence title = screen.getTitle();
|
final CharSequence title = screen.getTitle();
|
||||||
if (!TextUtils.isEmpty(title)) {
|
if (!TextUtils.isEmpty(title)) {
|
||||||
|
@@ -308,11 +308,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected final int getPreferenceScreenResId(@NonNull Context context) {
|
|
||||||
return getPreferenceScreenResId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected abstract int getPreferenceScreenResId();
|
protected abstract int getPreferenceScreenResId();
|
||||||
|
|
||||||
@@ -413,7 +408,7 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
removeControllersForHybridMode();
|
removeControllersForHybridMode();
|
||||||
}
|
}
|
||||||
setPreferenceScreen(screen);
|
setPreferenceScreen(screen);
|
||||||
requireActivity().setTitle(screen.getTitle());
|
updateActivityTitleWithScreenTitle(screen);
|
||||||
} else {
|
} else {
|
||||||
addPreferencesFromResource(resId);
|
addPreferencesFromResource(resId);
|
||||||
screen = getPreferenceScreen();
|
screen = getPreferenceScreen();
|
||||||
@@ -447,19 +442,6 @@ public abstract class DashboardFragment extends SettingsPreferenceFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns if catalyst is enabled on current screen. */
|
|
||||||
protected final boolean isCatalystEnabled() {
|
|
||||||
return getPreferenceScreenCreator() != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private @Nullable PreferenceScreenCreator getPreferenceScreenCreator() {
|
|
||||||
if (!Flags.catalyst()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
Context context = getContext();
|
|
||||||
return context != null ? getPreferenceScreenCreator(context) : null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform {@link AbstractPreferenceController#displayPreference(PreferenceScreen)}
|
* Perform {@link AbstractPreferenceController#displayPreference(PreferenceScreen)}
|
||||||
* on all {@link AbstractPreferenceController}s.
|
* on all {@link AbstractPreferenceController}s.
|
||||||
|
@@ -86,7 +86,13 @@ public abstract class RadioButtonPickerFragment extends SettingsPreferenceFragme
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
super.onCreatePreferences(savedInstanceState, rootKey);
|
if (isCatalystEnabled()) {
|
||||||
|
PreferenceScreen preferenceScreen = createPreferenceScreen();
|
||||||
|
setPreferenceScreen(preferenceScreen);
|
||||||
|
updateActivityTitleWithScreenTitle(preferenceScreen);
|
||||||
|
} else {
|
||||||
|
super.onCreatePreferences(savedInstanceState, rootKey);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
// Check if the xml specifies if static preferences should go on the top or bottom
|
// Check if the xml specifies if static preferences should go on the top or bottom
|
||||||
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(getContext(),
|
final List<Bundle> metadata = PreferenceXmlParserUtils.extractMetadata(getContext(),
|
||||||
|
Reference in New Issue
Block a user