Skip to content

Commit

Permalink
UiModeManager
Browse files Browse the repository at this point in the history
Added a night mode getter and setter for ShadowUIModeManager

PiperOrigin-RevId: 239505733
  • Loading branch information
Googler authored and copybara-robolectric committed Mar 21, 2019
1 parent aeadc29 commit 78a4eec
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Expand Up @@ -38,4 +38,20 @@ public void testModeSwitch() {
uiModeManager.disableCarMode(0);
assertThat(uiModeManager.getCurrentModeType()).isEqualTo(Configuration.UI_MODE_TYPE_NORMAL);
}

private static final int INVALID_NIGHT_MODE = -4242;

@Test
public void testNightMode() {
assertThat(uiModeManager.getNightMode()).isEqualTo(UiModeManager.MODE_NIGHT_AUTO);

uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_YES);
assertThat(uiModeManager.getNightMode()).isEqualTo(UiModeManager.MODE_NIGHT_YES);

uiModeManager.setNightMode(UiModeManager.MODE_NIGHT_NO);
assertThat(uiModeManager.getNightMode()).isEqualTo(UiModeManager.MODE_NIGHT_NO);

uiModeManager.setNightMode(INVALID_NIGHT_MODE);
assertThat(uiModeManager.getNightMode()).isEqualTo(UiModeManager.MODE_NIGHT_AUTO);
}
}
Expand Up @@ -2,13 +2,19 @@

import android.app.UiModeManager;
import android.content.res.Configuration;
import com.google.common.collect.ImmutableSet;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

/** */
@Implements(UiModeManager.class)
public class ShadowUIModeManager {
public int currentModeType = Configuration.UI_MODE_TYPE_UNDEFINED;
public int currentNightMode = UiModeManager.MODE_NIGHT_AUTO;

private static final ImmutableSet<Integer> VALID_NIGHT_MODES =
ImmutableSet.of(
UiModeManager.MODE_NIGHT_AUTO, UiModeManager.MODE_NIGHT_NO, UiModeManager.MODE_NIGHT_YES);

@Implementation
public int getCurrentModeType() {
Expand All @@ -24,4 +30,18 @@ public void enableCarMode(int flags) {
public void disableCarMode(int flags) {
currentModeType = Configuration.UI_MODE_TYPE_NORMAL;
}

@Implementation
public int getNightMode() {
return currentNightMode;
}

@Implementation
public void setNightMode(int mode) {
if (VALID_NIGHT_MODES.contains(mode)) {
currentNightMode = mode;
} else {
currentNightMode = UiModeManager.MODE_NIGHT_AUTO;
}
}
}

0 comments on commit 78a4eec

Please sign in to comment.