Add storage_summary_donut above ProfileSelectStorageFragment
- Modify ProfileSelectFragment to support add preference xml in the
top, and tabLayout below the preferences. Base preference layout is
dummy_preference_screen.xml which contains no preference.
ProfileSelectStorageFragment contains StorageSummaryDonutPreference
above the tabLayout.
- Make StorageSummaryDonutPreferenceController self workable without
StorageDashboardFragment dependence.
- Rename inactive_apps.xml to dummy_preference_screen.xml
- Move ShadowPrivateStorageInfo from LowStorageSliceTest
Bug: 141601408
Test: manual
Change-Id: Ide12840dc81bb104f328e230ecda5d35bba01d7a
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java
index 65d0c82..b5a1539 100644
--- a/src/com/android/settings/Utils.java
+++ b/src/com/android/settings/Utils.java
@@ -21,9 +21,6 @@
import static android.text.format.DateUtils.FORMAT_ABBREV_MONTH;
import static android.text.format.DateUtils.FORMAT_SHOW_DATE;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
-
import android.annotation.Nullable;
import android.app.ActionBar;
import android.app.Activity;
@@ -106,6 +103,7 @@
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.core.FeatureFlags;
import com.android.settings.dashboard.profileselector.ProfileFragmentBridge;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settingslib.widget.ActionBarShadowController;
@@ -1061,12 +1059,14 @@
*/
public static Fragment getTargetFragment(Activity activity, String fragmentName, Bundle args) {
Fragment f = null;
- final boolean isWorkOnly = args == null ? false : args.getBoolean(EXTRA_WORK_ONLY);
- final boolean isPersonalOnly = args == null ? false : args.getBoolean(EXTRA_PERSONAL_ONLY);
+ final boolean isPersonal = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL : false;
+ final boolean isWork = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.WORK : false;
if (FeatureFlagUtils.isEnabled(activity, FeatureFlags.PERSONAL_WORK_PROFILE)
&& UserManager.get(activity).getUserProfiles().size() > 1
&& ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName) != null
- && !isWorkOnly && !isPersonalOnly) {
+ && !isWork && !isPersonal) {
f = Fragment.instantiate(activity, ProfileFragmentBridge.FRAGMENT_MAP.get(fragmentName),
args);
} else {
diff --git a/src/com/android/settings/applications/manageapplications/ManageApplications.java b/src/com/android/settings/applications/manageapplications/ManageApplications.java
index 01289f2..1906a2d 100644
--- a/src/com/android/settings/applications/manageapplications/ManageApplications.java
+++ b/src/com/android/settings/applications/manageapplications/ManageApplications.java
@@ -29,6 +29,7 @@
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_POWER_WHITELIST_ALL;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_RECENT;
import static com.android.settings.applications.manageapplications.AppFilterRegistry.FILTER_APPS_WORK;
+import static com.android.settings.search.actionbar.SearchMenuController.MENU_SEARCH;
import android.annotation.Nullable;
import android.annotation.StringRes;
@@ -99,6 +100,7 @@
import com.android.settings.applications.appinfo.WriteSettingsDetails;
import com.android.settings.core.InstrumentedFragment;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.fuelgauge.HighPowerDetail;
import com.android.settings.notification.AppNotificationSettings;
import com.android.settings.notification.ConfigureNotificationSettings;
@@ -141,9 +143,7 @@
public static final String EXTRA_VOLUME_UUID = "volumeUuid";
public static final String EXTRA_VOLUME_NAME = "volumeName";
public static final String EXTRA_STORAGE_TYPE = "storageType";
- public static final String EXTRA_WORK_ONLY = "workProfileOnly";
public static final String EXTRA_WORK_ID = "workId";
- public static final String EXTRA_PERSONAL_ONLY = "personalOnly";
private static final String EXTRA_SORT_ORDER = "sortOrder";
private static final String EXTRA_SHOW_SYSTEM = "showSystem";
@@ -310,8 +310,10 @@
}
final AppFilterRegistry appFilterRegistry = AppFilterRegistry.getInstance();
mFilter = appFilterRegistry.get(appFilterRegistry.getDefaultFilterType(mListType));
- mIsPersonalOnly = args != null ? args.getBoolean(EXTRA_PERSONAL_ONLY) : false;
- mIsWorkOnly = args != null ? args.getBoolean(EXTRA_WORK_ONLY) : false;
+ mIsPersonalOnly = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL : false;
+ mIsWorkOnly = args != null ? args.getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.WORK : false;
mWorkUserId = args != null ? args.getInt(EXTRA_WORK_ID) : NO_USER_SPECIFIED;
mExpandSearch = activity.getIntent().getBooleanExtra(EXTRA_EXPAND_SEARCH_VIEW, false);
@@ -696,6 +698,10 @@
// Hide notification menu items, because sorting happens when filtering
mOptionsMenu.findItem(R.id.sort_order_recent_notification).setVisible(false);
mOptionsMenu.findItem(R.id.sort_order_frequent_notification).setVisible(false);
+ final MenuItem searchItem = mOptionsMenu.findItem(MENU_SEARCH);
+ if (searchItem != null) {
+ searchItem.setVisible(false);
+ }
}
@Override
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
index b7a1301..b8d4be1 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectFragment.java
@@ -22,13 +22,15 @@
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.android.settings.R;
-import com.android.settings.core.InstrumentedFragment;
+import com.android.settings.dashboard.DashboardFragment;
import com.google.android.material.tabs.TabLayout;
@@ -38,7 +40,9 @@
/**
* Base fragment class for profile settings.
*/
-public abstract class ProfileSelectFragment extends InstrumentedFragment {
+public abstract class ProfileSelectFragment extends DashboardFragment {
+
+ private static final String TAG = "ProfileSelectFragment";
/**
* Denotes the profile type.
@@ -63,16 +67,29 @@
*/
public static final int ALL = PERSONAL | WORK;
- private View mContentView;
+ /**
+ * Used in fragment argument and pass {@link ProfileType} to it
+ */
+ public static final String EXTRA_PROFILE = "profile";
+
+ private ViewGroup mContentView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
- mContentView = inflater.inflate(R.layout.profile_select_tablayout, null /* root */);
- final ViewPager viewPager = mContentView.findViewById(R.id.view_pager);
- viewPager.setAdapter(new ViewPagerAdapter(this));
- final TabLayout tabs = mContentView.findViewById(R.id.tabs);
+ mContentView = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
+
+ final View tabContainer = mContentView.findViewById(R.id.tab_container);
+ final ViewPager viewPager = tabContainer.findViewById(R.id.view_pager);
+ viewPager.setAdapter(new ProfileSelectFragment.ViewPagerAdapter(this));
+ final TabLayout tabs = tabContainer.findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
+ tabContainer.setVisibility(View.VISIBLE);
+
+ final FrameLayout listContainer = mContentView.findViewById(android.R.id.list_container);
+ listContainer.setLayoutParams(new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
return mContentView;
}
@@ -87,13 +104,23 @@
*/
public abstract Fragment[] getFragments();
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.dummy_preference_screen;
+ }
+
+ @Override
+ protected String getLogTag() {
+ return TAG;
+ }
+
static class ViewPagerAdapter extends FragmentStatePagerAdapter {
private final Fragment[] mChildFragments;
private final Context mContext;
ViewPagerAdapter(ProfileSelectFragment fragment) {
- super(fragment.getActivity().getSupportFragmentManager());
+ super(fragment.getChildFragmentManager());
mContext = fragment.getContext();
mChildFragments = fragment.getFragments();
}
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
index 7290258..8a9e4f8 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectManageApplications.java
@@ -16,9 +16,6 @@
package com.android.settings.dashboard.profileselector;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_PERSONAL_ONLY;
-import static com.android.settings.applications.manageapplications.ManageApplications.EXTRA_WORK_ONLY;
-
import android.os.Bundle;
import androidx.fragment.app.Fragment;
@@ -33,12 +30,12 @@
@Override
public Fragment[] getFragments() {
final Bundle workOnly = new Bundle();
- workOnly.putBoolean(EXTRA_WORK_ONLY, true);
+ workOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.WORK);
final Fragment workFragment = new ManageApplications();
workFragment.setArguments(workOnly);
final Bundle personalOnly = new Bundle();
- personalOnly.putBoolean(EXTRA_PERSONAL_ONLY, true);
+ personalOnly.putInt(EXTRA_PROFILE, ProfileSelectFragment.PERSONAL);
final Fragment personalFragment = new ManageApplications();
personalFragment.setArguments(personalOnly);
return new Fragment[]{
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
index c7e4fd8..fccabb5 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectStorageFragment.java
@@ -23,6 +23,7 @@
import androidx.fragment.app.Fragment;
+import com.android.settings.R;
import com.android.settings.deviceinfo.StorageDashboardFragment;
import com.android.settings.deviceinfo.StorageProfileFragment;
@@ -35,6 +36,7 @@
final Bundle storageBundle = new Bundle();
storageBundle.putString(VolumeInfo.EXTRA_VOLUME_ID, VolumeInfo.ID_PRIVATE_INTERNAL);
+ storageBundle.putInt(EXTRA_PROFILE, ProfileSelectFragment.PERSONAL);
final Fragment storageDashboardFragment = new StorageDashboardFragment();
storageDashboardFragment.setArguments(storageBundle);
@@ -46,7 +48,6 @@
break;
}
}
- // TODO(b/143330969): Need to think about more profile users case
if (targetUser != null) {
storageBundle.putInt(StorageProfileFragment.USER_ID_EXTRA, targetUser.id);
}
@@ -58,5 +59,10 @@
storageProfileFragment
};
}
+
+ @Override
+ protected int getPreferenceScreenResId() {
+ return R.xml.storage_summary_donut;
+ }
}
diff --git a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
index 0e53333..b36ad43 100644
--- a/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
+++ b/src/com/android/settings/deviceinfo/StorageDashboardFragment.java
@@ -33,16 +33,17 @@
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
+import androidx.preference.Preference;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.dashboard.DashboardFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.storage.AutomaticStorageManagementSwitchPreferenceController;
import com.android.settings.deviceinfo.storage.CachedStorageValuesHelper;
import com.android.settings.deviceinfo.storage.SecondaryUserController;
import com.android.settings.deviceinfo.storage.StorageAsyncLoader;
import com.android.settings.deviceinfo.storage.StorageItemPreferenceController;
-import com.android.settings.deviceinfo.storage.StorageSummaryDonutPreferenceController;
import com.android.settings.deviceinfo.storage.UserIconLoader;
import com.android.settings.deviceinfo.storage.VolumeSizesLoader;
import com.android.settings.search.BaseSearchIndexProvider;
@@ -62,6 +63,7 @@
implements
LoaderManager.LoaderCallbacks<SparseArray<StorageAsyncLoader.AppsStorageResult>> {
private static final String TAG = "StorageDashboardFrag";
+ private static final String SUMMARY_PREF_KEY = "pref_summary";
private static final int STORAGE_JOB_ID = 0;
private static final int ICON_JOB_ID = 1;
private static final int VOLUME_SIZE_JOB_ID = 2;
@@ -71,10 +73,10 @@
private SparseArray<StorageAsyncLoader.AppsStorageResult> mAppsResult;
private CachedStorageValuesHelper mCachedStorageValuesHelper;
- private StorageSummaryDonutPreferenceController mSummaryController;
private StorageItemPreferenceController mPreferenceController;
private PrivateVolumeOptionMenuController mOptionMenuController;
private List<AbstractPreferenceController> mSecondaryUsers;
+ private boolean mPersonalOnly;
@Override
public void onCreate(Bundle icicle) {
@@ -84,12 +86,19 @@
final Activity activity = getActivity();
StorageManager sm = activity.getSystemService(StorageManager.class);
mVolume = Utils.maybeInitializeVolume(sm, getArguments());
+ mPersonalOnly = getArguments().getInt(ProfileSelectFragment.EXTRA_PROFILE)
+ == ProfileSelectFragment.PERSONAL;
if (mVolume == null) {
activity.finish();
return;
}
-
initializeOptionsMenu(activity);
+ if (mPersonalOnly) {
+ final Preference summary = getPreferenceScreen().findPreference(SUMMARY_PREF_KEY);
+ if (summary != null) {
+ summary.setVisible(false);
+ }
+ }
}
@Override
@@ -119,7 +128,6 @@
null /* header view */)
.setRecyclerView(getListView(), getSettingsLifecycle())
.styleActionBar(activity);
-
}
@Override
@@ -140,7 +148,6 @@
boolean stopLoading = false;
if (mStorageInfo != null) {
long privateUsedBytes = mStorageInfo.totalBytes - mStorageInfo.freeBytes;
- mSummaryController.updateBytes(privateUsedBytes, mStorageInfo.totalBytes);
mPreferenceController.setVolume(mVolume);
mPreferenceController.setUsedSize(privateUsedBytes);
mPreferenceController.setTotalSize(mStorageInfo.totalBytes);
@@ -187,8 +194,6 @@
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- mSummaryController = new StorageSummaryDonutPreferenceController(context);
- controllers.add(mSummaryController);
StorageManager sm = context.getSystemService(StorageManager.class);
mPreferenceController = new StorageItemPreferenceController(context, this,
@@ -241,7 +246,6 @@
final StorageManager sm = context.getSystemService(StorageManager.class);
final UserManager userManager = context.getSystemService(UserManager.class);
final List<AbstractPreferenceController> controllers = new ArrayList<>();
- controllers.add(new StorageSummaryDonutPreferenceController(context));
controllers.add(new StorageItemPreferenceController(context, null /* host */,
null /* volume */, new StorageManagerVolumeProvider(sm)));
controllers.addAll(SecondaryUserController.getSecondaryUserControllers(
diff --git a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
index 31898d1..26039fb 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceController.java
@@ -41,6 +41,7 @@
import com.android.settings.core.FeatureFlags;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
import com.android.settings.deviceinfo.PrivateVolumeSettings.SystemInfoFragment;
import com.android.settings.deviceinfo.StorageItemPreference;
import com.android.settings.overlay.FeatureFactory;
@@ -392,14 +393,15 @@
private Bundle getWorkAnnotatedBundle(int additionalCapacity) {
if (FeatureFlagUtils.isEnabled(mContext, FeatureFlags.PERSONAL_WORK_PROFILE)) {
- final Bundle args = new Bundle(3 + additionalCapacity);
- args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
+ final Bundle args = new Bundle(2 + additionalCapacity);
+ args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
+ mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.PERSONAL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
- args.putBoolean(ManageApplications.EXTRA_PERSONAL_ONLY, !mIsWorkProfile);
return args;
} else {
final Bundle args = new Bundle(2 + additionalCapacity);
- args.putBoolean(ManageApplications.EXTRA_WORK_ONLY, mIsWorkProfile);
+ args.putInt(ProfileSelectFragment.EXTRA_PROFILE,
+ mIsWorkProfile ? ProfileSelectFragment.WORK : ProfileSelectFragment.ALL);
args.putInt(ManageApplications.EXTRA_WORK_ID, mUserId);
return args;
}
diff --git a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
index d450a2a..d8ee711 100644
--- a/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
+++ b/src/com/android/settings/deviceinfo/storage/StorageSummaryDonutPreferenceController.java
@@ -17,6 +17,7 @@
package com.android.settings.deviceinfo.storage;
import android.content.Context;
+import android.os.storage.StorageManager;
import android.os.storage.VolumeInfo;
import android.text.TextUtils;
import android.text.format.Formatter;
@@ -25,22 +26,29 @@
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
-import com.android.settings.core.PreferenceControllerMixin;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.core.BasePreferenceController;
+import com.android.settingslib.deviceinfo.PrivateStorageInfo;
+import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
+import com.android.settingslib.utils.ThreadUtils;
+
+import java.text.NumberFormat;
/**
- * StorgaeSummaryPreferenceController updates the donut storage summary preference to have the
+ * SummaryPreferenceController updates the donut storage summary preference to have the
* correct sizes showing.
*/
-public class StorageSummaryDonutPreferenceController extends AbstractPreferenceController implements
- PreferenceControllerMixin {
+public class StorageSummaryDonutPreferenceController extends BasePreferenceController {
private long mUsedBytes;
private long mTotalBytes;
private StorageSummaryDonutPreference mSummary;
+ private final StorageManager mStorageManager;
+ private final StorageManagerVolumeProvider mStorageManagerVolumeProvider;
- public StorageSummaryDonutPreferenceController(Context context) {
- super(context);
+ public StorageSummaryDonutPreferenceController(Context context, String key) {
+ super(context, key);
+ mStorageManager = mContext.getSystemService(StorageManager.class);
+ mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(mStorageManager);
}
/**
@@ -58,19 +66,31 @@
@Override
public void displayPreference(PreferenceScreen screen) {
- mSummary = screen.findPreference("pref_summary");
+ mSummary = screen.findPreference(getPreferenceKey());
mSummary.setEnabled(true);
+
+ ThreadUtils.postOnBackgroundThread(() -> {
+ final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
+ final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
+ mStorageManagerVolumeProvider);
+ final double privateUsedBytes = info.totalBytes - info.freeBytes;
+ mTotalBytes = info.totalBytes;
+ mUsedBytes = info.totalBytes - info.freeBytes;
+
+ ThreadUtils.postOnMainThread(() -> {
+ updateState(mSummary);
+ });
+ });
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
- StorageSummaryDonutPreference summary = (StorageSummaryDonutPreference) preference;
- summary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
- summary.setSummary(mContext.getString(R.string.storage_volume_total,
+ mSummary.setTitle(convertUsedBytesToFormattedText(mContext, mUsedBytes));
+ mSummary.setSummary(mContext.getString(R.string.storage_volume_total,
Formatter.formatShortFileSize(mContext, mTotalBytes)));
- summary.setPercent(mUsedBytes, mTotalBytes);
- summary.setEnabled(true);
+ mSummary.setPercent(mUsedBytes, mTotalBytes);
+ mSummary.setEnabled(true);
}
/** Invalidates the data on the view and re-renders. */
@@ -81,13 +101,8 @@
}
@Override
- public boolean isAvailable() {
- return true;
- }
-
- @Override
- public String getPreferenceKey() {
- return "pref_summary";
+ public int getAvailabilityStatus() {
+ return AVAILABLE;
}
/**
diff --git a/src/com/android/settings/fuelgauge/InactiveApps.java b/src/com/android/settings/fuelgauge/InactiveApps.java
index 6c8a954..c386a7d 100644
--- a/src/com/android/settings/fuelgauge/InactiveApps.java
+++ b/src/com/android/settings/fuelgauge/InactiveApps.java
@@ -67,7 +67,8 @@
super.onCreate(icicle);
mUsageStats = getActivity().getSystemService(UsageStatsManager.class);
- addPreferencesFromResource(R.xml.inactive_apps);
+ addPreferencesFromResource(R.xml.dummy_preference_screen);
+ getActivity().setTitle(R.string.inactive_apps_title);
}
@Override
diff --git a/src/com/android/settings/search/actionbar/SearchMenuController.java b/src/com/android/settings/search/actionbar/SearchMenuController.java
index 0243c09..9e22bbf 100644
--- a/src/com/android/settings/search/actionbar/SearchMenuController.java
+++ b/src/com/android/settings/search/actionbar/SearchMenuController.java
@@ -42,6 +42,7 @@
public class SearchMenuController implements LifecycleObserver, OnCreateOptionsMenu {
public static final String NEED_SEARCH_ICON_IN_ACTION_BAR = "need_search_icon_in_action_bar";
+ public static final int MENU_SEARCH = Menu.FIRST + 10;
private final Fragment mHost;
private final int mPageId;
@@ -80,7 +81,11 @@
if (arguments != null && !arguments.getBoolean(NEED_SEARCH_ICON_IN_ACTION_BAR, true)) {
return;
}
- final MenuItem searchItem = menu.add(Menu.NONE, Menu.NONE, 0 /* order */,
+ // menu contains search item, skip it
+ if (menu.findItem(MENU_SEARCH) != null) {
+ return;
+ }
+ final MenuItem searchItem = menu.add(Menu.NONE, MENU_SEARCH, 0 /* order */,
R.string.search_menu);
searchItem.setIcon(R.drawable.ic_search_24dp);
searchItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);