Example usage for android.app UiModeManager MODE_NIGHT_YES

List of usage examples for android.app UiModeManager MODE_NIGHT_YES

Introduction

In this page you can find the example usage for android.app UiModeManager MODE_NIGHT_YES.

Prototype

int MODE_NIGHT_YES

To view the source code for android.app UiModeManager MODE_NIGHT_YES.

Click Source Link

Document

Constant for #setNightMode(int) and #getNightMode() : always run in night mode.

Usage

From source file:com.keylesspalace.tusky.util.ThemeUtils.java

public static void setAppNightMode(String flavor, Context context) {
    int mode;// w  ww  .ja  va 2 s  .c  om
    switch (flavor) {
    default:
    case THEME_NIGHT:
        mode = UiModeManager.MODE_NIGHT_YES;
        break;
    case THEME_DAY:
        mode = UiModeManager.MODE_NIGHT_NO;
        break;
    case THEME_BLACK:
        mode = UiModeManager.MODE_NIGHT_YES;
        break;
    case THEME_AUTO:
        mode = UiModeManager.MODE_NIGHT_AUTO;
        break;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        UiModeManager uiModeManager = (UiModeManager) context.getApplicationContext()
                .getSystemService(Context.UI_MODE_SERVICE);
        uiModeManager.setNightMode(mode);
    } else {
        AppCompatDelegate.setDefaultNightMode(mode);
    }

}