Java Code Examples for android.app.UiModeManager#MODE_NIGHT_NO

The following examples show how to use android.app.UiModeManager#MODE_NIGHT_NO . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From AnotherRSS with The Unlicense 6 votes vote down vote up
@Override
protected void onResume() {
    Log.d(AnotherRSS.TAG, "onResume");
    AnotherRSS.withGui = true;
    new DbExpunge().execute();

    boolean night = mPreferences.getBoolean("nightmode_use", false);
    if (night) {
        int startH = mPreferences.getInt("nightmode_use_start", AnotherRSS.Config.DEFAULT_NIGHT_START);
        int stopH = mPreferences.getInt("nightmode_use_stop", AnotherRSS.Config.DEFAULT_NIGHT_STOP);
        if (AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_YES) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_YES);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
        }
        if (!AnotherRSS.inTimeSpan(startH, stopH) && umm.getNightMode() != UiModeManager.MODE_NIGHT_NO) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
    } else {
        if (umm.getNightMode() == UiModeManager.MODE_NIGHT_YES) {
            umm.setNightMode(UiModeManager.MODE_NIGHT_NO);
            AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
        }
    }
    super.onResume();
}
 
Example 2
Source File: UiModeManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public void setNightMode(int mode) {
    if (isNightModeLocked() &&  (getContext().checkCallingOrSelfPermission(
            android.Manifest.permission.MODIFY_DAY_NIGHT_MODE)
            != PackageManager.PERMISSION_GRANTED)) {
        Slog.e(TAG,
                "Night mode locked, requires MODIFY_DAY_NIGHT_MODE permission");
        return;
    }
    switch (mode) {
        case UiModeManager.MODE_NIGHT_NO:
        case UiModeManager.MODE_NIGHT_YES:
        case UiModeManager.MODE_NIGHT_AUTO:
            break;
        default:
            throw new IllegalArgumentException("Unknown mode: " + mode);
    }

    final long ident = Binder.clearCallingIdentity();
    try {
        synchronized (mLock) {
            if (mNightMode != mode) {
                Settings.Secure.putInt(getContext().getContentResolver(),
                        Settings.Secure.UI_NIGHT_MODE, mode);
                mNightMode = mode;
                updateLocked(0, 0);
            }
        }
    } finally {
        Binder.restoreCallingIdentity(ident);
    }
}
 
Example 3
Source File: UiModeManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static String nightModeToStr(int mode) {
    switch (mode) {
        case UiModeManager.MODE_NIGHT_YES:
            return NIGHT_MODE_STR_YES;
        case UiModeManager.MODE_NIGHT_NO:
            return NIGHT_MODE_STR_NO;
        case UiModeManager.MODE_NIGHT_AUTO:
            return NIGHT_MODE_STR_AUTO;
        default:
            return NIGHT_MODE_STR_UNKNOWN;
    }
}
 
Example 4
Source File: UiModeManagerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private static int strToNightMode(String modeStr) {
    switch (modeStr) {
        case NIGHT_MODE_STR_YES:
            return UiModeManager.MODE_NIGHT_YES;
        case NIGHT_MODE_STR_NO:
            return UiModeManager.MODE_NIGHT_NO;
        case NIGHT_MODE_STR_AUTO:
            return UiModeManager.MODE_NIGHT_AUTO;
        default:
            return -1;
    }
}