Refactor help menu stuff into a controller
This is a clean up to action bar menu item pattern, we will use the same pattern to build search icon on all pages in a later change. Bug: 68814716 Test: robotests Change-Id: Iedd3ec263e8ccb63ed75ec7a95b28c00878b1de4
This commit is contained in:
@@ -39,8 +39,6 @@ import android.text.TextUtils;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
@@ -49,10 +47,11 @@ import com.android.settings.applications.LayoutPreference;
|
||||
import com.android.settings.core.InstrumentedPreferenceFragment;
|
||||
import com.android.settings.core.instrumentation.Instrumentable;
|
||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
||||
import com.android.settings.support.actionbar.HelpMenuController;
|
||||
import com.android.settings.support.actionbar.HelpResourceProvider;
|
||||
import com.android.settings.widget.LoadingViewController;
|
||||
import com.android.settingslib.CustomDialogPreference;
|
||||
import com.android.settingslib.CustomEditTextPreference;
|
||||
import com.android.settingslib.HelpUtils;
|
||||
import com.android.settingslib.widget.FooterPreferenceMixin;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -61,13 +60,7 @@ import java.util.UUID;
|
||||
* Base class for Settings fragments, with some helper functions and dialog management.
|
||||
*/
|
||||
public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceFragment
|
||||
implements DialogCreatable {
|
||||
|
||||
/**
|
||||
* The Help Uri Resource key. This can be passed as an extra argument when creating the
|
||||
* Fragment.
|
||||
**/
|
||||
public static final String HELP_URI_RESOURCE_KEY = "help_uri_resource";
|
||||
implements DialogCreatable, HelpResourceProvider {
|
||||
|
||||
private static final String TAG = "SettingsPreference";
|
||||
|
||||
@@ -79,13 +72,11 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
protected final FooterPreferenceMixin mFooterPreferenceMixin =
|
||||
new FooterPreferenceMixin(this, getLifecycle());
|
||||
|
||||
private SettingsDialogFragment mDialogFragment;
|
||||
|
||||
private String mHelpUri;
|
||||
|
||||
private static final int ORDER_FIRST = -1;
|
||||
private static final int ORDER_LAST = Integer.MAX_VALUE -1;
|
||||
|
||||
private SettingsDialogFragment mDialogFragment;
|
||||
// Cache the content resolver for async callbacks
|
||||
private ContentResolver mContentResolver;
|
||||
|
||||
@@ -144,22 +135,12 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
HelpMenuController.init(this /* host */);
|
||||
|
||||
if (icicle != null) {
|
||||
mPreferenceHighlighted = icicle.getBoolean(SAVE_HIGHLIGHTED_KEY);
|
||||
}
|
||||
|
||||
// Prepare help url and enable menu if necessary
|
||||
final Bundle arguments = getArguments();
|
||||
final int helpResource;
|
||||
if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
|
||||
helpResource = arguments.getInt(HELP_URI_RESOURCE_KEY);
|
||||
} else {
|
||||
helpResource = getHelpResource();
|
||||
}
|
||||
if (helpResource != 0) {
|
||||
mHelpUri = getResources().getString(helpResource);
|
||||
}
|
||||
|
||||
// Check if we should keep the preferences expanded.
|
||||
if (arguments != null) {
|
||||
@@ -177,8 +158,8 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final View root = super.onCreateView(inflater, container, savedInstanceState);
|
||||
mPinnedHeaderFrameLayout = (ViewGroup) root.findViewById(R.id.pinned_header);
|
||||
mButtonBar = (ViewGroup) root.findViewById(R.id.button_bar);
|
||||
mPinnedHeaderFrameLayout = root.findViewById(R.id.pinned_header);
|
||||
mButtonBar = root.findViewById(R.id.button_bar);
|
||||
return root;
|
||||
}
|
||||
|
||||
@@ -465,22 +446,6 @@ public abstract class SettingsPreferenceFragment extends InstrumentedPreferenceF
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override this if you want to show a help item in the menu, by returning the resource id.
|
||||
* @return the resource id for the help url
|
||||
*/
|
||||
protected int getHelpResource() {
|
||||
return R.string.help_uri_default;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
if (mHelpUri != null && getActivity() != null) {
|
||||
HelpUtils.prepareHelpMenuItem(getActivity(), menu, mHelpUri, getClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* The name is intentionally made different from Activity#finish(), so that
|
||||
* users won't misunderstand its meaning.
|
||||
|
||||
Reference in New Issue
Block a user