v7/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java
private boolean updateForNightMode(@ApplyableNightMode final int mode) {
        final Resources res = mContext.getResources();
        final Configuration conf = res.getConfiguration();
        final int currentNightMode = conf.uiMode & Configuration.UI_MODE_NIGHT_MASK;

        final int newNightMode = (mode == MODE_NIGHT_YES)
                ? Configuration.UI_MODE_NIGHT_YES
                : Configuration.UI_MODE_NIGHT_NO;

        if (currentNightMode != newNightMode) {
            if (shouldRecreateOnNightModeChange()) {
                if (DEBUG) {
                    Log.d(TAG, "applyNightMode() | Night mode changed, recreating Activity");
                }
                // If we've already been created, we need to recreate the Activity for the
                // mode to be applied
                final Activity activity = (Activity) mContext;
                activity.recreate();
            } else {
                if (DEBUG) {
                    Log.d(TAG, "applyNightMode() | Night mode changed, updating configuration");
                }
                final Configuration config = new Configuration(conf);
                final DisplayMetrics metrics = res.getDisplayMetrics();

                // Update the UI Mode to reflect the new night mode
                config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK);
                res.updateConfiguration(config, metrics);

                // We may need to flush the Resources' drawable cache due to framework bugs.
                if (!(Build.VERSION.SDK_INT >= 26)) {
                    ResourcesFlusher.flush(res);
                }
            }
            return true;
        } else {
            if (DEBUG) {
                Log.d(TAG, "applyNightMode() | Skipping. Night mode has not changed: " + mode);
            }
        }
        return false;
    }
/**
     * Updates the {@link Resources} configuration {@code uiMode} with the
     * chosen {@code UI_MODE_NIGHT} value.
     */
Updates the  Resources configuration  uiMode with the
chosen  UI_MODE_NIGHT value.
Updates the Resources configuration uiMode with the chosen UI_MODE_NIGHT value .
private boolean updateForNightMode(@ApplyableNightMode final int mode) {
        final Resources res = mContext.getResources();
        final Configuration conf = res.getConfiguration();
        final int currentNightMode = conf.uiMode & Configuration.UI_MODE_NIGHT_MASK;
        final int newNightMode = (mode == MODE_NIGHT_YES)
                ? Configuration.UI_MODE_NIGHT_YES
                : Configuration.UI_MODE_NIGHT_NO;
        if (currentNightMode != newNightMode) {
            if (shouldRecreateOnNightModeChange()) {
                if (DEBUG) {
                    Log.d(TAG, "applyNightMode() | Night mode changed, recreating Activity");
                }
                final Activity activity = (Activity) mContext;
                activity.recreate();
            } else {
                if (DEBUG) {
                    Log.d(TAG, "applyNightMode() | Night mode changed, updating configuration");
                }
                final Configuration config = new Configuration(conf);
                final DisplayMetrics metrics = res.getDisplayMetrics();
                config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK);
                res.updateConfiguration(config, metrics);
                if (!(Build.VERSION.SDK_INT >= 26)) {
                    ResourcesFlusher.flush(res);
                }
            }
            return true;
        } else {
            if (DEBUG) {
                Log.d(TAG, "applyNightMode() | Skipping. Night mode has not changed: " + mode);
            }
        }
        return false;
    }
private boolean updateForNightMode ( @ ApplyableNightMode final int mode ) { final Resources res = mContext . getResources ( ) ; final Configuration conf = res . getConfiguration ( ) ; final int currentNightMode = conf . uiMode & Configuration . UI_MODE_NIGHT_MASK ; final int newNightMode = ( mode == MODE_NIGHT_YES ) ? Configuration . UI_MODE_NIGHT_YES : Configuration . UI_MODE_NIGHT_NO ; if ( currentNightMode != newNightMode ) { if ( shouldRecreateOnNightModeChange ( ) ) { if ( DEBUG ) { Log . d ( TAG , "applyNightMode() | Night mode changed, recreating Activity" ) ; } final Activity activity = ( Activity ) mContext ; activity . recreate ( ) ; } else { if ( DEBUG ) { Log . d ( TAG , "applyNightMode() | Night mode changed, updating configuration" ) ; } final Configuration config = new Configuration ( conf ) ; final DisplayMetrics metrics = res . getDisplayMetrics ( ) ; config . uiMode = newNightMode | ( config . uiMode & ~ Configuration . UI_MODE_NIGHT_MASK ) ; res . updateConfiguration ( config , metrics ) ; if ( ! ( Build . VERSION . SDK_INT >= 26 ) ) { ResourcesFlusher . flush ( res ) ; } } return true ; } else { if ( DEBUG ) { Log . d ( TAG , "applyNightMode() | Skipping. Night mode has not changed: " + mode ) ; } } return false ; }
Updates the {@link Resources} configuration {@code uiMode} with the
 chosen {@code UI_MODE_NIGHT} value.
Updates the { @link Resources } configuration { @code uiMode } with the chosen { @code UI_MODE_NIGHT } value .
// If we've already been created, we need to recreate the Activity for the // mode to be applied // Update the UI Mode to reflect the new night mode // We may need to flush the Resources' drawable cache due to framework bugs.