Remove unused HelpMenuController

Bug: 365922551
Test: Presubmit
Flag: EXEMPT Cleanup
Change-Id: I100bf23e42be1b33de18f92afa0fef3c3ecd8dda
This commit is contained in:
Jacky Wang
2024-09-11 17:49:16 +08:00
parent d88ab26776
commit 4b2b590d5c
2 changed files with 0 additions and 151 deletions

View File

@@ -1,73 +0,0 @@
/*
* Copyright (C) 2017 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.support.actionbar;
import static com.android.settings.support.actionbar.HelpResourceProvider.HELP_URI_RESOURCE_KEY;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import com.android.settingslib.HelpUtils;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.ObservableFragment;
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
import com.android.settingslib.core.lifecycle.events.OnCreateOptionsMenu;
/**
* A controller that adds help menu to any Settings page.
*/
public class HelpMenuController implements LifecycleObserver, OnCreateOptionsMenu {
private final Fragment mHost;
public static void init(@NonNull ObservablePreferenceFragment host) {
host.getSettingsLifecycle().addObserver(new HelpMenuController(host));
}
public static void init(@NonNull ObservableFragment host) {
host.getSettingsLifecycle().addObserver(new HelpMenuController(host));
}
private HelpMenuController(@NonNull Fragment host) {
mHost = host;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
final Bundle arguments = mHost.getArguments();
int helpResourceId = 0;
if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
helpResourceId = arguments.getInt(HELP_URI_RESOURCE_KEY);
} else if (mHost instanceof HelpResourceProvider) {
helpResourceId = ((HelpResourceProvider) mHost).getHelpResource();
}
String helpUri = null;
if (helpResourceId != 0) {
helpUri = mHost.getContext().getString(helpResourceId);
}
final Activity activity = mHost.getActivity();
if (helpUri != null && activity != null) {
HelpUtils.prepareHelpMenuItem(activity, menu, helpUri, mHost.getClass().getName());
}
}
}

View File

@@ -1,78 +0,0 @@
/*
* Copyright (C) 2017 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.support.actionbar;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.Context;
import android.os.Bundle;
import com.android.settingslib.core.lifecycle.ObservablePreferenceFragment;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RobolectricTestRunner;
@RunWith(RobolectricTestRunner.class)
public class HelpMenuControllerTest {
@Mock
private Context mContext;
private TestFragment mHost;
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mHost = spy(new TestFragment());
doReturn(mContext).when(mHost).getContext();
}
@Test
public void onCreateOptionsMenu_withArgumentOverride_shouldPrepareHelpUsingOverride() {
final Bundle bundle = new Bundle();
bundle.putInt(HelpResourceProvider.HELP_URI_RESOURCE_KEY, 123);
mHost.setArguments(bundle);
HelpMenuController.init(mHost);
mHost.getSettingsLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
verify(mContext).getString(123);
}
@Test
public void onCreateOptionsMenu_noArgumentOverride_shouldPrepareHelpUsingProvider() {
HelpMenuController.init(mHost);
mHost.getSettingsLifecycle().onCreateOptionsMenu(null /* menu */, null /* inflater */);
verify(mContext).getString(mHost.getHelpResource());
}
private static class TestFragment extends ObservablePreferenceFragment
implements HelpResourceProvider {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
}
}
}