Search Icon persists through screen rotation
Change-Id: If88d345f4ce61f6aec1599d0db85cbfa3b8e91c3 Fixes: 36457675 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -84,7 +84,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
// Constants for state save/restore
|
// Constants for state save/restore
|
||||||
private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
|
private static final String SAVE_KEY_CATEGORIES = ":settings:categories";
|
||||||
private static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
|
@VisibleForTesting
|
||||||
|
static final String SAVE_KEY_SHOW_HOME_AS_UP = ":settings:show_home_as_up";
|
||||||
|
@VisibleForTesting
|
||||||
|
static final String SAVE_KEY_SHOW_SEARCH = ":settings:show_search";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When starting this activity, the invoking Intent can contain this extra
|
* When starting this activity, the invoking Intent can contain this extra
|
||||||
@@ -193,8 +196,10 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
|
|
||||||
private Button mNextButton;
|
private Button mNextButton;
|
||||||
|
|
||||||
private boolean mDisplayHomeAsUpEnabled;
|
@VisibleForTesting
|
||||||
private boolean mDisplaySearch;
|
boolean mDisplayHomeAsUpEnabled;
|
||||||
|
@VisibleForTesting
|
||||||
|
boolean mDisplaySearch;
|
||||||
|
|
||||||
private boolean mIsShowingDashboard;
|
private boolean mIsShowingDashboard;
|
||||||
private boolean mIsShortcut;
|
private boolean mIsShortcut;
|
||||||
@@ -231,7 +236,6 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
if (!mDisplaySearch) {
|
if (!mDisplaySearch) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
mSearchFeatureProvider.setUpSearchMenu(menu, this);
|
mSearchFeatureProvider.setUpSearchMenu(menu, this);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -514,12 +518,28 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
|
saveState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For testing purposes to avoid crashes from final variables in Activity's onSaveInstantState.
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void saveState(Bundle outState) {
|
||||||
if (mCategories.size() > 0) {
|
if (mCategories.size() > 0) {
|
||||||
outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
|
outState.putParcelableArrayList(SAVE_KEY_CATEGORIES, mCategories);
|
||||||
}
|
}
|
||||||
|
|
||||||
outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
|
outState.putBoolean(SAVE_KEY_SHOW_HOME_AS_UP, mDisplayHomeAsUpEnabled);
|
||||||
|
outState.putBoolean(SAVE_KEY_SHOW_SEARCH, mDisplaySearch);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||||
|
super.onRestoreInstanceState(savedInstanceState);
|
||||||
|
|
||||||
|
mDisplayHomeAsUpEnabled = savedInstanceState.getBoolean(SAVE_KEY_SHOW_HOME_AS_UP);
|
||||||
|
mDisplaySearch = savedInstanceState.getBoolean(SAVE_KEY_SHOW_SEARCH);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -16,20 +16,28 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Menu;
|
||||||
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Answers;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.RuntimeEnvironment;
|
import org.robolectric.RuntimeEnvironment;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
@@ -42,6 +50,9 @@ import static org.mockito.Mockito.when;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class SettingsActivityTest {
|
public class SettingsActivityTest {
|
||||||
|
|
||||||
|
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -50,10 +61,15 @@ public class SettingsActivityTest {
|
|||||||
private Bitmap mBitmap;
|
private Bitmap mBitmap;
|
||||||
private SettingsActivity mActivity;
|
private SettingsActivity mActivity;
|
||||||
|
|
||||||
|
private FakeFeatureFactory mFeatureFactory;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
|
|
||||||
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
|
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
|
|
||||||
mActivity = spy(new SettingsActivity());
|
mActivity = spy(new SettingsActivity());
|
||||||
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
|
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
|
||||||
}
|
}
|
||||||
@@ -61,7 +77,6 @@ public class SettingsActivityTest {
|
|||||||
@Test
|
@Test
|
||||||
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
|
public void launchSettingFragment_nullExtraShowFragment_shouldNotCrash()
|
||||||
throws ClassNotFoundException {
|
throws ClassNotFoundException {
|
||||||
mActivity = spy(new SettingsActivity());
|
|
||||||
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
|
when(mActivity.getFragmentManager()).thenReturn(mFragmentManager);
|
||||||
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
|
when(mFragmentManager.beginTransaction()).thenReturn(mock(FragmentTransaction.class));
|
||||||
|
|
||||||
@@ -76,4 +91,51 @@ public class SettingsActivityTest {
|
|||||||
|
|
||||||
verify(mTaskDescription).setIcon(any());
|
verify(mTaskDescription).setIcon(any());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateOptionsMenu_setsUpSearch() {
|
||||||
|
ReflectionHelpers.setField(mActivity, "mSearchFeatureProvider",
|
||||||
|
mFeatureFactory.getSearchFeatureProvider());
|
||||||
|
mActivity.mDisplaySearch = true;
|
||||||
|
mActivity.onCreateOptionsMenu(null);
|
||||||
|
|
||||||
|
verify(mFeatureFactory.getSearchFeatureProvider()).setUpSearchMenu(any(Menu.class),
|
||||||
|
any(Activity.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveState_DisplaySearchSaved() {
|
||||||
|
mActivity.mDisplaySearch = true;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
mActivity.saveState(bundle);
|
||||||
|
|
||||||
|
assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_SEARCH)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSaveState_EnabledHomeSaved() {
|
||||||
|
mActivity.mDisplayHomeAsUpEnabled = true;
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
mActivity.saveState(bundle);
|
||||||
|
|
||||||
|
assertThat((boolean) bundle.get(SettingsActivity.SAVE_KEY_SHOW_HOME_AS_UP)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRestoreState_DisplaySearchRestored() {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
|
||||||
|
mActivity.onRestoreInstanceState(bundle);
|
||||||
|
|
||||||
|
assertThat(mActivity.mDisplaySearch).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRestoreState_EnabledHomeRestored() {
|
||||||
|
Bundle bundle = new Bundle();
|
||||||
|
bundle.putBoolean(SettingsActivity.SAVE_KEY_SHOW_SEARCH, true);
|
||||||
|
mActivity.onRestoreInstanceState(bundle);
|
||||||
|
|
||||||
|
assertThat(mActivity.mDisplaySearch).isTrue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user