All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.robolectric.shadows.ShadowUIModeManager Maven / Gradle / Ivy

There is a newer version: 4.14.1
Show newest version
package org.robolectric.shadows;

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 VALID_NIGHT_MODES =
      ImmutableSet.of(
          UiModeManager.MODE_NIGHT_AUTO, UiModeManager.MODE_NIGHT_NO, UiModeManager.MODE_NIGHT_YES);

  @Implementation
  public int getCurrentModeType() {
    return currentModeType;
  }

  @Implementation
  public void enableCarMode(int flags) {
    currentModeType = Configuration.UI_MODE_TYPE_CAR;
  }

  @Implementation
  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;
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy