Use FooterPreference in xml explicitly

We don't rely on FooterPreferenceMixinCompat
to create footer preference in dashboard fragment.

Instead, declare a FooterPreference explicitly in
xml of screen.

It makes more sense for our referenceController design.

Test: visual, robotest
Bug: 124129485
Change-Id: I0b0c0f9e38d85aa89b815ce2b84ddff30a1d206b
This commit is contained in:
tmfang
2019-05-31 18:24:29 +08:00
parent f1c0f23510
commit 24c3324268
10 changed files with 84 additions and 109 deletions

View File

@@ -16,13 +16,16 @@
package com.android.settings.datetime.timezone;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import androidx.preference.Preference;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import com.android.settings.datetime.timezone.TimeZoneInfo.Formatter;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
@@ -34,20 +37,38 @@ import java.util.Locale;
@RunWith(RobolectricTestRunner.class)
public class TimeZoneInfoPreferenceControllerTest {
@Test
public void updateState_matchExpectedFormattedText() {
Date now = new Date(0L); // 00:00 1/1/1970
Formatter formatter = new Formatter(Locale.US, now);
private TimeZoneInfo mTimeZoneInfo;
private TimeZoneInfoPreferenceController mController;
TimeZoneInfo timeZoneInfo = formatter.format("America/Los_Angeles");
TimeZoneInfoPreferenceController controller =
new TimeZoneInfoPreferenceController(RuntimeEnvironment.application);
controller.mDate = now;
controller.setTimeZoneInfo(timeZoneInfo);
Preference preference = spy(new Preference(RuntimeEnvironment.application));
controller.updateState(preference);
assertEquals("Uses Pacific Time (GMT-08:00). "
+ "Pacific Daylight Time starts on April 26, 1970.",
preference.getTitle().toString());
@Before
public void setUp() {
final Context context = RuntimeEnvironment.application;
final Date now = new Date(0L); // 00:00 1/1/1970
final Formatter formatter = new Formatter(Locale.US, now);
mTimeZoneInfo = formatter.format("America/Los_Angeles");
mController = new TimeZoneInfoPreferenceController(context, "key");
mController.mDate = now;
mController.setTimeZoneInfo(mTimeZoneInfo);
}
@Test
public void getSummary_matchExpectedFormattedText() {
assertThat(mController.getSummary().toString()).isEqualTo(
"Uses Pacific Time (GMT-08:00). "
+ "Pacific Daylight Time starts on April 26, 1970.");
}
@Test
public void getAvailabilityStatus_timeZoneInfoSet_shouldReturnAVAILABLE_UNSEARCHABLE() {
mController.setTimeZoneInfo(mTimeZoneInfo);
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
public void getAvailabilityStatus_noTimeZoneInfoSet_shouldReturnUNSUPPORTED_ON_DEVICE() {
mController.setTimeZoneInfo(null);
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}

View File

@@ -21,6 +21,7 @@ import static com.android.settings.core.BasePreferenceController.CONDITIONALLY_U
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_ALL_APPS;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_DEFAULT;
import static com.android.settings.development.gamedriver.GameDriverEnableForAllAppsPreferenceController.GAME_DRIVER_OFF;
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
@@ -62,7 +63,7 @@ public class GameDriverFooterPreferenceControllerTest {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mResolver = mContext.getContentResolver();
mController = spy(new GameDriverFooterPreferenceController(mContext));
mController = spy(new GameDriverFooterPreferenceController(mContext, "key"));
when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
}
@@ -104,20 +105,4 @@ public class GameDriverFooterPreferenceControllerTest {
verify(mGameDriverContentObserver).unregister(mResolver);
}
@Test
public void updateState_available_visible() {
when(mController.getAvailabilityStatus()).thenReturn(AVAILABLE_UNSEARCHABLE);
mController.updateState(mPreference);
verify(mPreference).setVisible(true);
}
@Test
public void updateState_unavailable_invisible() {
when(mController.getAvailabilityStatus()).thenReturn(CONDITIONALLY_UNAVAILABLE);
mController.updateState(mPreference);
verify(mPreference).setVisible(false);
}
}

View File

@@ -14,6 +14,9 @@
package com.android.settings.display;
import static com.android.settings.core.BasePreferenceController.AVAILABLE_UNSEARCHABLE;
import static com.android.settings.core.BasePreferenceController.UNSUPPORTED_ON_DEVICE;
import static com.google.common.truth.Truth.assertThat;
import com.android.settings.testutils.shadow.SettingsShadowResources;
@@ -34,7 +37,8 @@ public class NightDisplayFooterPreferenceControllerTest {
@Before
public void setUp() {
mController = new NightDisplayFooterPreferenceController(RuntimeEnvironment.application);
mController =
new NightDisplayFooterPreferenceController(RuntimeEnvironment.application, "key");
}
@After
@@ -43,16 +47,18 @@ public class NightDisplayFooterPreferenceControllerTest {
}
@Test
public void isAvailable_configuredAvailable() {
public void getAvailabilityStatus_configuredAvailable_shouldReturnAVAILABLE_UNSEARCHABLE() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, true);
assertThat(mController.isAvailable()).isTrue();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE_UNSEARCHABLE);
}
@Test
public void isAvailable_configuredUnavailable() {
public void getAvailabilityStatus_configuredUnavailable_shouldReturnUNSUPPORTED_ON_DEVICE() {
SettingsShadowResources.overrideResource(
com.android.internal.R.bool.config_nightDisplayAvailable, false);
assertThat(mController.isAvailable()).isFalse();
assertThat(mController.getAvailabilityStatus()).isEqualTo(UNSUPPORTED_ON_DEVICE);
}
}