[Catalyst] Provide launch intent
Bug: 373895400 Flag: com.android.settings.flags.catalyst Test: manual Change-Id: If7825798c441dc0009fbd91918d4795873b39fa3
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings;
|
||||
|
||||
import static com.android.settings.SettingsActivity.EXTRA_FRAGMENT_ARG_KEY;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.app.admin.DevicePolicyManager;
|
||||
@@ -45,6 +47,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.flags.Flags;
|
||||
import com.android.settings.support.actionbar.HelpResourceProvider;
|
||||
import com.android.settings.widget.HighlightablePreferenceGroupAdapter;
|
||||
import com.android.settings.widget.LoadingViewController;
|
||||
@@ -367,9 +370,13 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
@Override
|
||||
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
|
||||
final Bundle arguments = getArguments();
|
||||
mAdapter = new HighlightablePreferenceGroupAdapter(preferenceScreen,
|
||||
arguments == null
|
||||
? null : arguments.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY),
|
||||
String key = arguments == null ? null : arguments.getString(EXTRA_FRAGMENT_ARG_KEY);
|
||||
if (Flags.catalyst() && key == null) {
|
||||
Activity activity = getActivity();
|
||||
Intent intent = activity != null ? activity.getIntent() : null;
|
||||
key = intent != null ? intent.getStringExtra(EXTRA_FRAGMENT_ARG_KEY) : null;
|
||||
}
|
||||
mAdapter = new HighlightablePreferenceGroupAdapter(preferenceScreen, key,
|
||||
mPreferenceHighlighted);
|
||||
return mAdapter;
|
||||
}
|
||||
|
@@ -18,10 +18,13 @@ package com.android.settings.display
|
||||
import android.content.Context
|
||||
import com.android.settings.DisplaySettings
|
||||
import com.android.settings.R
|
||||
import com.android.settings.Settings.DisplaySettingsActivity
|
||||
import com.android.settings.display.darkmode.DarkModeScreen
|
||||
import com.android.settings.flags.Flags
|
||||
import com.android.settings.utils.makeLaunchIntent
|
||||
import com.android.settingslib.metadata.PreferenceAvailabilityProvider
|
||||
import com.android.settingslib.metadata.PreferenceIconProvider
|
||||
import com.android.settingslib.metadata.PreferenceMetadata
|
||||
import com.android.settingslib.metadata.ProvidePreferenceScreen
|
||||
import com.android.settingslib.metadata.preferenceHierarchy
|
||||
import com.android.settingslib.preference.PreferenceScreenCreator
|
||||
@@ -52,6 +55,9 @@ class DisplayScreen :
|
||||
+PeakRefreshRateSwitchPreference()
|
||||
}
|
||||
|
||||
override fun getLaunchIntent(context: Context, metadata: PreferenceMetadata?) =
|
||||
makeLaunchIntent(context, DisplaySettingsActivity::class.java, metadata?.key)
|
||||
|
||||
override fun isAvailable(context: Context) =
|
||||
context.resources.getBoolean(R.bool.config_show_top_level_display)
|
||||
|
||||
|
34
src/com/android/settings/utils/IntentUtils.kt
Normal file
34
src/com/android/settings/utils/IntentUtils.kt
Normal file
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (C) 2024 The Android Open Source 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.settings.utils
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import com.android.settings.SettingsActivity
|
||||
|
||||
/**
|
||||
* Returns the [Intent] to start given settings activity and locate the preference.
|
||||
*
|
||||
* @param context context
|
||||
* @param activityClass activity to start
|
||||
* @param key preference key to locate
|
||||
*/
|
||||
fun makeLaunchIntent(context: Context, activityClass: Class<out Activity>, key: String?) =
|
||||
Intent(context, activityClass).apply {
|
||||
if (key != null) putExtra(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key)
|
||||
}
|
@@ -30,6 +30,7 @@ import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.PreferenceGroup;
|
||||
import androidx.preference.PreferenceGroupAdapter;
|
||||
@@ -64,7 +65,7 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
||||
|
||||
private final Context mContext;
|
||||
private final int mNormalBackgroundRes;
|
||||
private final String mHighlightKey;
|
||||
private final @Nullable String mHighlightKey;
|
||||
private boolean mHighlightRequested;
|
||||
private int mHighlightPosition = RecyclerView.NO_POSITION;
|
||||
|
||||
@@ -101,7 +102,8 @@ public class HighlightablePreferenceGroupAdapter extends PreferenceGroupAdapter
|
||||
screen.setInitialExpandedChildrenCount(initialCount);
|
||||
}
|
||||
|
||||
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup, String key,
|
||||
public HighlightablePreferenceGroupAdapter(PreferenceGroup preferenceGroup,
|
||||
@Nullable String key,
|
||||
boolean highlightRequested) {
|
||||
super(preferenceGroup);
|
||||
mHighlightKey = key;
|
||||
|
Reference in New Issue
Block a user