}
// Prepare help url and enable menu if necessary
- final Bundle arguments = getArguments();
- final int helpResource;
+ Bundle arguments = getArguments();
+ int helpResource;
if (arguments != null && arguments.containsKey(HELP_URI_RESOURCE_KEY)) {
helpResource = arguments.getInt(HELP_URI_RESOURCE_KEY);
} else {
if (helpResource != 0) {
mHelpUri = getResources().getString(helpResource);
}
-
- // Check if we should keep the preferences expanded.
- if (arguments != null) {
- mPreferenceKey = arguments.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
- if (!TextUtils.isEmpty(mPreferenceKey)) {
- getPreferenceScreen().setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- }
- }
}
@Override
public void onResume() {
super.onResume();
- if (mPreferenceKey != null) {
+ final Bundle args = getArguments();
+ if (args != null) {
+ mPreferenceKey = args.getString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY);
highlightPreferenceIfNeeded();
}
}
package com.android.settings;
+
import android.app.Activity;
import android.content.Context;
-import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceCategory;
import android.support.v7.preference.PreferenceManager;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
-import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
-import com.android.settings.testutils.shadow.SettingsShadowResources;
@RunWith(SettingsRobolectricTestRunner.class)
-@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION_O)
+@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
public class SettingsPreferenceFragmentTest {
private static final int ITEM_COUNT = 5;
@Mock
+ private PreferenceManager mPreferenceManager;
+ @Mock
private Activity mActivity;
@Mock
private View mListContainer;
assertThat(mEmptyView.getVisibility()).isEqualTo(View.GONE);
}
- @Test
- @Config(shadows = SettingsShadowResources.SettingsShadowTheme.class)
- public void onCreate_hasExtraFragmentKey_shouldExpandPreferences() {
- doReturn(mContext.getTheme()).when(mActivity).getTheme();
- doReturn(mContext.getResources()).when(mFragment).getResources();
- doReturn(mPreferenceScreen).when(mFragment).getPreferenceScreen();
- final Bundle bundle = new Bundle();
- bundle.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, "test_key");
- doReturn(bundle).when(mFragment).getArguments();
-
- mFragment.onCreate(null /* icicle */);
-
- verify(mPreferenceScreen).setInitialExpandedChildrenCount(Integer.MAX_VALUE);
- }
-
public static class TestFragment extends SettingsPreferenceFragment {
@Override
}
}
+
}